about summary refs log tree commit diff
path: root/src/libgreen
AgeCommit message (Collapse)AuthorLines
2014-02-23std: Move unstable::stack to rt::stackBrian Anderson-1/+1
2014-02-23std: Move raw to std::rawBrian Anderson-3/+3
Issue #1457
2014-02-23std: Move intrinsics to std::intrinsics.Brian Anderson-1/+1
Issue #1457
2014-02-18auto merge of #12345 : huonw/rust/speeling, r=cmrbors-1/+1
2014-02-18Spellcheck library docs.Huon Wilson-1/+1
2014-02-16Clean up std::task docs, make TaskBuilder a real builderKevin Ballard-1/+0
Delete all the documentation from std::task that references linked failure. Tweak TaskBuilder to be more builder-like. .name() is now .named() and .add_wrapper() is now .with_wrapper(). Remove .watched() and .unwatched() as they didn't actually do anything.
2014-02-15auto merge of #12235 : huonw/rust/raii-lock, r=alexcrichtonbors-34/+25
- adds a `LockGuard` type returned by `.lock` and `.trylock` that unlocks the mutex in the destructor - renames `mutex::Mutex` to `StaticNativeMutex` - adds a `NativeMutex` type with a destructor - removes `LittleLock` - adds `#[must_use]` to `sync::mutex::Guard` to remind people to use it
2014-02-16Convert some unnecessary StaticNativeMutexes to NativeMutexes.Huon Wilson-12/+6
2014-02-16std: add a NativeMutex type as a wrapper to destroy StaticNativeMutex.Huon Wilson-5/+5
This obsoletes LittleLock, and so it is removed.
2014-02-16std: Rename unstable::mutex::Mutex to StaticNativeMutex.Huon Wilson-8/+8
This better reflects its purpose and design.
2014-02-16std: add an RAII unlocker to Mutex.Huon Wilson-15/+12
This automatically unlocks its lock when it goes out of scope, and provides a safe(ish) method to call .wait.
2014-02-14extern mod => extern crateAlex Crichton-1/+1
This was previously implemented, and it just needed a snapshot to go through
2014-02-14auto merge of #12186 : alexcrichton/rust/no-sleep-2, r=brsonbors-60/+99
Any single-threaded task benchmark will spend a good chunk of time in `kqueue()` on osx and `epoll()` on linux, and the reason for this is that each time a task is terminated it will hit the syscall. When a task terminates, it context switches back to the scheduler thread, and the scheduler thread falls out of `run_sched_once` whenever it figures out that it did some work. If we know that `epoll()` will return nothing, then we can continue to do work locally (only while there's work to be done). We must fall back to `epoll()` whenever there's active I/O in order to check whether it's ready or not, but without that (which is largely the case in benchmarks), we can prevent the costly syscall and can get a nice speedup. I've separated the commits into preparation for this change and then the change itself, the last commit message has more details.
2014-02-13Remove two allocations from spawning a green taskAlex Crichton-117/+124
Two unfortunate allocations were wrapping a proc() in a proc() with GreenTask::build_start_wrapper, and then boxing this proc in a ~proc() inside of Context::new(). Both of these allocations were a direct result from two conditions: 1. The Context::new() function has a nice api of taking a procedure argument to start up a new context with. This inherently required an allocation by build_start_wrapper because extra code needed to be run around the edges of a user-provided proc() for a new task. 2. The initial bootstrap code only understood how to pass one argument to the next function. By modifying the assembly and entry points to understand more than one argument, more information is passed through in registers instead of allocating a pointer-sized context. This is sadly where I end up throwing mips under a bus because I have no idea what's going on in the mips context switching code and don't know how to modify it. Closes #7767 cc #11389
2014-02-13Don't require an allocation for on_exit messagesAlex Crichton-3/+2
Instead, use an enum to allow running both a procedure and sending the task result over a channel. I expect the common case to be sending on a channel (e.g. task::try), so don't require an extra allocation in the common case. cc #11389
2014-02-13Fix a bug where cached stacks weren't re-usedAlex Crichton-2/+32
The condition was the wrong direction and it also didn't take equality into account. Tests were added for both cases. For the small benchmark of `task::try(proc() {}).unwrap()`, this takes the iteration time on OSX from 15119 ns/iter to 6179 ns/iter (timed with RUST_THREADS=1) cc #11389
2014-02-12Don't hit epoll unless a scheduler absolutely mustAlex Crichton-19/+50
Currently, a scheduler will hit epoll() or kqueue() at the end of *every task*. The reason is that the scheduler will context switch back to the scheduler task, terminate the previous task, and then return from run_sched_once. In doing so, the scheduler will poll for any active I/O. This shows up painfully in benchmarks that have no I/O at all. For example, this benchmark: for _ in range(0, 1000000) { spawn(proc() {}); } In this benchmark, the scheduler is currently wasting a good chunk of its time hitting epoll() when there's always active work to be done (run with RUST_THREADS=1). This patch uses the previous two commits to alter the scheduler's behavior to only return from run_sched_once if no work could be found when trying really really hard. If there is active I/O, this commit will perform the same as before, falling back to epoll() to check for I/O completion (to not starve I/O tasks). In the benchmark above, I got the following numbers: 12.554s on today's master 3.861s with #12172 applied 2.261s with both this and #12172 applied cc #8341
2014-02-12Percolate the (Scheduler, GreenTask) pair upwardsAlex Crichton-50/+56
This is in preparation for running do_work in a loop while there are no active I/O handles. This changes the do_work and interpret_message_queue methods to return a triple where the last element is a boolean flag as to whether work was done or not. This commit preserves the same behavior as before, it simply re-structures the code in preparation for future work.
2014-02-12Expose whether event loops have active I/OAlex Crichton-0/+2
The green scheduler can optimize its runtime based on this by deciding to not go to sleep in epoll() if there is no active I/O and there is a task to be stolen. This is implemented for librustuv by keeping a count of the number of tasks which are currently homed. If a task is homed, and then performs a blocking I/O operation, the count will be nonzero while the task is blocked. The homing count is intentionally 0 when there are I/O handles, but no handles currently blocked. The reason for this is that epoll() would only be used to wake up the scheduler anyway. The crux of this change was to have a `HomingMissile` contain a mutable borrowed reference back to the `HomeHandle`. The rest of the change was just dealing with this fallout. This reference is used to decrement the homed handle count in a HomingMissile's destructor. Also note that the count maintained is not atomic because all of its increments/decrements/reads are all on the same I/O thread.
2014-02-11Rewrite channels yet again for upgradeabilityAlex Crichton-2/+2
This, the Nth rewrite of channels, is not a rewrite of the core logic behind channels, but rather their API usage. In the past, we had the distinction between oneshot, stream, and shared channels, but the most recent rewrite dropped oneshots in favor of streams and shared channels. This distinction of stream vs shared has shown that it's not quite what we'd like either, and this moves the `std::comm` module in the direction of "one channel to rule them all". There now remains only one Chan and one Port. This new channel is actually a hybrid oneshot/stream/shared channel under the hood in order to optimize for the use cases in question. Additionally, this also reduces the cognitive burden of having to choose between a Chan or a SharedChan in an API. My simple benchmarks show no reduction in efficiency over the existing channels today, and a 3x improvement in the oneshot case. I sadly don't have a pre-last-rewrite compiler to test out the old old oneshots, but I would imagine that the performance is comparable, but slightly slower (due to atomic reference counting). This commit also brings the bonus bugfix to channels that the pending queue of messages are all dropped when a Port disappears rather then when both the Port and the Chan disappear.
2014-02-11Shuffle around ownership in concurrent queuesAlex Crichton-8/+70
Beforehand, using a concurrent queue always mandated that the "shared state" be stored internally to the queues in order to provide a safe interface. This isn't quite as flexible as one would want in some circumstances, so instead this commit moves the queues to not containing the shared state. The queues no longer have a "default useful safe" interface, but rather a "default safe" interface (minus the useful part). The queues have to be shared manually through an Arc or some other means. This allows them to be a little more flexible at the cost of a usability hindrance. I plan on using this new flexibility to upgrade a channel to a shared channel seamlessly.
2014-02-11Change `xfail` directives in compiletests to `ignore`, closes #11363Florian Hahn-2/+2
2014-02-11Move replace and swap to std::mem. Get rid of std::utilEdward Wang-6/+6
Also move Void to std::any, move drop to std::mem and reexport in prelude.
2014-02-07Delete send_str, rewrite clients on top of MaybeOwned<'static>Kevin Ballard-2/+2
Declare a `type SendStr = MaybeOwned<'static>` to ease readibility of types that needed the old SendStr behavior. Implement all the traits for MaybeOwned that SendStr used to implement.
2014-02-06Add some doc examples to lib{green,native}Alex Crichton-3/+149
"How do I start in libX" is a common question that I've seen, so I figured putting the examples in as many places as possible is probably a good idea.
2014-02-03Various bug fixes and rebase conflictsAlex Crichton-2/+1
2014-02-03std: Remove try_send_deferred plus all falloutAlex Crichton-9/+7
Now that extra::sync primitives are built on a proper mutex instead of a pthreads one, there's no longer any use for this function.
2014-02-03std: Hardcode pthread constants and structuresAlex Crichton-15/+11
This allows for easier static initialization of a pthread mutex, although the windows mutexes still sadly suffer. Note that this commit removes the clone() method from a mutex because it no longer makes sense for pthreads mutexes. This also removes the Once type for now, but it'll get added back shortly.
2014-02-03green: Remove io_error usageAlex Crichton-2/+3
2014-01-30Remove Times traitBrendan Zabarauskas-4/+4
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal was then lost after `do` was disabled for closures. It's time to let this one go.
2014-01-29Removing do keyword from libgreenScott Lawrence-101/+99
2014-01-26Removed all instances of XXX in preparation for relaxing of FIXME ruleSalem Talha-8/+8
2014-01-26auto merge of #11762 : alexcrichton/rust/guard_pages, r=alexcrichtonbors-37/+120
Rebasing of the previous PRs, I believe I've found the problems.
2014-01-26Bring in the line-length policeAlex Crichton-33/+35
2014-01-25Uppercase numeric constantsChris Wong-2/+2
The following are renamed: * `min_value` => `MIN` * `max_value` => `MAX` * `bits` => `BITS` * `bytes` => `BYTES` Fixes #10010.
2014-01-24Fix zero-sized memory mappingCorey Richardson-3/+15
2014-01-24Use `mmap` to map in task stacks and guard pageCorey Richardson-34/+103
Also implement caching of stacks.
2014-01-21[std::vec] Rename .remove_opt() to .remove(), drop the old .remove() behaviorSimon Sapin-1/+1
2014-01-21[std::vec] Rename .pop_opt() to .pop(), drop the old .pop() behaviorSimon Sapin-2/+5
2014-01-21Remove unnecessary parentheses.Huon Wilson-1/+1
2014-01-20Register new snapshotsAlex Crichton-2/+1
Upgrade the version to 0.10-pre
2014-01-15auto merge of #11112 : alexcrichton/rust/issue-11087, r=brsonbors-2/+3
This should allow callers to know whether the channel was empty or disconnected without having to block. Closes #11087
2014-01-15Allow more "error" values in try_recv()Alex Crichton-2/+3
This should allow callers to know whether the channel was empty or disconnected without having to block. Closes #11087
2014-01-15libstd: Added more #[inline] annotations and replaced uses of `libc::abort` ↵Eduard Burtescu-2/+2
with the intrinsic.
2014-01-12Bump version to 0.10-preBrian Anderson-0/+1
2014-01-09auto merge of #11360 : huonw/rust/stack_bounds, r=alexcrichtonbors-6/+7
We just approximate with a 2MB stack for native::start.
2014-01-07doc: Add libgreen and libnative to the indexBrian Anderson-0/+3
2014-01-07auto merge of #11353 : alexcrichton/rust/improve-logging, r=brsonbors-1/+5
This will allow capturing of common things like logging messages, stdout prints (using stdio println), and failure messages (printed to stderr). Any new prints added to libstd should be funneled through these task handles to allow capture as well. Additionally, this commit redirects logging back through a `Logger` trait so the log level can be usefully consumed by an arbitrary logger. This commit also introduces methods to set the task-local stdout handles: * std::io::stdio::set_stdout * std::io::stdio::set_stderr * std::io::logging::set_logger These methods all return the previous logger just in case it needs to be used for inspection. I plan on using this infrastructure for extra::test soon, but we don't quite have the primitives that I'd like to use for it, so it doesn't migrate extra::test at this time. Closes #6369
2014-01-07std::rt: require known stack bounds for all tasks.Huon Wilson-6/+7
We just approximate with a 1 or 2 MB stack for native::start.
2014-01-06Support arbitrary stdout/stderr/logger handlesAlex Crichton-1/+5
This will allow capturing of common things like logging messages, stdout prints (using stdio println), and failure messages (printed to stderr). Any new prints added to libstd should be funneled through these task handles to allow capture as well. Additionally, this commit redirects logging back through a `Logger` trait so the log level can be usefully consumed by an arbitrary logger. This commit also introduces methods to set the task-local stdout handles: * std::io::stdio::set_stdout * std::io::stdio::set_stderr * std::io::logging::set_logger These methods all return the previous logger just in case it needs to be used for inspection. I plan on using this infrastructure for extra::test soon, but we don't quite have the primitives that I'd like to use for it, so it doesn't migrate extra::test at this time. Closes #6369