Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Lock //thanks to 'doublep' from StackOverflow for this RAII solution, edited it
- {
- MUTEX mutex;
- bool locked;
- Lock (MUTEX mutex)
- : mutex (mutex),
- locked (false)
- {
- }
- ~Lock ()
- {
- release ();
- }
- bool acquire (int timeout = -1)
- {
- if (!locked && TryEnterCriticalSection(&mutex) != 0)
- {
- locked = true;
- }
- return locked;
- }
- int release ()
- {
- if (locked)
- {
- LeaveCriticalSection(&mutex); locked = false;
- return true;
- }
- return false;
- }
- };
- MUTEX mutex_q;
- MUTEX mutex_p;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement