Skip to content

[libc] clean up MutexLock #93619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading