Merge "Make Condition use CLOCK_MONOTONIC"
This commit is contained in:
commit
7f932afefc
1 changed files with 12 additions and 9 deletions
|
|
@ -86,19 +86,22 @@ private:
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
|
|
||||||
inline Condition::Condition() {
|
inline Condition::Condition() : Condition(PRIVATE) {
|
||||||
pthread_cond_init(&mCond, NULL);
|
|
||||||
}
|
}
|
||||||
inline Condition::Condition(int type) {
|
inline Condition::Condition(int type) {
|
||||||
|
pthread_condattr_t attr;
|
||||||
|
pthread_condattr_init(&attr);
|
||||||
|
#if defined(__linux__)
|
||||||
|
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (type == SHARED) {
|
if (type == SHARED) {
|
||||||
pthread_condattr_t attr;
|
|
||||||
pthread_condattr_init(&attr);
|
|
||||||
pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
||||||
pthread_cond_init(&mCond, &attr);
|
|
||||||
pthread_condattr_destroy(&attr);
|
|
||||||
} else {
|
|
||||||
pthread_cond_init(&mCond, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_cond_init(&mCond, &attr);
|
||||||
|
pthread_condattr_destroy(&attr);
|
||||||
|
|
||||||
}
|
}
|
||||||
inline Condition::~Condition() {
|
inline Condition::~Condition() {
|
||||||
pthread_cond_destroy(&mCond);
|
pthread_cond_destroy(&mCond);
|
||||||
|
|
@ -109,7 +112,7 @@ inline status_t Condition::wait(Mutex& mutex) {
|
||||||
inline status_t Condition::waitRelative(Mutex& mutex, nsecs_t reltime) {
|
inline status_t Condition::waitRelative(Mutex& mutex, nsecs_t reltime) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
#else // __APPLE__
|
#else // __APPLE__
|
||||||
// Apple doesn't support POSIX clocks.
|
// Apple doesn't support POSIX clocks.
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue