Skip to content

Commit de44a55

Browse files
author
Yifan Zhu
committed
address CRs
1 parent b9abf31 commit de44a55

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

libc/src/__support/threads/linux/CndVar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ void CndVar::notify_one() {
7575
if (waitq_front == nullptr)
7676
waitq_back = nullptr;
7777

78-
qmtx.futex = RawMutex::UNLOCKED;
78+
qmtx.reset();
7979

8080
// this is a special WAKE_OP, so we use syscall directly
8181
LIBC_NAMESPACE::syscall_impl<long>(
82-
FUTEX_SYSCALL_ID, &qmtx.futex.val, FUTEX_WAKE_OP, 1, 1,
82+
FUTEX_SYSCALL_ID, &qmtx.get_raw_futex(), FUTEX_WAKE_OP, 1, 1,
8383
&first->futex_word.val,
8484
FUTEX_OP(FUTEX_OP_SET, WS_Signalled, FUTEX_OP_CMP_EQ, WS_Waiting));
8585
}

libc/src/__support/threads/linux/raw_mutex.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ class RawMutex {
4545
LIBC_INLINE_VAR static constexpr FutexWordType IN_CONTENTION = 0b10;
4646

4747
private:
48-
LIBC_INLINE FutexWordType spin(int spin_count) {
48+
LIBC_INLINE FutexWordType spin(unsigned spin_count) {
4949
FutexWordType result;
5050
for (;;) {
5151
result = futex.load(cpp::MemoryOrder::RELAXED);
5252
// spin until one of the following conditions is met:
5353
// - the mutex is unlocked
5454
// - the mutex is in contention
5555
// - the spin count reaches 0
56-
if (result != LOCKED || spin_count == 0)
56+
if (result != LOCKED || spin_count == 0u)
5757
return result;
5858
// Pause the pipeline to avoid extraneous memory operations due to
5959
// speculation.
@@ -65,7 +65,7 @@ class RawMutex {
6565
// Return true if the lock is acquired. Return false if timeout happens before
6666
// the lock is acquired.
6767
LIBC_INLINE bool lock_slow(cpp::optional<Futex::Timeout> timeout,
68-
bool is_pshared, int spin_count) {
68+
bool is_pshared, unsigned spin_count) {
6969
FutexWordType state = spin(spin_count);
7070
// Before go into contention state, try to grab the lock.
7171
if (state == UNLOCKED &&
@@ -105,7 +105,7 @@ class RawMutex {
105105
LIBC_INLINE bool
106106
lock(cpp::optional<Futex::Timeout> timeout = cpp::nullopt,
107107
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) {
109109
// Timeout will not be checked if immediate lock is possible.
110110
if (LIBC_LIKELY(try_lock()))
111111
return true;
@@ -122,7 +122,8 @@ class RawMutex {
122122
LIBC_INLINE void static destroy([[maybe_unused]] RawMutex *lock) {
123123
LIBC_ASSERT(lock->futex == UNLOCKED && "Mutex destroyed while used.");
124124
}
125-
friend class CndVar;
125+
LIBC_INLINE Futex &get_raw_futex() { return futex; }
126+
LIBC_INLINE void reset() { futex = UNLOCKED; }
126127
};
127128
} // namespace LIBC_NAMESPACE
128129

0 commit comments

Comments
 (0)