diff --git a/src/clock.cpp b/src/clock.cpp index b2960e84..b15bd743 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -60,15 +60,9 @@ int alt_clock_gettime (int clock_id, timespec *ts) { - // The clock_id specified is not supported on this system. - if (clock_id != CLOCK_REALTIME) { - errno = EINVAL; - return -1; - } - clock_serv_t cclock; mach_timespec_t mts; - host_get_clock_service (mach_host_self (), CALENDAR_CLOCK, &cclock); + host_get_clock_service (mach_host_self (), clock_id, &cclock); clock_get_time (cclock, &mts); mach_port_deallocate (mach_task_self (), cclock); ts->tv_sec = mts.tv_sec; @@ -162,8 +156,8 @@ uint64_t zmq::clock_t::now_us () // Use POSIX clock_gettime function to get precise monotonic time. struct timespec tv; -#if defined ZMQ_HAVE_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12 - int rc = alt_clock_gettime (CLOCK_MONOTONIC, &tv); +#if defined ZMQ_HAVE_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12 + int rc = alt_clock_gettime (SYSTEM_CLOCK, &tv); #else int rc = clock_gettime (CLOCK_MONOTONIC, &tv); #endif @@ -250,7 +244,7 @@ uint64_t zmq::clock_t::rdtsc () #else struct timespec ts; #if defined ZMQ_HAVE_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12 - alt_clock_gettime (CLOCK_MONOTONIC, &ts); + alt_clock_gettime (SYSTEM_CLOCK, &ts); #else clock_gettime (CLOCK_MONOTONIC, &ts); #endif diff --git a/src/condition_variable.hpp b/src/condition_variable.hpp index d8c80953..910e4afc 100644 --- a/src/condition_variable.hpp +++ b/src/condition_variable.hpp @@ -81,15 +81,15 @@ namespace zmq #else -#ifdef ZMQ_HAVE_WINDOWS_TARGET_XP -#include -#include -#endif +#ifdef ZMQ_HAVE_WINDOWS_TARGET_XP +#include +#include +#endif namespace zmq { -#ifndef ZMQ_HAVE_WINDOWS_TARGET_XP +#ifndef ZMQ_HAVE_WINDOWS_TARGET_XP class condition_variable_t { public: @@ -133,51 +133,51 @@ namespace zmq void operator = (const condition_variable_t&); }; #else - class condition_variable_t - { - public: - inline condition_variable_t() - { - - } - - inline ~condition_variable_t() - { - - } - - inline int wait(mutex_t* mutex_, int timeout_) - { - std::unique_lock lck(mtx); // lock mtx - mutex_->unlock(); // unlock mutex_ - int res = 0; - if(timeout_ == -1) { - cv.wait(lck); // unlock mtx and wait cv.notify_all(), lock mtx after cv.notify_all() - } else if (cv.wait_for(lck, std::chrono::milliseconds(timeout_)) == std::cv_status::timeout) { - // time expired - errno = EAGAIN; - res = -1; - } - lck.unlock(); // unlock mtx - mutex_->lock(); // lock mutex_ - return res; - } - - inline void broadcast() - { - std::unique_lock lck(mtx); // lock mtx - cv.notify_all(); - } - - private: - - std::condition_variable cv; - std::mutex mtx; - - // Disable copy construction and assignment. - condition_variable_t(const condition_variable_t&); - void operator = (const condition_variable_t&); - }; + class condition_variable_t + { + public: + inline condition_variable_t() + { + + } + + inline ~condition_variable_t() + { + + } + + inline int wait(mutex_t* mutex_, int timeout_) + { + std::unique_lock lck(mtx); // lock mtx + mutex_->unlock(); // unlock mutex_ + int res = 0; + if(timeout_ == -1) { + cv.wait(lck); // unlock mtx and wait cv.notify_all(), lock mtx after cv.notify_all() + } else if (cv.wait_for(lck, std::chrono::milliseconds(timeout_)) == std::cv_status::timeout) { + // time expired + errno = EAGAIN; + res = -1; + } + lck.unlock(); // unlock mtx + mutex_->lock(); // lock mutex_ + return res; + } + + inline void broadcast() + { + std::unique_lock lck(mtx); // lock mtx + cv.notify_all(); + } + + private: + + std::condition_variable cv; + std::mutex mtx; + + // Disable copy construction and assignment. + condition_variable_t(const condition_variable_t&); + void operator = (const condition_variable_t&); + }; #endif } @@ -214,9 +214,9 @@ namespace zmq struct timespec timeout; #if defined ZMQ_HAVE_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12 - alt_clock_gettime(CLOCK_REALTIME, &timeout); + alt_clock_gettime(SYSTEM_CLOCK, &timeout); #else - clock_gettime(CLOCK_REALTIME, &timeout); + clock_gettime(CLOCK_MONOTONIC, &timeout); #endif timeout.tv_sec += timeout_ / 1000;