diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-11-15 18:01:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-15 18:01:58 +0100 |
| commit | 6e5a4c1385946386635b9e97aa0ecc79632211cd (patch) | |
| tree | 5fc86aaa23530d9d9fed91322618994518fb4147 /src/libstd/sys | |
| parent | 1bd30ce2aac40c7698aa4a1b9520aa649ff2d1c5 (diff) | |
| parent | 88717319142e162ae2f48124d94f33d2c21bc2ce (diff) | |
| download | rust-6e5a4c1385946386635b9e97aa0ecc79632211cd.tar.gz rust-6e5a4c1385946386635b9e97aa0ecc79632211cd.zip | |
Rollup merge of #66350 - hermitcore:hermit, r=rkruppe
protect creation of destructors by a mutex - add on HermitCore an additional lock to protect static data
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/hermit/thread_local.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libstd/sys/hermit/thread_local.rs b/src/libstd/sys/hermit/thread_local.rs index 4bc8c4d5883..268fb770eae 100644 --- a/src/libstd/sys/hermit/thread_local.rs +++ b/src/libstd/sys/hermit/thread_local.rs @@ -3,6 +3,7 @@ use crate::collections::BTreeMap; use crate::ptr; use crate::sync::atomic::{AtomicUsize, Ordering}; +use crate::sys_common::mutex::Mutex; pub type Key = usize; @@ -11,6 +12,7 @@ type Dtor = unsafe extern fn(*mut u8); static NEXT_KEY: AtomicUsize = AtomicUsize::new(0); static mut KEYS: *mut BTreeMap<Key, Option<Dtor>> = ptr::null_mut(); +static KEYS_LOCK: Mutex = Mutex::new(); #[thread_local] static mut LOCALS: *mut BTreeMap<Key, *mut u8> = ptr::null_mut(); @@ -32,6 +34,7 @@ unsafe fn locals() -> &'static mut BTreeMap<Key, *mut u8> { #[inline] pub unsafe fn create(dtor: Option<Dtor>) -> Key { let key = NEXT_KEY.fetch_add(1, Ordering::SeqCst); + let _guard = KEYS_LOCK.lock(); keys().insert(key, dtor); key } |
