Clear stale 'post's on the event semphaphore

This commit is contained in:
Chris Robinson
2018-02-10 21:42:45 -08:00
parent 1e93122470
commit b11e31fbfd
3 changed files with 22 additions and 0 deletions
+5
View File
@@ -13,6 +13,11 @@ static int EventThread(void *arg)
{
ALCcontext *context = arg;
/* Clear all pending posts on the semaphore. */
while(alsem_trywait(&context->EventSem) == althrd_success)
{
}
while(1)
{
AsyncEvent evt;
+16
View File
@@ -354,6 +354,14 @@ int alsem_wait(alsem_t *sem)
return althrd_error;
}
int alsem_trywait(alsem_t *sem)
{
DWORD ret = WaitForSingleObject(*sem, 0);
if(ret == WAIT_OBJECT_0) return althrd_success;
if(ret == WAIT_TIMEOUT) return althrd_busy;
return althrd_error;
}
/* An associative map of uint:void* pairs. The key is the TLS index (given by
* TlsAlloc), and the value is the altss_dtor_t callback. When a thread exits,
@@ -664,6 +672,14 @@ int alsem_wait(alsem_t *sem)
return althrd_error;
}
int alsem_trywait(alsem_t *sem)
{
if(sem_trywait(sem) == 0) return althrd_success;
if(errno == EWOULDBLOCK) return althrd_busy;
if(errno == EINTR) return -2;
return althrd_error;
}
int altss_create(altss_t *tss_id, altss_dtor_t callback)
{
+1
View File
@@ -237,6 +237,7 @@ int alsem_init(alsem_t *sem, unsigned int initial);
void alsem_destroy(alsem_t *sem);
int alsem_post(alsem_t *sem);
int alsem_wait(alsem_t *sem);
int alsem_trywait(alsem_t *sem);
int altss_create(altss_t *tss_id, altss_dtor_t callback);
void altss_delete(altss_t tss_id);