fix cond.h time
This commit is contained in:
19
deps/oblib/src/lib/lock/cond.cpp
vendored
19
deps/oblib/src/lib/lock/cond.cpp
vendored
@ -20,7 +20,18 @@ namespace obutil
|
|||||||
{
|
{
|
||||||
Cond::Cond()
|
Cond::Cond()
|
||||||
{
|
{
|
||||||
int rt = pthread_cond_init(&_cond, NULL);
|
|
||||||
|
int rt = pthread_condattr_init(&_attr);
|
||||||
|
if (0 != rt) {
|
||||||
|
_OB_LOG_RET(WARN, OB_ERR_SYS, "Failed to init cond attr, err=%d", rt);
|
||||||
|
}
|
||||||
|
// Set the attribute to use CLOCK_MONOTONIC clock source
|
||||||
|
rt = pthread_condattr_setclock(&_attr, CLOCK_MONOTONIC);
|
||||||
|
if (0 != rt) {
|
||||||
|
_OB_LOG_RET(WARN, OB_ERR_SYS, "Failed to set MONOTONIC Clock, err=%d", rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
rt = pthread_cond_init(&_cond, &_attr);
|
||||||
if (0 != rt) {
|
if (0 != rt) {
|
||||||
_OB_LOG_RET(WARN, OB_ERR_SYS, "Failed to init cond, err=%d", rt);
|
_OB_LOG_RET(WARN, OB_ERR_SYS, "Failed to init cond, err=%d", rt);
|
||||||
}
|
}
|
||||||
@ -28,7 +39,11 @@ Cond::Cond()
|
|||||||
|
|
||||||
Cond::~Cond()
|
Cond::~Cond()
|
||||||
{
|
{
|
||||||
int rt = pthread_cond_destroy(&_cond);
|
int rt = pthread_condattr_destroy(&_attr);
|
||||||
|
if (0 != rt) {
|
||||||
|
_OB_LOG_RET(WARN, OB_ERR_SYS, "Failed to destroy cond attr, err=%d", rt);
|
||||||
|
}
|
||||||
|
rt = pthread_cond_destroy(&_cond);
|
||||||
if (0 != rt) {
|
if (0 != rt) {
|
||||||
_OB_LOG_RET(WARN, OB_ERR_SYS, "Failed to destroy cond, err=%d", rt);
|
_OB_LOG_RET(WARN, OB_ERR_SYS, "Failed to destroy cond, err=%d", rt);
|
||||||
}
|
}
|
||||||
|
|||||||
3
deps/oblib/src/lib/lock/cond.h
vendored
3
deps/oblib/src/lib/lock/cond.h
vendored
@ -71,6 +71,7 @@ private:
|
|||||||
template <typename M> bool timed_wait_impl(const M&, const ObSysTime&) const;
|
template <typename M> bool timed_wait_impl(const M&, const ObSysTime&) const;
|
||||||
|
|
||||||
mutable pthread_cond_t _cond;
|
mutable pthread_cond_t _cond;
|
||||||
|
mutable pthread_condattr_t _attr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename M> inline bool
|
template <typename M> inline bool
|
||||||
@ -104,7 +105,7 @@ Cond::timed_wait_impl(const M& mutex, const ObSysTime& timeout) const
|
|||||||
LockState state;
|
LockState state;
|
||||||
mutex.unlock(state);
|
mutex.unlock(state);
|
||||||
|
|
||||||
timeval tv = ObSysTime::now(ObSysTime::Realtime) + timeout;
|
timeval tv = ObSysTime::now(ObSysTime::Monotonic) + timeout;
|
||||||
timespec ts;
|
timespec ts;
|
||||||
ts.tv_sec = tv.tv_sec;
|
ts.tv_sec = tv.tv_sec;
|
||||||
ts.tv_nsec = tv.tv_usec * 1000;
|
ts.tv_nsec = tv.tv_usec * 1000;
|
||||||
|
|||||||
Reference in New Issue
Block a user