Skip to content

Commit

Permalink
fix pthread condvar timeouts for android
Browse files Browse the repository at this point in the history
  • Loading branch information
lunixbochs committed Mar 5, 2018
1 parent b5a238c commit 8e84fc4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/condition_variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ class condition_variable_t

#include <pthread.h>

#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
#define ANDROID_LEGACY
extern "C" int pthread_cond_timedwait_monotonic_np (pthread_cond_t *,
pthread_mutex_t *,
const struct timespec *);
#endif

namespace zmq
{
class condition_variable_t
Expand All @@ -183,7 +190,7 @@ class condition_variable_t
{
pthread_condattr_t attr;
pthread_condattr_init (&attr);
#ifndef ZMQ_HAVE_OSX
#if !defined(ZMQ_HAVE_OSX) && !defined(ANDROID_LEGACY)
pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
#endif
int rc = pthread_cond_init (&cond, &attr);
Expand Down Expand Up @@ -220,6 +227,9 @@ class condition_variable_t
#ifdef ZMQ_HAVE_OSX
rc = pthread_cond_timedwait_relative_np (
&cond, mutex_->get_mutex (), &timeout);
#elif defined(ANDROID_LEGACY)
rc = pthread_cond_timedwait_monotonic_np (
&cond, mutex_->get_mutex (), &timeout);
#else
rc = pthread_cond_timedwait (&cond, mutex_->get_mutex (), &timeout);
#endif
Expand Down

0 comments on commit 8e84fc4

Please sign in to comment.