Skip to content

Commit 4ad3529

Browse files
fix condvar after merge
1 parent b88cea0 commit 4ad3529

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

libc/src/__support/threads/CndVar.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_CNDVAR_H
1111

1212
#include "src/__support/threads/linux/futex_utils.h" // Futex
13+
#include "src/__support/threads/linux/raw_mutex.h" // RawMutex
1314
#include "src/__support/threads/mutex.h" // Mutex
1415

1516
#include <stdint.h> // uint32_t
@@ -29,12 +30,12 @@ struct CndVar {
2930

3031
CndWaiter *waitq_front;
3132
CndWaiter *waitq_back;
32-
Mutex qmtx;
33+
internal::RawMutex qmtx;
3334

3435
static int init(CndVar *cv) {
3536
cv->waitq_front = cv->waitq_back = nullptr;
36-
auto err = Mutex::init(&cv->qmtx, false, false, false);
37-
return err == MutexError::NONE ? 0 : -1;
37+
internal::RawMutex::init(&cv->qmtx);
38+
return 0;
3839
}
3940

4041
static void destroy(CndVar *cv) {

libc/src/__support/threads/linux/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,6 @@ add_object_library(
9898
libc.src.__support.OSUtil.osutil
9999
libc.src.__support.threads.linux.futex_word_type
100100
libc.src.__support.threads.mutex
101+
libc.src.__support.threads.linux.raw_mutex
102+
libc.src.__support.CPP.mutex
101103
)

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/__support/threads/CndVar.h"
10+
#include "raw_mutex.h"
11+
#include "src/__support/CPP/mutex.h"
1012
#include "src/__support/OSUtil/syscall.h" // syscall_impl
1113
#include "src/__support/threads/linux/futex_word.h" // FutexWordType
1214
#include "src/__support/threads/mutex.h" // Mutex, MutexLock
@@ -27,7 +29,7 @@ int CndVar::wait(Mutex *m) {
2729

2830
CndWaiter waiter;
2931
{
30-
MutexLock ml(&qmtx);
32+
cpp::lock_guard ml(qmtx);
3133
CndWaiter *old_back = nullptr;
3234
if (waitq_front == nullptr) {
3335
waitq_front = waitq_back = &waiter;
@@ -73,17 +75,17 @@ void CndVar::notify_one() {
7375
if (waitq_front == nullptr)
7476
waitq_back = nullptr;
7577

76-
qmtx.futex_word = FutexWordType(Mutex::LockState::Free);
78+
qmtx.futex = internal::RawMutex::UNLOCKED;
7779

7880
// this is a special WAKE_OP, so we use syscall directly
7981
LIBC_NAMESPACE::syscall_impl<long>(
80-
FUTEX_SYSCALL_ID, &qmtx.futex_word.val, FUTEX_WAKE_OP, 1, 1,
82+
FUTEX_SYSCALL_ID, &qmtx.futex.val, FUTEX_WAKE_OP, 1, 1,
8183
&first->futex_word.val,
8284
FUTEX_OP(FUTEX_OP_SET, WS_Signalled, FUTEX_OP_CMP_EQ, WS_Waiting));
8385
}
8486

8587
void CndVar::broadcast() {
86-
MutexLock ml(&qmtx);
88+
cpp::lock_guard ml(qmtx);
8789
uint32_t dummy_futex_word;
8890
CndWaiter *waiter = waitq_front;
8991
waitq_front = waitq_back = nullptr;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endif
2525

2626
namespace LIBC_NAMESPACE {
27+
struct CndVar;
2728
namespace internal {
2829
// Lock is a simple timable lock for internal usage.
2930
// This is separated from Mutex because this one does not need to consider
@@ -112,6 +113,7 @@ class RawMutex {
112113
// Detect invalid unlock operation.
113114
return prev != UNLOCKED;
114115
}
116+
friend struct ::LIBC_NAMESPACE::CndVar;
115117
};
116118
} // namespace internal
117119
} // namespace LIBC_NAMESPACE

0 commit comments

Comments
 (0)