mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-27 19:10:22 +01:00
* change macOS < 10.12 clock to SYSTEM_CLOCK, fixes #2537 * remove clock_id option from alt_clock_gettime since we always want a monotonic clock. * update header definition for alt_clock_gettime * pass clock definition down to host_get_clock_service for macOS < 10.12 * change to monotonic clocks
This commit is contained in:
@@ -81,15 +81,15 @@ namespace zmq
|
||||
|
||||
#else
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS_TARGET_XP
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#endif
|
||||
#ifdef ZMQ_HAVE_WINDOWS_TARGET_XP
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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;
|
||||
|
||||
Reference in New Issue
Block a user