about summary refs log tree commit diff
path: root/src/libstd/unstable/sync.rs
AgeCommit message (Collapse)AuthorLines
2014-06-06std: Extract librustrt out of libstdAlex Crichton-159/+0
As part of the libstd facade efforts, this commit extracts the runtime interface out of the standard library into a standalone crate, librustrt. This crate will provide the following services: * Definition of the rtio interface * Definition of the Runtime interface * Implementation of the Task structure * Implementation of task-local-data * Implementation of task failure via unwinding via libunwind * Implementation of runtime initialization and shutdown * Implementation of thread-local-storage for the local rust Task Notably, this crate avoids the following services: * Thread creation and destruction. The crate does not require the knowledge of an OS threading system, and as a result it seemed best to leave out the `rt::thread` module from librustrt. The librustrt module does depend on mutexes, however. * Implementation of backtraces. There is no inherent requirement for the runtime to be able to generate backtraces. As will be discussed later, this functionality continues to live in libstd rather than librustrt. As usual, a number of architectural changes were required to make this crate possible. Users of "stable" functionality will not be impacted by this change, but users of the `std::rt` module will likely note the changes. A list of architectural changes made is: * The stdout/stderr handles no longer live directly inside of the `Task` structure. This is a consequence of librustrt not knowing about `std::io`. These two handles are now stored inside of task-local-data. The handles were originally stored inside of the `Task` for perf reasons, and TLD is not currently as fast as it could be. For comparison, 100k prints goes from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable perf loss for the successful extraction of a librustrt crate. * The `rtio` module was forced to duplicate more functionality of `std::io`. As the module no longer depends on `std::io`, `rtio` now defines structures such as socket addresses, addrinfo fiddly bits, etc. The primary change made was that `rtio` now defines its own `IoError` type. This type is distinct from `std::io::IoError` in that it does not have an enum for what error occurred, but rather a platform-specific error code. The native and green libraries will be updated in later commits for this change, and the bulk of this effort was put behind updating the two libraries for this change (with `rtio`). * Printing a message on task failure (along with the backtrace) continues to live in libstd, not in librustrt. This is a consequence of the above decision to move the stdout/stderr handles to TLD rather than inside the `Task` itself. The unwinding API now supports registration of global callback functions which will be invoked when a task fails, allowing for libstd to register a function to print a message and a backtrace. The API for registering a callback is experimental and unsafe, as the ramifications of running code on unwinding is pretty hairy. * The `std::unstable::mutex` module has moved to `std::rt::mutex`. * The `std::unstable::sync` module has been moved to `std::rt::exclusive` and the type has been rewritten to not internally have an Arc and to have an RAII guard structure when locking. Old code should stop using `Exclusive` in favor of the primitives in `libsync`, but if necessary, old code should port to `Arc<Exclusive<T>>`. * The local heap has been stripped down to have fewer debugging options. None of these were tested, and none of these have been used in a very long time. [breaking-change]
2014-05-19std: Build Exclusive on Arc<Unsafe<T>>Alex Crichton-3/+5
This removes the usage of UnsafeArc
2014-05-02Replace most ~exprs with 'box'. #11779Brian Anderson-1/+1
2014-04-18std: Make ~[T] no longer a growable vectorAlex Crichton-1/+1
This removes all resizability support for ~[T] vectors in preparation of DST. The only growable vector remaining is Vec<T>. In summary, the following methods from ~[T] and various functions were removed. Each method/function has an equivalent on the Vec type in std::vec unless otherwise stated. * slice::OwnedCloneableVector * slice::OwnedEqVector * slice::append * slice::append_one * slice::build (no replacement) * slice::bytes::push_bytes * slice::from_elem * slice::from_fn * slice::with_capacity * ~[T].capacity() * ~[T].clear() * ~[T].dedup() * ~[T].extend() * ~[T].grow() * ~[T].grow_fn() * ~[T].grow_set() * ~[T].insert() * ~[T].pop() * ~[T].push() * ~[T].push_all() * ~[T].push_all_move() * ~[T].remove() * ~[T].reserve() * ~[T].reserve_additional() * ~[T].reserve_exect() * ~[T].retain() * ~[T].set_len() * ~[T].shift() * ~[T].shrink_to_fit() * ~[T].swap_remove() * ~[T].truncate() * ~[T].unshift() * ~str.clear() * ~str.set_len() * ~str.truncate() Note that no other API changes were made. Existing apis that took or returned ~[T] continue to do so. [breaking-change]
2014-03-31std: Switch field privacy as necessaryAlex Crichton-1/+1
2014-03-23std: Move NativeMutex from &mut self to &selfAlex Crichton-2/+2
The proper usage of shared types is now sharing through `&self` rather than `&mut self` because the mutable version will provide stronger guarantees (no aliasing on *any* thread).
2014-03-13std: Rename Chan/Port types and constructorAlex Crichton-3/+3
* Chan<T> => Sender<T> * Port<T> => Receiver<T> * Chan::new() => channel() * constructor returns (Sender, Receiver) instead of (Receiver, Sender) * local variables named `port` renamed to `rx` * local variables named `chan` renamed to `tx` Closes #11765
2014-02-16std: add a NativeMutex type as a wrapper to destroy StaticNativeMutex.Huon Wilson-47/+7
This obsoletes LittleLock, and so it is removed.
2014-02-16std: Rename unstable::mutex::Mutex to StaticNativeMutex.Huon Wilson-3/+3
This better reflects its purpose and design.
2014-02-16std: add an RAII unlocker to Mutex.Huon Wilson-18/+6
This automatically unlocks its lock when it goes out of scope, and provides a safe(ish) method to call .wait.
2014-02-03std: Fix tests with io_error usageAlex Crichton-1/+1
2014-01-29Removing do keyword from libstd and librustcScott Lawrence-4/+4
2013-12-24std: Get stdtest all passing againAlex Crichton-2/+1
This commit brings the library up-to-date in order to get all tests passing again
2013-12-24std: Introduce std::syncAlex Crichton-477/+4
For now, this moves the following modules to std::sync * UnsafeArc (also removed unwrap method) * mpsc_queue * spsc_queue * atomics * mpmc_bounded_queue * deque We may want to remove some of the queues, but for now this moves things out of std::rt into std::sync
2013-12-16Fallout of rewriting std::commAlex Crichton-12/+11
2013-12-10libstd: Change `atomically` to use RAII.Patrick Walton-15/+45
2013-12-10libstd: Remove `Cell`s that were used because of `finally` by convertingPatrick Walton-27/+42
their `finally` blocks to RAII.
2013-12-08Remove dead codesKiet Tran-0/+1
2013-12-03Move std::util::ignore to std::prelude::dropSteven Fackler-4/+3
It's a more fitting name for the most common use case of this function.
2013-12-01remove useless `transmute_immut` functionDaniel Micay-1/+1
2013-11-28Register new snapshotsAlex Crichton-1/+1
2013-11-26librustc: Fix merge fallout.Patrick Walton-2/+2
2013-11-26libstd: Remove all non-`proc` uses of `do` from libstdPatrick Walton-38/+19
2013-11-25Move LittleLock to using RAIIAlex Crichton-69/+50
This moves the locking/waiting methods to returning an RAII struct instead of relying on closures. Additionally, this changes the methods to all take '&mut self' to discourage recursive locking. The new method to block is to call `wait` on the returned RAII structure instead of calling it on the lock itself (this enforces that the lock is held). At the same time, this improves the Mutex interface a bit by allowing destruction of non-initialized members and by allowing construction of an empty mutex (nothing initialized inside).
2013-11-24Remove linked failure from the runtimeAlex Crichton-82/+58
The reasons for doing this are: * The model on which linked failure is based is inherently complex * The implementation is also very complex, and there are few remaining who fully understand the implementation * There are existing race conditions in the core context switching function of the scheduler, and possibly others. * It's unclear whether this model of linked failure maps well to a 1:1 threading model Linked failure is often a desired aspect of tasks, but we would like to take a much more conservative approach in re-implementing linked failure if at all. Closes #8674 Closes #8318 Closes #8863
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-8/+8
2013-11-18Remove the C++ lock_and_signal typeAlex Crichton-25/+16
A the same time this purges all runtime support needed for statically initialized mutexes, moving all users over to the new Mutex type instead.
2013-11-13add rust_trylock_little_lockJason Toffaletti-1/+16
Try to acquire lock and succeed only if lock is not already held. Uses TryEnterCriticalSection or pthread_mutex_trylock.
2013-11-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-6/+8
These two attributes are no longer useful now that Rust has decided to leave segmented stacks behind. It is assumed that the rust task's stack is always large enough to make an FFI call (due to the stack being very large). There's always the case of stack overflow, however, to consider. This does not change the behavior of stack overflow in Rust. This is still normally triggered by the __morestack function and aborts the whole process. C stack overflow will continue to corrupt the stack, however (as it did before this commit as well). The future improvement of a guard page at the end of every rust stack is still unimplemented and is intended to be the mechanism through which we attempt to detect C stack overflow. Closes #8822 Closes #10155
2013-10-28Register new snapshotsAlex Crichton-5/+4
2013-10-28Allow fail messages to be caught, and introduce the Any traitMarvin Löbel-11/+31
Some code cleanup, sorting of import blocks Removed std::unstable::UnsafeArc's use of Either Added run-fail tests for the new FailWithCause impls Changed future_result and try to return Result<(), ~Any>. - Internally, there is an enum of possible fail messages passend around. - In case of linked failure or a string message, the ~Any gets lazyly allocated in future_results recv method. - For that, future result now returns a wrapper around a Port. - Moved and renamed task::TaskResult into rt::task::UnwindResult and made it an internal enum. - Introduced a replacement typedef `type TaskResult = Result<(), ~Any>`.
2013-10-24Implement a basic event loop built on LittleLockAlex Crichton-0/+47
It's not guaranteed that there will always be an event loop to run, and this implementation will serve as an incredibly basic one which does not provide any I/O, but allows the scheduler to still run. cc #9128
2013-10-23Removed Unnecessary comments and white spaces #4386reedlepee-3/+0
2013-10-23Making fields in std and extra : private #4386reedlepee-2/+5
2013-10-22Drop the '2' suffix from logging macrosAlex Crichton-3/+3
Who doesn't like a massive renaming?
2013-10-18auto merge of #9926 : Kimundi/rust/future_result_bad_sig, r=huonwbors-7/+4
2013-10-18Made `std::task::TaskBuilder::future_result()` easier to useMarvin Löbel-7/+4
2013-10-17std: Move size/align functions to std::mem. #2240Brian Anderson-1/+1
2013-10-08make small ty_struct immediateDaniel Micay-1/+3
Closes #9651
2013-09-30std: Remove usage of fmt!Alex Crichton-3/+3
2013-09-18Register new snapshotsAlex Crichton-17/+0
2013-09-16switch Drop to `&mut self`Daniel Micay-2/+2
2013-08-29reduce the size of UnsafeArc from 2 words to 1Daniel Micay-1/+9
2013-08-27librustc: Ensure that type parameters are in the right positions in paths.Patrick Walton-1/+2
This removes the stacking of type parameters that occurs when invoking trait methods, and fixes all places in the standard library that were relying on it. It is somewhat awkward in places; I think we'll probably want something like the `Foo::<for T>::new()` syntax.
2013-08-27std: use ArcData rather than c_void in UnsafeArc.Huon Wilson-17/+12
This means that fewer `transmute`s are required, so there is less chance of a `transmute` not having the corresponding `forget` (possibly leading to use-after-free, etc).
2013-08-27Rename UnsafeAtomicRcBox to UnsafeArc. Fixes #7674.Huon Wilson-42/+42
2013-08-23std: Reduce TLS accessBrian Anderson-12/+16
2013-08-22Enabled unit tests in std and extra.Vadim Chugunov-3/+3
2013-08-19Add externfn macro and correctly label fixed_stack_segmentsNiko Matsakis-6/+20
2013-08-16Reserve 'yield' keywordKevin Ballard-10/+10
Rename task::yield() to task::deschedule(). Fixes #8494.