Add mechanism to reset/lock semaphores
This commit is contained in:
parent
629e6cbefb
commit
9c0ba3b3d5
@ -55,10 +55,12 @@ class LIBPBD_API Semaphore {
|
||||
|
||||
int signal ();
|
||||
int wait ();
|
||||
int reset ();
|
||||
|
||||
#else
|
||||
int signal () { return sem_post (ptr_to_sem()); }
|
||||
int wait () { return sem_wait (ptr_to_sem()); }
|
||||
int reset () { int rv = 0 ; while (sem_trywait (ptr_to_sem()) == 0) ++rv; return rv; }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -74,4 +74,16 @@ Semaphore::wait ()
|
||||
return (result == WAIT_OBJECT_0);
|
||||
}
|
||||
|
||||
int
|
||||
Semaphore::reset ()
|
||||
{
|
||||
int rv = -1;
|
||||
DWORD result;
|
||||
do {
|
||||
++rv;
|
||||
result = WaitForSingleObject(_sem, 0);
|
||||
} while (result == WAIT_OBJECT_0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user