@@ -45,15 +45,15 @@ class RawMutex {
45
45
LIBC_INLINE_VAR static constexpr FutexWordType IN_CONTENTION = 0b10 ;
46
46
47
47
private:
48
- LIBC_INLINE FutexWordType spin (int spin_count) {
48
+ LIBC_INLINE FutexWordType spin (unsigned spin_count) {
49
49
FutexWordType result;
50
50
for (;;) {
51
51
result = futex.load (cpp::MemoryOrder::RELAXED);
52
52
// spin until one of the following conditions is met:
53
53
// - the mutex is unlocked
54
54
// - the mutex is in contention
55
55
// - the spin count reaches 0
56
- if (result != LOCKED || spin_count == 0 )
56
+ if (result != LOCKED || spin_count == 0u )
57
57
return result;
58
58
// Pause the pipeline to avoid extraneous memory operations due to
59
59
// speculation.
@@ -65,7 +65,7 @@ class RawMutex {
65
65
// Return true if the lock is acquired. Return false if timeout happens before
66
66
// the lock is acquired.
67
67
LIBC_INLINE bool lock_slow (cpp::optional<Futex::Timeout> timeout,
68
- bool is_pshared, int spin_count) {
68
+ bool is_pshared, unsigned spin_count) {
69
69
FutexWordType state = spin (spin_count);
70
70
// Before go into contention state, try to grab the lock.
71
71
if (state == UNLOCKED &&
@@ -105,7 +105,7 @@ class RawMutex {
105
105
LIBC_INLINE bool
106
106
lock (cpp::optional<Futex::Timeout> timeout = cpp::nullopt,
107
107
bool is_shared = false ,
108
- int spin_count = LIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT) {
108
+ unsigned spin_count = LIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT) {
109
109
// Timeout will not be checked if immediate lock is possible.
110
110
if (LIBC_LIKELY (try_lock ()))
111
111
return true ;
@@ -122,7 +122,8 @@ class RawMutex {
122
122
LIBC_INLINE void static destroy ([[maybe_unused]] RawMutex *lock) {
123
123
LIBC_ASSERT (lock->futex == UNLOCKED && " Mutex destroyed while used." );
124
124
}
125
- friend class CndVar ;
125
+ LIBC_INLINE Futex &get_raw_futex () { return futex; }
126
+ LIBC_INLINE void reset () { futex = UNLOCKED; }
126
127
};
127
128
} // namespace LIBC_NAMESPACE
128
129
0 commit comments