aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-10 22:53:03 -0800
committerChris Robinson <[email protected]>2018-11-10 22:53:03 -0800
commit5bc2918e16c0ec5b43837ed0a12bfa1f7187103a (patch)
treead2ecc08749c2d6455f826e5c5e4988e41d1b52e
parentf3ce7bc7dcf20275d93974755c42486d812d771f (diff)
Remove the unused condition variable APIs
-rw-r--r--common/threads.c152
-rw-r--r--common/threads.h12
2 files changed, 0 insertions, 164 deletions
diff --git a/common/threads.c b/common/threads.c
index de9fc452..16604267 100644
--- a/common/threads.c
+++ b/common/threads.c
@@ -192,125 +192,6 @@ void almtx_destroy(almtx_t *mtx)
DeleteCriticalSection(mtx);
}
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
-int alcnd_init(alcnd_t *cond)
-{
- InitializeConditionVariable(cond);
- return althrd_success;
-}
-
-int alcnd_signal(alcnd_t *cond)
-{
- WakeConditionVariable(cond);
- return althrd_success;
-}
-
-int alcnd_broadcast(alcnd_t *cond)
-{
- WakeAllConditionVariable(cond);
- return althrd_success;
-}
-
-int alcnd_wait(alcnd_t *cond, almtx_t *mtx)
-{
- if(SleepConditionVariableCS(cond, mtx, INFINITE) != 0)
- return althrd_success;
- return althrd_error;
-}
-
-void alcnd_destroy(alcnd_t* UNUSED(cond))
-{
- /* Nothing to delete? */
-}
-
-#else
-
-/* WARNING: This is a rather poor implementation of condition variables, with
- * known problems. However, it's simple, efficient, and good enough for now to
- * not require Vista. Based on "Strategies for Implementing POSIX Condition
- * Variables" by Douglas C. Schmidt and Irfan Pyarali:
- * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
- */
-/* A better solution may be using Wine's implementation. It requires internals
- * (NtCreateKeyedEvent, NtReleaseKeyedEvent, and NtWaitForKeyedEvent) from
- * ntdll, and implemention of exchange and compare-exchange for RefCounts.
- */
-
-typedef struct {
- RefCount wait_count;
-
- HANDLE events[2];
-} _int_alcnd_t;
-enum {
- SIGNAL = 0,
- BROADCAST = 1
-};
-
-int alcnd_init(alcnd_t *cond)
-{
- _int_alcnd_t *icond = calloc(1, sizeof(*icond));
- if(!icond) return althrd_nomem;
-
- InitRef(&icond->wait_count, 0);
-
- icond->events[SIGNAL] = CreateEventW(NULL, FALSE, FALSE, NULL);
- icond->events[BROADCAST] = CreateEventW(NULL, TRUE, FALSE, NULL);
- if(!icond->events[SIGNAL] || !icond->events[BROADCAST])
- {
- if(icond->events[SIGNAL])
- CloseHandle(icond->events[SIGNAL]);
- if(icond->events[BROADCAST])
- CloseHandle(icond->events[BROADCAST]);
- free(icond);
- return althrd_error;
- }
-
- cond->Ptr = icond;
- return althrd_success;
-}
-
-int alcnd_signal(alcnd_t *cond)
-{
- _int_alcnd_t *icond = cond->Ptr;
- if(ReadRef(&icond->wait_count) > 0)
- SetEvent(icond->events[SIGNAL]);
- return althrd_success;
-}
-
-int alcnd_broadcast(alcnd_t *cond)
-{
- _int_alcnd_t *icond = cond->Ptr;
- if(ReadRef(&icond->wait_count) > 0)
- SetEvent(icond->events[BROADCAST]);
- return althrd_success;
-}
-
-int alcnd_wait(alcnd_t *cond, almtx_t *mtx)
-{
- _int_alcnd_t *icond = cond->Ptr;
- int res;
-
- IncrementRef(&icond->wait_count);
- LeaveCriticalSection(mtx);
-
- res = WaitForMultipleObjects(2, icond->events, FALSE, INFINITE);
-
- if(DecrementRef(&icond->wait_count) == 0 && res == WAIT_OBJECT_0+BROADCAST)
- ResetEvent(icond->events[BROADCAST]);
- EnterCriticalSection(mtx);
-
- return althrd_success;
-}
-
-void alcnd_destroy(alcnd_t *cond)
-{
- _int_alcnd_t *icond = cond->Ptr;
- CloseHandle(icond->events[SIGNAL]);
- CloseHandle(icond->events[BROADCAST]);
- free(icond);
-}
-#endif /* defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 */
-
int alsem_init(alsem_t *sem, unsigned int initial)
{
@@ -560,39 +441,6 @@ void almtx_destroy(almtx_t *mtx)
pthread_mutex_destroy(mtx);
}
-int alcnd_init(alcnd_t *cond)
-{
- if(pthread_cond_init(cond, NULL) == 0)
- return althrd_success;
- return althrd_error;
-}
-
-int alcnd_signal(alcnd_t *cond)
-{
- if(pthread_cond_signal(cond) == 0)
- return althrd_success;
- return althrd_error;
-}
-
-int alcnd_broadcast(alcnd_t *cond)
-{
- if(pthread_cond_broadcast(cond) == 0)
- return althrd_success;
- return althrd_error;
-}
-
-int alcnd_wait(alcnd_t *cond, almtx_t *mtx)
-{
- if(pthread_cond_wait(cond, mtx) == 0)
- return althrd_success;
- return althrd_error;
-}
-
-void alcnd_destroy(alcnd_t *cond)
-{
- pthread_cond_destroy(cond);
-}
-
#ifdef __APPLE__
diff --git a/common/threads.h b/common/threads.h
index c2168cdf..2cc65557 100644
--- a/common/threads.h
+++ b/common/threads.h
@@ -41,11 +41,6 @@ typedef void (*altss_dtor_t)(void*);
typedef DWORD althrd_t;
typedef CRITICAL_SECTION almtx_t;
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
-typedef CONDITION_VARIABLE alcnd_t;
-#else
-typedef struct { void *Ptr; } alcnd_t;
-#endif
typedef HANDLE alsem_t;
typedef DWORD altss_t;
typedef LONG alonce_flag;
@@ -128,7 +123,6 @@ inline int altss_set(altss_t tss_id, void *val)
typedef pthread_t althrd_t;
typedef pthread_mutex_t almtx_t;
-typedef pthread_cond_t alcnd_t;
#ifdef __APPLE__
typedef dispatch_semaphore_t alsem_t;
#else /* !__APPLE__ */
@@ -220,12 +214,6 @@ void althrd_setname(althrd_t thr, const char *name);
int almtx_init(almtx_t *mtx, int type);
void almtx_destroy(almtx_t *mtx);
-int alcnd_init(alcnd_t *cond);
-int alcnd_signal(alcnd_t *cond);
-int alcnd_broadcast(alcnd_t *cond);
-int alcnd_wait(alcnd_t *cond, almtx_t *mtx);
-void alcnd_destroy(alcnd_t *cond);
-
int alsem_init(alsem_t *sem, unsigned int initial);
void alsem_destroy(alsem_t *sem);
int alsem_post(alsem_t *sem);