From eeb811730362868458410ed96673ee75c2d79220 Mon Sep 17 00:00:00 2001 From: Aron Rosenberg Date: Fri, 6 May 2011 00:10:37 -0400 Subject: Fix semaphore emulation on Windows The existing emulation of posix semaphores on Windows uses SetEvent() and WaitForSingleObject(), which implements a binary semaphore, not a counting semaphore as implemented by posix. This causes deadlock when used with the expected posix semantics. Instead, this patch uses the CreateSemaphore() and ReleaseSemaphore() calls (introduced in Windows 2000) which have the expected behavior. This patch also reverts commit eb16f00, which split a semaphore that was being used with counting semantics into two binary semaphores. That commit is unnecessary with corrected emulation. Change-Id: If400771536a27af4b0c3a31aa4c4e9ced89ce6a0 --- vp8/common/threading.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'vp8/common') diff --git a/vp8/common/threading.h b/vp8/common/threading.h index b7542b306..5927cb165 100644 --- a/vp8/common/threading.h +++ b/vp8/common/threading.h @@ -59,9 +59,9 @@ #ifdef _WIN32 #define sem_t HANDLE #define pause(voidpara) __asm PAUSE -#define sem_init(sem, sem_attr1, sem_init_value) (int)((*sem = CreateEvent(NULL,FALSE,FALSE,NULL))==NULL) +#define sem_init(sem, sem_attr1, sem_init_value) (int)((*sem = CreateSemaphore(NULL,0,32768,NULL))==NULL) #define sem_wait(sem) (int)(WAIT_OBJECT_0 != WaitForSingleObject(*sem,INFINITE)) -#define sem_post(sem) SetEvent(*sem) +#define sem_post(sem) ReleaseSemaphore(*sem,1,NULL) #define sem_destroy(sem) if(*sem)((int)(CloseHandle(*sem))==TRUE) #define thread_sleep(nms) Sleep(nms) -- cgit v1.2.3