From 42330c05b6c8014249794214fd99be9b50ccdc3a Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 12 Feb 2016 19:10:01 +0100 Subject: [PATCH] In Windows use the safe signaling This mostly to detect possible problems in the Windows pthread implementation --- cmdline/io.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmdline/io.c b/cmdline/io.c index 72aa68ef..07dfe1e6 100644 --- a/cmdline/io.c +++ b/cmdline/io.c @@ -44,9 +44,20 @@ * Calling pthread_cond_signal without locking mutex * http://stackoverflow.com/questions/4544234/calling-pthread-cond-signal-without-locking-mutex/4544494#4544494 */ + +/* with checkers use the safe signaling */ +#ifdef CHECKER +#define USE_SAFE_SIGNAL 1 +#endif + +/* in Windows also use the safe signaling */ +#ifdef _WIN32 +#define USE_SAFE_SIGNAL 1 +#endif + static void pthread_cond_signal_and_unlock(pthread_cond_t* cond, pthread_mutex_t* mutex) { -#ifndef CHECKER +#ifndef USE_SAFE_SIGNAL /* without the thread checker unlock before signaling, */ /* this reduces the number of context switches */ pthread_mutex_unlock(mutex); @@ -54,7 +65,7 @@ static void pthread_cond_signal_and_unlock(pthread_cond_t* cond, pthread_mutex_t pthread_cond_signal(cond); -#ifdef CHECKER +#ifdef USE_SAFE_SIGNAL /* with the thread checker unlock after signaling */ /* to make explicit the condition and mutex relation */ pthread_mutex_unlock(mutex); @@ -63,7 +74,7 @@ static void pthread_cond_signal_and_unlock(pthread_cond_t* cond, pthread_mutex_t static void pthread_cond_broadcast_and_unlock(pthread_cond_t* cond, pthread_mutex_t* mutex) { -#ifndef CHECKER +#ifndef USE_SAFE_SIGNAL /* without the thread checker unlock before signaling, */ /* this reduces the number of context switches */ pthread_mutex_unlock(mutex); @@ -71,7 +82,7 @@ static void pthread_cond_broadcast_and_unlock(pthread_cond_t* cond, pthread_mute pthread_cond_broadcast(cond); -#ifdef CHECKER +#ifdef USE_SAFE_SIGNAL /* with the thread checker unlock after signaling */ /* to make explicit the condition and mutex relation */ pthread_mutex_unlock(mutex);