diff options
| author | bors <bors@rust-lang.org> | 2018-06-17 20:11:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-06-17 20:11:35 +0000 |
| commit | 86a8f1a6374dd558ebdafe061e61720a73ae732c (patch) | |
| tree | b2e2ad7987a2ffd9c8b987c38710b68206452c2f /src/libstd/sys/redox | |
| parent | 2b973e653257f965e33a61b58c0eb7e863aed6c8 (diff) | |
| parent | b81da278623d9dcda1776008612bd42e1922e9c3 (diff) | |
| download | rust-86a8f1a6374dd558ebdafe061e61720a73ae732c.tar.gz rust-86a8f1a6374dd558ebdafe061e61720a73ae732c.zip | |
Auto merge of #51529 - nodakai:improve-sys_common-mutex, r=oli-obk
libstd: add an RAII utility for sys_common::mutex::Mutex It is indeed debatable whether or not we should introduce more sophistication like this to the lowest layer of a system library. In fact, `Drop::drop()` cannot be `unsafe` (IIRC there was a discussion on introducing an unsafe variant of `Drop` whose entire scope must be within `unsafe`)
Diffstat (limited to 'src/libstd/sys/redox')
| -rw-r--r-- | src/libstd/sys/redox/args.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/libstd/sys/redox/args.rs b/src/libstd/sys/redox/args.rs index 59ae2a74a6d..556ed77372e 100644 --- a/src/libstd/sys/redox/args.rs +++ b/src/libstd/sys/redox/args.rs @@ -73,17 +73,15 @@ mod imp { CStr::from_ptr(*argv.offset(i) as *const libc::c_char).to_bytes().to_vec() }).collect(); - LOCK.lock(); + let _guard = LOCK.lock(); let ptr = get_global_ptr(); assert!((*ptr).is_none()); (*ptr) = Some(box args); - LOCK.unlock(); } pub unsafe fn cleanup() { - LOCK.lock(); + let _guard = LOCK.lock(); *get_global_ptr() = None; - LOCK.unlock(); } pub fn args() -> Args { @@ -96,16 +94,14 @@ mod imp { fn clone() -> Option<Vec<Vec<u8>>> { unsafe { - LOCK.lock(); + let _guard = LOCK.lock(); let ptr = get_global_ptr(); - let ret = (*ptr).as_ref().map(|s| (**s).clone()); - LOCK.unlock(); - return ret + (*ptr).as_ref().map(|s| (**s).clone()) } } - fn get_global_ptr() -> *mut Option<Box<Vec<Vec<u8>>>> { - unsafe { mem::transmute(&GLOBAL_ARGS_PTR) } + unsafe fn get_global_ptr() -> *mut Option<Box<Vec<Vec<u8>>>> { + mem::transmute(&GLOBAL_ARGS_PTR) } } |
