relibc: P5-robust-mutex-enotrec-fix — apply Phase 0e patch
This commit is contained in:
+7
-3
@@ -43,9 +43,13 @@ pub unsafe fn init() {
|
||||
thread.stack_size = STACK_SIZE;
|
||||
}
|
||||
|
||||
unsafe { Tcb::current() }
|
||||
.expect_notls("no TCB present for main thread")
|
||||
.pthread = thread;
|
||||
let tcb = unsafe { Tcb::current() }
|
||||
.expect_notls("no TCB present for main thread");
|
||||
tcb.pthread = thread;
|
||||
|
||||
OS_TID_TO_PTHREAD
|
||||
.lock()
|
||||
.insert(Sys::current_os_tid(), ForceSendSync(tcb as *const Tcb as *mut Tcb));
|
||||
}
|
||||
|
||||
//static NEXT_INDEX: AtomicU32 = AtomicU32::new(FIRST_THREAD_IDX + 1);
|
||||
|
||||
@@ -136,11 +136,7 @@ impl RlctMutex {
|
||||
Err(thread) => {
|
||||
let owner = thread & INDEX_MASK;
|
||||
|
||||
if !crate::pthread::mutex_owner_id_is_live(owner) {
|
||||
if !self.robust {
|
||||
return Err(Errno(ENOTRECOVERABLE));
|
||||
}
|
||||
|
||||
if !crate::pthread::mutex_owner_id_is_live(owner) && self.robust {
|
||||
let new_value = (thread & WAITING_BIT) | FUTEX_OWNER_DIED | this_thread;
|
||||
match self.inner.compare_exchange(
|
||||
thread,
|
||||
@@ -151,6 +147,11 @@ impl RlctMutex {
|
||||
Ok(_) => return self.finish_lock_acquire(true),
|
||||
Err(_) => continue,
|
||||
}
|
||||
} else if !crate::pthread::mutex_owner_id_is_live(owner) {
|
||||
// Non-robust mutex with apparently-dead owner: per POSIX the
|
||||
// behaviour is undefined. We conservatively keep spinning /
|
||||
// futex-waiting rather than returning ENOTRECOVERABLE, which
|
||||
// would crash any Rust std::sync::Mutex user.
|
||||
}
|
||||
|
||||
if spins_left > 0 {
|
||||
|
||||
Reference in New Issue
Block a user