diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c index d3445820..168c40c6 100644 --- a/src/MQTTAsync.c +++ b/src/MQTTAsync.c @@ -129,7 +129,7 @@ void MQTTAsync_init_rand(void) mutex_type mqttasync_mutex = NULL; mutex_type socket_mutex = NULL; mutex_type mqttcommand_mutex = NULL; -sem_type send_evt = NULL; +evt_type send_evt = NULL; #if !defined(NO_HEAP_TRACKING) extern mutex_type stack_mutex; extern mutex_type heap_mutex; diff --git a/src/Thread.c b/src/Thread.c index d515177e..56f97a83 100644 --- a/src/Thread.c +++ b/src/Thread.c @@ -262,16 +262,6 @@ evt_type Thread_create_evt(int *rc) *rc = -1; pthread_condattr_init(&attr); -#if 0 - /* in theory, a monotonic clock should be able to be used. However on at least - * one system reported, even though setclock() reported success, it didn't work. - */ - if ((rc = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) == 0) - use_clock_monotonic = 1; - else - Log(LOG_ERROR, -1, "Error %d calling pthread_condattr_setclock(CLOCK_MONOTONIC)", rc); -#endif - evt = malloc(sizeof(evt_type_struct)); if (evt) { @@ -295,7 +285,8 @@ int Thread_signal_evt(evt_type evt) FUNC_ENTRY; pthread_mutex_lock(&evt->mutex); evt->val = 1; - rc = pthread_cond_signal(&evt->cond); + // TODO: Determine if this could be more efficient with pthread_cond_signal() + rc = pthread_cond_broadcast(&evt->cond); pthread_mutex_unlock(&evt->mutex); FUNC_EXIT_RC(rc); @@ -349,19 +340,19 @@ int Thread_destroy_evt(evt_type evt) * @param rc return code: 0 for success, negative otherwise * @return the new condition variable */ -sem_type Thread_create_evt(int *rc) +evt_type Thread_create_evt(int *rc) { FUNC_ENTRY; - sem_type sem = CreateEvent( + evt_type evt = CreateEvent( NULL, /* default security attributes */ FALSE, /* manual-reset event? */ FALSE, /* initial state is nonsignaled */ NULL /* object name */ ); if (rc) - *rc = (sem == NULL) ? GetLastError() : 0; + *rc = (evt == NULL) ? GetLastError() : 0; FUNC_EXIT_RC(*rc); - return sem; + return evt; } /** diff --git a/src/Thread.h b/src/Thread.h index e682ab7b..28ff72df 100644 --- a/src/Thread.h +++ b/src/Thread.h @@ -41,9 +41,7 @@ #define thread_id_type DWORD #define thread_return_type DWORD #define thread_fn LPTHREAD_START_ROUTINE - #define cond_type HANDLE #define evt_type HANDLE - #define sem_type HANDLE #undef ETIMEDOUT #define ETIMEDOUT WSAETIMEDOUT #else @@ -56,13 +54,6 @@ typedef thread_return_type (*thread_fn)(void*); typedef struct { pthread_cond_t cond; pthread_mutex_t mutex; int val; } evt_type_struct; typedef evt_type_struct *evt_type; - #if defined(OSX) - #include - typedef dispatch_semaphore_t sem_type; - #else - #include - typedef sem_t *sem_type; - #endif #endif LIBMQTT_API void Paho_thread_start(thread_fn, void*);