aboutsummaryrefslogtreecommitdiffstats
path: root/common/threads.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-02-10 21:42:45 -0800
committerChris Robinson <[email protected]>2018-02-11 06:14:18 -0800
commitb11e31fbfd6744a6d938ebb4a0e85c173386322a (patch)
tree67f4ddad035d94dc02716c5929726f9225e4498c /common/threads.c
parent1e93122470445810a77ee549c5945ead44fd5676 (diff)
Clear stale 'post's on the event semphaphore
Diffstat (limited to 'common/threads.c')
-rw-r--r--common/threads.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/threads.c b/common/threads.c
index b95cb548..88052d7e 100644
--- a/common/threads.c
+++ b/common/threads.c
@@ -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)
{