Skip to content

Commit 2e99a88

Browse files
committed
Add diagnostic items to sys::Mutex
1 parent 77101fe commit 2e99a88

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,9 @@ symbols! {
20712071
sym,
20722072
sync,
20732073
synthetic,
2074+
sys_mutex_lock,
2075+
sys_mutex_try_lock,
2076+
sys_mutex_unlock,
20742077
t32,
20752078
target,
20762079
target_abi,

library/std/src/sys/sync/mutex/futex.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ impl Mutex {
1919
}
2020

2121
#[inline]
22+
#[cfg_attr(not(test), rustc_diagnostic_item = "sys_mutex_try_lock")]
2223
pub fn try_lock(&self) -> bool {
2324
self.futex.compare_exchange(UNLOCKED, LOCKED, Acquire, Relaxed).is_ok()
2425
}
2526

2627
#[inline]
28+
#[cfg_attr(not(test), rustc_diagnostic_item = "sys_mutex_lock")]
2729
pub fn lock(&self) {
2830
if self.futex.compare_exchange(UNLOCKED, LOCKED, Acquire, Relaxed).is_err() {
2931
self.lock_contended();
@@ -80,6 +82,7 @@ impl Mutex {
8082
}
8183

8284
#[inline]
85+
#[cfg_attr(not(test), rustc_diagnostic_item = "sys_mutex_unlock")]
8386
pub unsafe fn unlock(&self) {
8487
if self.futex.swap(UNLOCKED, Release) == CONTENDED {
8588
// We only wake up one thread. When that thread locks the mutex, it

library/std/src/sys/sync/mutex/pthread.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@ impl Mutex {
2828
}
2929

3030
#[inline]
31+
#[cfg_attr(not(test), rustc_diagnostic_item = "sys_mutex_lock")]
3132
pub fn lock(&self) {
3233
// SAFETY: we call `init` above, therefore reentrant locking is safe.
3334
// In `drop` we ensure that the mutex is not destroyed while locked.
3435
unsafe { self.get().lock() }
3536
}
3637

3738
#[inline]
39+
#[cfg_attr(not(test), rustc_diagnostic_item = "sys_mutex_unlock")]
3840
pub unsafe fn unlock(&self) {
3941
// SAFETY: the mutex can only be locked if it is already initialized
4042
// and we observed this initialization since we observed the locking.
4143
unsafe { self.pal.get_unchecked().unlock() }
4244
}
4345

4446
#[inline]
47+
#[cfg_attr(not(test), rustc_diagnostic_item = "sys_mutex_try_lock")]
4548
pub fn try_lock(&self) -> bool {
4649
// SAFETY: we call `init` above, therefore reentrant locking is safe.
4750
// In `drop` we ensure that the mutex is not destroyed while locked.

0 commit comments

Comments
 (0)