libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
Mutex.h
1/****************************************************************************
2 * Platform Abstraction Layer
3 * Daryl Borth 2026
4 * Mutex.h
5 *
6 * Generic - Everything platform-specific lives behind platform->getThread().
7 ***************************************************************************/
8#pragma once
9
13class Mutex
14{
15 public:
16 Mutex();
17 ~Mutex();
18
19 Mutex(const Mutex &) = delete;
20 Mutex & operator=(const Mutex &) = delete;
21
23 void lock();
25 void unlock();
26
27 protected:
28 friend class Cond;
29 void * handle = nullptr;
30};
31
37{
38 public:
40 explicit MutexLock(Mutex & m) : mutex(m) { mutex.lock(); }
41 ~MutexLock() { mutex.unlock(); }
42
43 MutexLock(const MutexLock &) = delete;
44 MutexLock & operator=(const MutexLock &) = delete;
45
46 protected:
48};
RAII lock guard - locks on construction, unlocks on destruction.
Definition Mutex.h:37
Mutex & mutex
The mutex held by this guard.
Definition Mutex.h:47
MutexLock(Mutex &m)
Locks m until this guard goes out of scope.
Definition Mutex.h:40
A simple mutual-exclusion lock.
Definition Mutex.h:14
void unlock()
Releases the mutex. Must be called by the thread that locked it.
Definition Mutex.cpp:28
void * handle
Backend-assigned mutex handle.
Definition Mutex.h:29
friend class Cond
Cond::wait() needs the raw handle to pass to ThreadDriver::waitCond()
Definition Mutex.h:28
void lock()
Blocks until the mutex is acquired. Not recursive: locking twice from one thread deadlocks.
Definition Mutex.cpp:22