about summary refs log tree commit diff
path: root/src/libstd/sys/common
AgeCommit message (Collapse)AuthorLines
2014-12-18std: Move the panic flag to its own thread localAlex Crichton-11/+0
This flag is somewhat tied to the `unwind` module rather than the `thread_info` module, so this commit moves it into that module as well as allowing the same OS thread to call `unwind::try` multiple times. Previously once a thread panicked its panic flag was never reset, even after exiting the panic handler.
2014-12-18Revise std::thread API to join by defaultAaron Turon-10/+12
This commit is part of a series that introduces a `std::thread` API to replace `std::task`. In the new API, `spawn` returns a `JoinGuard`, which by default will join the spawned thread when dropped. It can also be used to join explicitly at any time, returning the thread's result. Alternatively, the spawned thread can be explicitly detached (so no join takes place). As part of this change, Rust processes now terminate when the main thread exits, even if other detached threads are still running, moving Rust closer to standard threading models. This new behavior may break code that was relying on the previously implicit join-all. In addition to the above, the new thread API also offers some built-in support for building blocking abstractions in user space; see the module doc for details. Closes #18000 [breaking-change]
2014-12-18Avoid .take().unwrap() with FnOnce closuresAlex Crichton-3/+2
2014-12-18Fallout from new thread APIAaron Turon-12/+13
2014-12-18Revise rt::unwindAaron Turon-6/+24
2014-12-18Remove rt::{mutex, exclusive}Aaron Turon-3/+2
2014-12-18Introduce std::threadAaron Turon-0/+60
Also removes: * `std::task` * `std::rt::task` * `std::rt::thread` Notes for the new API are in a follow-up commit. Closes #18000
2014-12-18Remove rt::bookkeepingAaron Turon-2/+1
This commit removes the runtime bookkeeping previously used to ensure that all Rust tasks were joined before the runtime was shut down. This functionality will be replaced by an RAII style `Thread` API, that will also offer a detached mode. Since this changes the semantics of shutdown, it is a: [breaking-change]
2014-12-18libs: merge librustrt into libstdAaron Turon-5/+497
This commit merges the `rustrt` crate into `std`, undoing part of the facade. This merger continues the paring down of the runtime system. Code relying on the public API of `rustrt` will break; some of this API is now available through `std::rt`, but is likely to change and/or be removed very soon. [breaking-change]
2014-12-15Remove internal uses of `marker::NoCopy`Jorge Aparicio-3/+0
2014-12-14Mostly rote conversion of `proc()` to `move||` (and occasionally `Thunk::new`)Niko Matsakis-2/+2
2014-12-13libstd: use unboxed closuresJorge Aparicio-21/+27
2014-12-09rollup merge of #19577: aidancully/masterAlex Crichton-1/+17
pthread_key_create can be 0. addresses issue #19567.
2014-12-05prefer "FIXME" to "TODO".Aidan Cully-1/+1
2014-12-05work around portability issue on FreeBSD, in which the key returned fromAidan Cully-1/+17
pthread_key_create can be 0.
2014-12-05Fall out of the std::sync rewriteAlex Crichton-12/+21
2014-12-05std: Rewrite the `sync` moduleAlex Crichton-1/+221
This commit is a reimplementation of `std::sync` to be based on the system-provided primitives wherever possible. The previous implementation was fundamentally built on top of channels, and as part of the runtime reform it has become clear that this is not the level of abstraction that the standard level should be providing. This rewrite aims to provide as thin of a shim as possible on top of the system primitives in order to make them safe. The overall interface of the `std::sync` module has in general not changed, but there are a few important distinctions, highlighted below: * The condition variable type, `Condvar`, has been separated out of a `Mutex`. A condition variable is now an entirely separate type. This separation benefits users who only use one mutex, and provides a clearer distinction of who's responsible for managing condition variables (the application). * All of `Condvar`, `Mutex`, and `RWLock` are now directly built on top of system primitives rather than using a custom implementation. The `Once`, `Barrier`, and `Semaphore` types are still built upon these abstractions of the system primitives. * The `Condvar`, `Mutex`, and `RWLock` types all have a new static type and constant initializer corresponding to them. These are provided primarily for C FFI interoperation, but are often useful to otherwise simply have a global lock. The types, however, will leak memory unless `destroy()` is called on them, which is clearly documented. * The `Condvar` implementation for an `RWLock` write lock has been removed. This may be added back in the future with a userspace implementation, but this commit is focused on exposing the system primitives first. * The fundamental architecture of this design is to provide two separate layers. The first layer is that exposed by `sys_common` which is a cross-platform bare-metal abstraction of the system synchronization primitives. No attempt is made at making this layer safe, and it is quite unsafe to use! It is currently not exported as part of the API of the standard library, but the stabilization of the `sys` module will ensure that these will be exposed in time. The purpose of this layer is to provide the core cross-platform abstractions if necessary to implementors. The second layer is the layer provided by `std::sync` which is intended to be the thinnest possible layer on top of `sys_common` which is entirely safe to use. There are a few concerns which need to be addressed when making these system primitives safe: * Once used, the OS primitives can never be **moved**. This means that they essentially need to have a stable address. The static primitives use `&'static self` to enforce this, and the non-static primitives all use a `Box` to provide this guarantee. * Poisoning is leveraged to ensure that invalid data is not accessible from other tasks after one has panicked. In addition to these overall blanket safety limitations, each primitive has a few restrictions of its own: * Mutexes and rwlocks can only be unlocked from the same thread that they were locked by. This is achieved through RAII lock guards which cannot be sent across threads. * Mutexes and rwlocks can only be unlocked if they were previously locked. This is achieved by not exposing an unlocking method. * A condition variable can only be waited on with a locked mutex. This is achieved by requiring a `MutexGuard` in the `wait()` method. * A condition variable cannot be used concurrently with more than one mutex. This is guaranteed by dynamically binding a condition variable to precisely one mutex for its entire lifecycle. This restriction may be able to be relaxed in the future (a mutex is unbound when no threads are waiting on the condvar), but for now it is sufficient to guarantee safety. * Condvars now support timeouts for their blocking operations. The implementation for these operations is provided by the system. Due to the modification of the `Condvar` API, removal of the `std::sync::mutex` API, and reimplementation, this is a breaking change. Most code should be fairly easy to port using the examples in the documentation of these primitives. [breaking-change] Closes #17094 Closes #18003
2014-11-26auto merge of #19169 : aturon/rust/fds, r=alexcrichtonbors-5/+4
This PR adds some internal infrastructure to allow the private `std::sys` module to access internal representation details of `std::io`. It then exposes those details in two new, platform-specific API surfaces: `std::os::unix` and `std::os::windows`. To start with, these will provide the ability to extract file descriptors, HANDLEs, SOCKETs, and so on from `std::io` types. More functionality, and more specific platforms (e.g. `std::os::linux`) will be added over time. Closes #18897
2014-11-24std: Leak all statically allocated TLS keysAlex Crichton-35/+2
It turns out that rustrt::at_exit() doesn't actually occur after all pthread threads have exited (nor does atexit()), so there's not actually a known point at which we can deallocate these keys. It's not super critical that we do so, however, because we're about to exit anyway! Closes #19280
2014-11-23std: Add a new top-level thread_local moduleAlex Crichton-0/+307
This commit removes the `std::local_data` module in favor of a new `std::thread_local` module providing thread local storage. The module provides two variants of TLS: one which owns its contents and one which is based on scoped references. Each implementation has pros and cons listed in the documentation. Both flavors have accessors through a function called `with` which yield a reference to a closure provided. Both flavors also panic if a reference cannot be yielded and provide a function to test whether an access would panic or not. This is an implementation of [RFC 461][rfc] and full details can be found in that RFC. This is a breaking change due to the removal of the `std::local_data` module. All users can migrate to the new thread local system like so: thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None))) The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as an implementation detail which must now be explicitly stated by users. [rfc]: https://github.com/rust-lang/rfcs/pull/461 [breaking-change]
2014-11-21sys: reveal std::io representation to sys moduleAaron Turon-5/+4
This commit adds a `AsInner` trait to `sys_common` and provides implementations on many `std::io` types. This is a building block for exposing platform-specific APIs that hook into `std::io` types.
2014-11-20Make most of std::rt privateAaron Turon-4/+4
Previously, the entire runtime API surface was publicly exposed, but that is neither necessary nor desirable. This commit hides most of the module, using librustrt directly as needed. The arrangement will need to be revisited when rustrt is pulled into std. [breaking-change]
2014-11-20Fallout from libgreen and libnative removalAaron Turon-1/+1
2014-11-17Switch to purely namespaced enumsSteven Fackler-0/+3
This breaks code that referred to variant names in the same namespace as their enum. Reexport the variants in the old location or alter code to refer to the new locations: ``` pub enum Foo { A, B } fn main() { let a = A; } ``` => ``` pub use self::Foo::{A, B}; pub enum Foo { A, B } fn main() { let a = A; } ``` or ``` pub enum Foo { A, B } fn main() { let a = Foo::A; } ``` [breaking-change]
2014-11-17Fix fallout from coercion removalNick Cameron-2/+2
2014-11-13Remove lots of numeric traits from the preludesBrendan Zabarauskas-0/+2
Num, NumCast, Unsigned, Float, Primitive and Int have been removed.
2014-11-13Deprecate Zero and One traitsBrendan Zabarauskas-3/+2
2014-11-10Fix 'renamed lint' warningsMichael Gehring-1/+1
2014-11-08Runtime removal: refactor ttyAaron Turon-0/+8
This patch continues runtime removal by moving the tty implementations into `sys`. Because this eliminates APIs in `libnative` and `librustrt`, it is a: [breaking-change] This functionality is likely to be available publicly, in some form, from `std` in the future.
2014-11-08Runtime removal: refactor processAaron Turon-11/+0
This patch continues the runtime removal by moving and refactoring the process implementation into the new `sys` module. Because this eliminates APIs in `libnative` and `librustrt`, it is a: [breaking-change] This functionality is likely to be available publicly, in some form, from `std` in the future.
2014-11-08Runtime removal: refactor helper threadsAaron Turon-0/+145
This patch continues the runtime removal by moving libnative::io::helper_thread into sys::helper_signal and sys_common::helper_thread Because this eliminates APIs in `libnative` and `librustrt`, it is a: [breaking-change] This functionality is likely to be available publicly, in some form, from `std` in the future.
2014-11-08Runtime removal: refactor pipes and networkingAaron Turon-0/+909
This patch continues the runtime removal by moving pipe and networking-related code into `sys`. Because this eliminates APIs in `libnative` and `librustrt`, it is a: [breaking-change] This functionality is likely to be available publicly, in some form, from `std` in the future.
2014-11-08Runtime removal: add private sys, sys_common modulesAaron Turon-0/+91
These modules will house the code that used to be part of the runtime system in libnative. The `sys_common` module contains a few low-level but cross-platform details. The `sys` module is set up using `#[cfg()]` to include either a unix or windows implementation of a common API surface. This API surface is *not* exported directly in `libstd`, but is instead used to bulid `std::os` and `std::io`. Ultimately, the low-level details in `sys` will be exposed in a controlled way through a separate platform-specific surface, but that setup is not part of this patch.