about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-17 20:11:35 +0000
committerbors <bors@rust-lang.org>2018-06-17 20:11:35 +0000
commit86a8f1a6374dd558ebdafe061e61720a73ae732c (patch)
treeb2e2ad7987a2ffd9c8b987c38710b68206452c2f /src/libstd/thread
parent2b973e653257f965e33a61b58c0eb7e863aed6c8 (diff)
parentb81da278623d9dcda1776008612bd42e1922e9c3 (diff)
downloadrust-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/thread')
-rw-r--r--src/libstd/thread/mod.rs5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index 1b976b79b4c..1dacf99b64b 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -935,20 +935,17 @@ impl ThreadId {
         static mut COUNTER: u64 = 0;
 
         unsafe {
-            GUARD.lock();
+            let _guard = GUARD.lock();
 
             // If we somehow use up all our bits, panic so that we're not
             // covering up subtle bugs of IDs being reused.
             if COUNTER == ::u64::MAX {
-                GUARD.unlock();
                 panic!("failed to generate unique thread ID: bitspace exhausted");
             }
 
             let id = COUNTER;
             COUNTER += 1;
 
-            GUARD.unlock();
-
             ThreadId(id)
         }
     }