From b81da278623d9dcda1776008612bd42e1922e9c3 Mon Sep 17 00:00:00 2001 From: "NODA, Kai" Date: Sat, 9 Jun 2018 21:13:04 +0800 Subject: libstd: add an RAII utility for sys_common::mutex::Mutex Signed-off-by: NODA, Kai --- src/libstd/thread/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/libstd/thread') 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) } } -- cgit 1.4.1-3-g733a5