Skip to content

Commit

Permalink
[libc] clean up MutexLock (#93619)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed May 28, 2024
1 parent f7c8a03 commit 0694552
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
1 change: 1 addition & 0 deletions libc/src/__support/threads/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ add_object_library(
libc.src.__support.OSUtil.osutil
libc.src.__support.threads.linux.futex_word_type
libc.src.__support.threads.mutex
libc.src.__support.CPP.mutex
)
7 changes: 4 additions & 3 deletions libc/src/__support/threads/linux/CndVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
//===----------------------------------------------------------------------===//

#include "src/__support/threads/CndVar.h"
#include "src/__support/CPP/mutex.h"
#include "src/__support/OSUtil/syscall.h" // syscall_impl
#include "src/__support/threads/linux/futex_word.h" // FutexWordType
#include "src/__support/threads/mutex.h" // Mutex, MutexLock
#include "src/__support/threads/mutex.h" // Mutex

#include <sys/syscall.h> // For syscall numbers.

Expand All @@ -27,7 +28,7 @@ int CndVar::wait(Mutex *m) {

CndWaiter waiter;
{
MutexLock ml(&qmtx);
cpp::lock_guard ml(qmtx);
CndWaiter *old_back = nullptr;
if (waitq_front == nullptr) {
waitq_front = waitq_back = &waiter;
Expand Down Expand Up @@ -83,7 +84,7 @@ void CndVar::notify_one() {
}

void CndVar::broadcast() {
MutexLock ml(&qmtx);
cpp::lock_guard ml(qmtx);
uint32_t dummy_futex_word;
CndWaiter *waiter = waitq_front;
waitq_front = waitq_back = nullptr;
Expand Down
14 changes: 0 additions & 14 deletions libc/src/__support/threads/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,4 @@
#include "src/__support/threads/gpu/mutex.h"
#endif // __linux__

namespace LIBC_NAMESPACE {

// An RAII class for easy locking and unlocking of mutexes.
class MutexLock {
Mutex *mutex;

public:
explicit MutexLock(Mutex *m) : mutex(m) { mutex->lock(); }

~MutexLock() { mutex->unlock(); }
};

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC___SUPPORT_THREADS_MUTEX_H

0 comments on commit 0694552

Please sign in to comment.