From: Aron Rosenberg Date: Fri, 6 May 2011 04:10:37 +0000 (-0400) Subject: Fix semaphore emulation on Windows X-Git-Tag: v0.9.7~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eeb811730362868458410ed96673ee75c2d79220;p=libvpx 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 --- 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) diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c index c92a366e8..c00494dcf 100644 --- a/vp8/encoder/ethreading.c +++ b/vp8/encoder/ethreading.c @@ -514,7 +514,6 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi) LPFTHREAD_DATA * lpfthd = &cpi->lpf_thread_data; sem_init(&cpi->h_event_start_lpf, 0, 0); - sem_init(&cpi->h_event_end_picklpf, 0, 0); sem_init(&cpi->h_event_end_lpf, 0, 0); lpfthd->ptr1 = (void *)cpi; @@ -548,7 +547,6 @@ void vp8cx_remove_encoder_threads(VP8_COMP *cpi) sem_destroy(&cpi->h_event_end_encoding); sem_destroy(&cpi->h_event_end_lpf); - sem_destroy(&cpi->h_event_end_picklpf); sem_destroy(&cpi->h_event_start_lpf); //free thread related resources diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 78f86557d..1738e5699 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -3140,7 +3140,7 @@ void loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) #if CONFIG_MULTITHREAD if (cpi->b_multi_threaded) - sem_post(&cpi->h_event_end_picklpf); /* signal that we have set filter_level */ + sem_post(&cpi->h_event_end_lpf); /* signal that we have set filter_level */ #endif if (cm->filter_level > 0) @@ -4135,7 +4135,7 @@ static void encode_frame_to_data_rate #if CONFIG_MULTITHREAD /* wait that filter_level is picked so that we can continue with stream packing */ if (cpi->b_multi_threaded) - sem_wait(&cpi->h_event_end_picklpf); + sem_wait(&cpi->h_event_end_lpf); #endif // build the bitstream diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index c2fcff88c..e2e6b367c 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -590,7 +590,6 @@ typedef struct sem_t *h_event_start_encoding; sem_t h_event_end_encoding; sem_t h_event_start_lpf; - sem_t h_event_end_picklpf; sem_t h_event_end_lpf; #endif