From 894d241fff9b5de10babf204d295e6550bec4223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 7 Jan 2015 17:03:32 +0100 Subject: [PATCH] added OSD_EVENT_WAIT_INFINITE and implemented it properly for all platforms (nw) --- src/osd/modules/sync/osdsync.h | 2 ++ src/osd/modules/sync/sync_ntc.c | 3 +++ src/osd/modules/sync/sync_os2.c | 8 +++++++- src/osd/modules/sync/sync_sdl.c | 2 ++ src/osd/modules/sync/sync_tc.c | 3 +++ src/osd/modules/sync/sync_windows.c | 10 ++++++++-- src/osd/modules/sync/work_osd.c | 3 +-- 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/osd/modules/sync/osdsync.h b/src/osd/modules/sync/osdsync.h index 5d166eb5145..724918d10e6 100644 --- a/src/osd/modules/sync/osdsync.h +++ b/src/osd/modules/sync/osdsync.h @@ -14,6 +14,8 @@ SYNCHRONIZATION INTERFACES - Events ***************************************************************************/ +#define OSD_EVENT_WAIT_INFINITE -1 + /* osd_event is an opaque type which represents a setable/resetable event */ struct osd_event; diff --git a/src/osd/modules/sync/sync_ntc.c b/src/osd/modules/sync/sync_ntc.c index 0ec99b2094a..85f5f42957b 100644 --- a/src/osd/modules/sync/sync_ntc.c +++ b/src/osd/modules/sync/sync_ntc.c @@ -403,6 +403,9 @@ void osd_event_reset(osd_event *event) int osd_event_wait(osd_event *event, osd_ticks_t timeout) { + if (timeout == OSD_EVENT_WAIT_INFINITE) + timeout = osd_ticks_per_second() * (osd_ticks_t)10000; + pthread_mutex_lock(&event->mutex); if (!timeout) { diff --git a/src/osd/modules/sync/sync_os2.c b/src/osd/modules/sync/sync_os2.c index 6ae91d4d408..1aba8082588 100644 --- a/src/osd/modules/sync/sync_os2.c +++ b/src/osd/modules/sync/sync_os2.c @@ -381,11 +381,17 @@ void osd_event_reset(osd_event *event) int osd_event_wait(osd_event *event, osd_ticks_t timeout) { ULONG rc; + ULONG timeout_param; + + if (timeout == OSD_EVENT_WAIT_INFINITE) + timeout_param = SEM_INDEFINITE_WAIT; + else + timeout_param = timeout * 1000 / osd_ticks_per_second(); if(event->autoreset) DosRequestMutexSem(event->hmtx, -1); - rc = DosWaitEventSem(event->hev, timeout * 1000 / osd_ticks_per_second()); + rc = DosWaitEventSem(event->hev, timeout_param); if(event->autoreset) { diff --git a/src/osd/modules/sync/sync_sdl.c b/src/osd/modules/sync/sync_sdl.c index fe1fdafe0bc..66de65e2850 100644 --- a/src/osd/modules/sync/sync_sdl.c +++ b/src/osd/modules/sync/sync_sdl.c @@ -247,6 +247,8 @@ void osd_event_reset(osd_event *event) int osd_event_wait(osd_event *event, osd_ticks_t timeout) { LOG(("osd_event_wait")); + if (timeout == OSD_EVENT_WAIT_INFINITE) + timeout = osd_ticks_per_second() * (osd_ticks_t)10000; SDL_mutexP(event->mutex); if (!timeout) { diff --git a/src/osd/modules/sync/sync_tc.c b/src/osd/modules/sync/sync_tc.c index 3a1e8ec8d17..f5a80adb7ec 100644 --- a/src/osd/modules/sync/sync_tc.c +++ b/src/osd/modules/sync/sync_tc.c @@ -238,6 +238,9 @@ void osd_event_reset(osd_event *event) int osd_event_wait(osd_event *event, osd_ticks_t timeout) { + if (timeout == OSD_EVENT_WAIT_INFINITE) + timeout = osd_ticks_per_second() * (osd_ticks_t)10000; + pthread_mutex_lock(&event->mutex); if (!timeout) { diff --git a/src/osd/modules/sync/sync_windows.c b/src/osd/modules/sync/sync_windows.c index 8326ce41f29..4b5c633d96d 100644 --- a/src/osd/modules/sync/sync_windows.c +++ b/src/osd/modules/sync/sync_windows.c @@ -239,8 +239,14 @@ void osd_event_reset(osd_event *event) int osd_event_wait(osd_event *event, osd_ticks_t timeout) { - int ret = WaitForSingleObject((HANDLE) event, timeout * 1000 / osd_ticks_per_second()); - return ( ret == WAIT_OBJECT_0); + DWORD timeout_param; + if (timeout == OSD_EVENT_WAIT_INFINITE) + timeout_param = INFINITE; + else + timeout_param = timeout * 1000 / osd_ticks_per_second(); + + int ret = WaitForSingleObject((HANDLE) event, timeout_param); + return (ret == WAIT_OBJECT_0); } //============================================================ diff --git a/src/osd/modules/sync/work_osd.c b/src/osd/modules/sync/work_osd.c index 1d69d351621..8a337cb7ff1 100644 --- a/src/osd/modules/sync/work_osd.c +++ b/src/osd/modules/sync/work_osd.c @@ -58,7 +58,6 @@ typedef void *PVOID; #if defined(OSD_WINDOWS) #define SPIN_LOOP_TIME (osd_ticks_per_second() / 50000) #else -#define INFINITE (osd_ticks_per_second() * (osd_ticks_t) 10000) #define SPIN_LOOP_TIME (osd_ticks_per_second() / 10000) #endif @@ -659,7 +658,7 @@ static void *worker_thread_entry(void *param) if (!queue_has_list_items(queue)) { begin_timing(thread->waittime); - osd_event_wait(thread->wakeevent, INFINITE); + osd_event_wait(thread->wakeevent, OSD_EVENT_WAIT_INFINITE); end_timing(thread->waittime); }