mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Alias MutexAutoLock to the simpler std::lock_guard
This commit is contained in:
parent
99b6315c1a
commit
244f4f285a
3 changed files with 12 additions and 7 deletions
|
@ -28,7 +28,7 @@ DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
void Event::wait()
|
void Event::wait()
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(mutex);
|
std::unique_lock lock(mutex);
|
||||||
while (!notified) {
|
while (!notified) {
|
||||||
cv.wait(lock);
|
cv.wait(lock);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,9 @@ void Event::wait()
|
||||||
|
|
||||||
void Event::signal()
|
void Event::signal()
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(mutex);
|
{
|
||||||
|
std::lock_guard lock(mutex);
|
||||||
notified = true;
|
notified = true;
|
||||||
|
}
|
||||||
cv.notify_one();
|
cv.notify_one();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,5 +26,8 @@ DEALINGS IN THE SOFTWARE.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mutex>
|
#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>;
|
||||||
|
|
|
@ -117,7 +117,7 @@ bool Thread::start()
|
||||||
|
|
||||||
// The mutex may already be locked if the thread is being restarted
|
// The mutex may already be locked if the thread is being restarted
|
||||||
// FIXME: what if this fails, or if already locked by same thread?
|
// 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 {
|
try {
|
||||||
m_thread_obj = new std::thread(threadProc, this);
|
m_thread_obj = new std::thread(threadProc, this);
|
||||||
|
@ -189,7 +189,7 @@ void Thread::threadProc(Thread *thr)
|
||||||
|
|
||||||
// Wait for the thread that started this one to finish initializing the
|
// Wait for the thread that started this one to finish initializing the
|
||||||
// thread handle so that getThreadId/getThreadHandle will work.
|
// 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();
|
thr->m_retval = thr->run();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue