diff options
author | Justin Dickow <jjdickow@gmail.com> | 2014-03-19 17:14:08 -0400 |
---|---|---|
committer | Justin Dickow <jjdickow@gmail.com> | 2014-03-19 17:14:08 -0400 |
commit | 30183f4737d2d12a2c3e1aeb3f7f15a108463747 (patch) | |
tree | ff22e99ccf4162b3ddd424bb497e01dd568c3452 | |
parent | bdb1f6a20f24007dc2bc032f8b646f02ec2ebafe (diff) | |
download | smartdevicelink-30183f4737d2d12a2c3e1aeb3f7f15a108463747.tar.gz |
replace clock_getting() with gettimeofday()
Credit to Brendan Shanks
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
-rw-r--r-- | SDL_Core/src/components/Utils/src/conditional_variable_posix.cc | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/SDL_Core/src/components/Utils/src/conditional_variable_posix.cc b/SDL_Core/src/components/Utils/src/conditional_variable_posix.cc index 46b31ee7c..c11b063d0 100644 --- a/SDL_Core/src/components/Utils/src/conditional_variable_posix.cc +++ b/SDL_Core/src/components/Utils/src/conditional_variable_posix.cc @@ -54,7 +54,9 @@ ConditionalVariable::ConditionalVariable() { if (initialized != 0) LOG4CXX_ERROR(g_logger, "Failed to initialize " "conditional variable attributes"); - pthread_condattr_setclock(&attrs, CLOCK_MONOTONIC); +#ifdef __linux__ + pthread_condattr_setclock(&attrs, CLOCK_MONOTONIC); // Default (non linux) will use the CPU clock +#endif initialized = pthread_cond_init(&cond_var_, &attrs); if (initialized != 0) LOG4CXX_ERROR(g_logger, "Failed to initialize " @@ -94,10 +96,28 @@ void ConditionalVariable::Wait(AutoLock& auto_lock) { LOG4CXX_ERROR(g_logger, "Failed to wait for conditional variable"); } +#ifdef OS_LINUX +static void current_time(struct timespec *ts) { + clock_gettime(CLOCK_MONOTONIC, ts); +} +#elif OS_MACOSX +#include <mach/clock.h> +#include <mach/mach.h> +static void current_time(struct timespec *ts) { + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts->tv_sec = mts.tv_sec; + ts->tv_nsec = mts.tv_nsec; +} +#endif + ConditionalVariable::WaitStatus ConditionalVariable::WaitFor( AutoLock& auto_lock, int32_t milliseconds){ struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); + current_time(&now); timespec wait_interval; wait_interval.tv_sec = now.tv_sec + (milliseconds / kMillisecondsPerSecond); |