diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-11-14 00:21:43 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-18 20:06:40 -0800 |
| commit | e8bf0788027932a0b547819cc9edd13c40426e36 (patch) | |
| tree | 9f64d86fc4275a096ad2236c198451a663c665be /src/libstd/rt | |
| parent | 24eb1b445dd878c12ca6503a9fa040179b94e614 (diff) | |
| download | rust-e8bf0788027932a0b547819cc9edd13c40426e36.tar.gz rust-e8bf0788027932a0b547819cc9edd13c40426e36.zip | |
Remove the C++ lock_and_signal type
A the same time this purges all runtime support needed for statically initialized mutexes, moving all users over to the new Mutex type instead.
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/args.rs | 53 | ||||
| -rw-r--r-- | src/libstd/rt/local_ptr.rs | 12 | ||||
| -rw-r--r-- | src/libstd/rt/test.rs | 20 |
3 files changed, 52 insertions, 33 deletions
diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 48e58879026..b9238224d6e 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -21,32 +21,42 @@ //! FIXME #7756: This has a lot of C glue for lack of globals. use option::Option; +#[cfg(test)] use option::{Some, None}; +#[cfg(test)] use realstd; +#[cfg(test)] use realargs = realstd::rt::args; /// One-time global initialization. -pub unsafe fn init(argc: int, argv: **u8) { - imp::init(argc, argv) -} +#[cfg(not(test))] +pub unsafe fn init(argc: int, argv: **u8) { imp::init(argc, argv) } +#[cfg(test)] +pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } /// One-time global cleanup. -pub fn cleanup() { - imp::cleanup() -} +#[cfg(not(test))] pub fn cleanup() { imp::cleanup() } +#[cfg(test)] pub fn cleanup() { realargs::cleanup() } /// Take the global arguments from global storage. -pub fn take() -> Option<~[~str]> { - imp::take() +#[cfg(not(test))] pub fn take() -> Option<~[~str]> { imp::take() } +#[cfg(test)] pub fn take() -> Option<~[~str]> { + match realargs::take() { + realstd::option::Some(a) => Some(a), + realstd::option::None => None, + } } /// Give the global arguments to global storage. /// /// It is an error if the arguments already exist. -pub fn put(args: ~[~str]) { - imp::put(args) -} +#[cfg(not(test))] pub fn put(args: ~[~str]) { imp::put(args) } +#[cfg(test)] pub fn put(args: ~[~str]) { realargs::put(args) } /// Make a clone of the global arguments. -pub fn clone() -> Option<~[~str]> { - imp::clone() +#[cfg(not(test))] pub fn clone() -> Option<~[~str]> { imp::clone() } +#[cfg(test)] pub fn clone() -> Option<~[~str]> { + match realargs::clone() { + realstd::option::Some(a) => Some(a), + realstd::option::None => None, + } } #[cfg(target_os = "linux")] @@ -58,9 +68,12 @@ mod imp { use iter::Iterator; use str; use unstable::finally::Finally; + use unstable::mutex::{Mutex, MUTEX_INIT}; use util; use vec; + static mut global_args_ptr: uint = 0; + pub unsafe fn init(argc: int, argv: **u8) { let args = load_argc_and_argv(argc, argv); put(args); @@ -94,20 +107,22 @@ mod imp { } fn with_lock<T>(f: &fn() -> T) -> T { + static mut lock: Mutex = MUTEX_INIT; + do (|| { unsafe { - rust_take_global_args_lock(); + lock.lock(); f() } }).finally { unsafe { - rust_drop_global_args_lock(); + lock.unlock(); } } } fn get_global_ptr() -> *mut Option<~~[~str]> { - unsafe { rust_get_global_args_ptr() } + unsafe { cast::transmute(&global_args_ptr) } } // Copied from `os`. @@ -117,12 +132,6 @@ mod imp { } } - extern { - fn rust_take_global_args_lock(); - fn rust_drop_global_args_lock(); - fn rust_get_global_args_ptr() -> *mut Option<~~[~str]>; - } - #[cfg(test)] mod tests { use option::{Some, None}; diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index f35b657d9dd..d5d1931a217 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -21,17 +21,23 @@ use ptr; use cell::Cell; use option::{Option, Some, None}; use unstable::finally::Finally; +use unstable::mutex::{Mutex, MUTEX_INIT}; use tls = rt::thread_local_storage; static mut RT_TLS_KEY: tls::Key = -1; /// Initialize the TLS key. Other ops will fail if this isn't executed first. pub fn init_tls_key() { + static mut lock: Mutex = MUTEX_INIT; + static mut initialized: bool = false; + unsafe { - rust_initialize_rt_tls_key(&mut RT_TLS_KEY); - extern { - fn rust_initialize_rt_tls_key(key: *mut tls::Key); + lock.lock(); + if !initialized { + tls::create(&mut RT_TLS_KEY); + initialized = true; } + lock.unlock(); } } diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 19ab36a6ac4..c1a7893f5a5 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -14,7 +14,6 @@ use cell::Cell; use clone::Clone; use container::Container; use iter::{Iterator, range}; -use libc; use option::{Some, None}; use os; use path::GenericPath; @@ -361,11 +360,16 @@ pub fn cleanup_task(mut task: ~Task) { /// Get a port number, starting at 9600, for use in tests pub fn next_test_port() -> u16 { + use unstable::mutex::{Mutex, MUTEX_INIT}; + static mut lock: Mutex = MUTEX_INIT; + static mut next_offset: u16 = 0; unsafe { - return rust_dbg_next_port(base_port() as libc::uintptr_t) as u16; - } - extern { - fn rust_dbg_next_port(base: libc::uintptr_t) -> libc::uintptr_t; + let base = base_port(); + lock.lock(); + let ret = base + next_offset; + next_offset += 1; + lock.unlock(); + return ret; } } @@ -395,13 +399,13 @@ The bots run multiple builds at the same time, and these builds all want to use ports. This function figures out which workspace it is running in and assigns a port range based on it. */ -fn base_port() -> uint { +fn base_port() -> u16 { use os; use str::StrSlice; use vec::ImmutableVector; - let base = 9600u; - let range = 1000; + let base = 9600u16; + let range = 1000u16; let bases = [ ("32-opt", base + range * 1), |
