25 #ifndef SYNC_REENTRANTLOCK_H
26 #define SYNC_REENTRANTLOCK_H
38 template<
class Status_t>
44 inline double getTime() {
47 return static_cast<double>(tv.tv_sec) + 1e-6 * static_cast<double>(tv.tv_usec);
58 pthread_mutexattr_t attr;
59 pthread_mutexattr_init(&attr);
60 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
62 pthread_mutexattr_destroy(&attr);
76 if (lock_count == 0) {
77 lock_time += Internal::getTime() - lock_last;
85 double start = Internal::getTime();
89 double time = Internal::getTime();
90 if (lock_count == 0) {
94 wait_time += time - start;
99 double GetWaitTime()
const {
return wait_time; }
100 double GetLockTime()
const {
return lock_time; }
105 mutable double wait_time;
106 mutable double lock_time;
107 mutable double lock_last;
108 mutable unsigned lock_count;
136 double time = Internal::getTime();
137 unsigned lock_count = lock.lock_count;
139 lock.lock_time += time - lock.lock_last;
141 pthread_cond_wait(&
cond, &lock.
lock);
143 double end = Internal::getTime();
144 lock.lock_count = lock_count;
145 lock.lock_last = end;
146 wait_time += end - time;
150 double GetWaitTime()
const {
return wait_time; }
154 mutable double wait_time;
void Wait(ReentrantLock &lock) const
#define ENSURE_ABORT(exp,...)
AutoLock< const ReentrantLock > AutoReentrantLock
Works just like a pthread condition but works with the ReentrantLock.
Automatic locking on the stack.