Skip to content

Commit

Permalink
Alias MutexAutoLock to the simpler std::lock_guard
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Oct 10, 2024
1 parent 0adb43b commit bc3a5fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/threading/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DEALINGS IN THE SOFTWARE.

void Event::wait()
{
MutexAutoLock lock(mutex);
std::unique_lock lock(mutex);
while (!notified) {
cv.wait(lock);
}
Expand All @@ -38,7 +38,9 @@ void Event::wait()

void Event::signal()
{
MutexAutoLock lock(mutex);
notified = true;
{
std::lock_guard lock(mutex);
notified = true;
}
cv.notify_one();
}
7 changes: 5 additions & 2 deletions src/threading/mutex_auto_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ DEALINGS IN THE SOFTWARE.
#pragma once

#include <mutex>
using MutexAutoLock = std::unique_lock<std::mutex>;
using RecursiveMutexAutoLock = std::unique_lock<std::recursive_mutex>;

/// @deprecated use std::lock_guard directly
using MutexAutoLock = std::lock_guard<std::mutex>;
/// @deprecated use std::lock_guard directly
using RecursiveMutexAutoLock = std::lock_guard<std::recursive_mutex>;
4 changes: 2 additions & 2 deletions src/threading/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool Thread::start()

// The mutex may already be locked if the thread is being restarted
// FIXME: what if this fails, or if already locked by same thread?
MutexAutoLock sf_lock(m_start_finished_mutex, std::try_to_lock);
std::unique_lock sf_lock(m_start_finished_mutex, std::try_to_lock);

try {
m_thread_obj = new std::thread(threadProc, this);
Expand Down Expand Up @@ -189,7 +189,7 @@ void Thread::threadProc(Thread *thr)

// Wait for the thread that started this one to finish initializing the
// thread handle so that getThreadId/getThreadHandle will work.
MutexAutoLock sf_lock(thr->m_start_finished_mutex);
std::unique_lock sf_lock(thr->m_start_finished_mutex);

thr->m_retval = thr->run();

Expand Down

0 comments on commit bc3a5fc

Please sign in to comment.