Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion library/std/src/sys/thread_local/key/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ pub type Key = libc::pthread_key_t;
#[inline]
pub fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
let mut key = 0;
assert_eq!(unsafe { libc::pthread_key_create(&mut key, mem::transmute(dtor)) }, 0);
if unsafe { libc::pthread_key_create(&mut key, mem::transmute(dtor)) } != 0 {
rtabort!("out of TLS keys");
}
key
}

Expand Down
17 changes: 7 additions & 10 deletions library/std/src/sys/thread_local/key/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,10 @@ impl LazyKey {
} else {
let key = unsafe { c::TlsAlloc() };
if key == c::TLS_OUT_OF_INDEXES {
// Wakeup the waiting threads before panicking to avoid deadlock.
unsafe {
c::InitOnceComplete(
self.once.get(),
c::INIT_ONCE_INIT_FAILED,
ptr::null_mut(),
);
}
panic!("out of TLS indexes");
// Since we abort the process, there is no need to wake up
// the waiting threads. If this were a panic, the wakeup
// would need to occur first in order to avoid deadlock.
rtabort!("out of TLS indexes");
}

unsafe {
Expand All @@ -112,7 +107,9 @@ impl LazyKey {
// If there is no destructor to clean up, we can use racy initialization.

let key = unsafe { c::TlsAlloc() };
assert_ne!(key, c::TLS_OUT_OF_INDEXES, "out of TLS indexes");
if key == c::TLS_OUT_OF_INDEXES {
rtabort!("out of TLS indexes");
}

match self.key.compare_exchange(0, key + 1, AcqRel, Acquire) {
Ok(_) => key,
Expand Down
Loading