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_common/thread_local.rs | |
| 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_common/thread_local.rs')
| -rw-r--r-- | src/libstd/sys_common/thread_local.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/libstd/sys_common/thread_local.rs b/src/libstd/sys_common/thread_local.rs index d0d6224de0a..75f6b9ac7fd 100644 --- a/src/libstd/sys_common/thread_local.rs +++ b/src/libstd/sys_common/thread_local.rs @@ -162,13 +162,12 @@ impl StaticKey { // we just simplify the whole branch. if imp::requires_synchronized_create() { static INIT_LOCK: Mutex = Mutex::new(); - INIT_LOCK.lock(); + let _guard = INIT_LOCK.lock(); let mut key = self.key.load(Ordering::SeqCst); if key == 0 { key = imp::create(self.dtor) as usize; self.key.store(key, Ordering::SeqCst); } - INIT_LOCK.unlock(); rtassert!(key != 0); return key } |
