13 #ifndef __UT_RECURSIVETIMEDLOCK_H_INCLUDED__
14 #define __UT_RECURSIVETIMEDLOCK_H_INCLUDED__
22 #if defined(USE_PTHREADS) && !defined(MBSD)
32 #define UT_PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE
34 #define UT_PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
42 pthread_mutexattr_t attr;
43 UT_VERIFY(pthread_mutexattr_init(&attr) == 0);
44 UT_VERIFY(pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE)==0);
45 UT_VERIFY(pthread_mutex_init(&myMutex, &attr) == 0);
46 UT_VERIFY(pthread_mutexattr_destroy(&attr) == 0);
50 pthread_mutex_destroy(&myMutex);
57 int res = pthread_mutex_trylock(&myMutex);
64 UT_VERIFY(pthread_mutex_lock(&myMutex) == 0);
69 const uint64 THOUSAND = 1000;
70 const uint64 MILLION = THOUSAND * THOUSAND;
75 gettimeofday(&now, NULL);
76 usec = now.tv_usec + THOUSAND*(ms + now.tv_sec*THOUSAND);
77 timeout.tv_sec = (time_t)(usec / MILLION);
78 timeout.tv_nsec = (long)((usec % MILLION) * THOUSAND);
80 int res = pthread_mutex_timedlock(&myMutex, &
timeout);
87 UT_VERIFY(pthread_mutex_unlock(&myMutex) == 0);
104 pthread_mutex_t myMutex;
107 #elif defined(_WIN32) || defined(MBSD)
116 template <
class HBOOST_MUTEX>
117 class UT_BoostLockable :
public UT_Lockable<HBOOST_MUTEX>
120 bool timedLock(
int ms)
123 .timed_lock(hboost::posix_time::milliseconds(ms));
144 template <
class STD_MUTEX>
151 .try_lock_for(std::chrono::milliseconds(ms));
158 #endif // __UT_RECURSIVETIMEDLOCK_H_INCLUDED__
UT_Lock interface adapter for C++11 mutexes.
unsigned long long uint64
Lock adapter for std mutexes.
GLbitfield GLuint64 timeout
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
UT_UniqueLock< UT_Lockable< STD_MUTEX > > Scope
UT_StdLockable< std::recursive_timed_mutex > UT_RecursiveTimedLock