12 #include <ecl/config/ecl.hpp> 13 #if defined(ECL_IS_POSIX) 21 #include "../../include/ecl/threads/mutex.hpp" 37 pthread_mutexattr_t attr;
40 result = pthread_mutexattr_init(&attr);
43 #if defined(NDEBUG) || defined(ECL_NDEBUG) 44 result = pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_NORMAL);
46 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
51 result = pthread_mutex_init(&
mutex, &attr);
54 result = pthread_mutexattr_destroy(&attr);
65 pthread_mutex_destroy(&
mutex);
70 void Mutex::lock() ecl_assert_throw_decl(StandardException)
73 int result = pthread_mutex_lock(&
mutex);
80 #if defined(_POSIX_TIMEOUTS) && (_POSIX_TIMEOUTS - 200112L) >= 0L 82 timeout.tv_sec = duration.sec();
83 timeout.tv_nsec = duration.nsec();
84 int result = pthread_mutex_timedlock(&
mutex, &timeout);
85 if (result == ETIMEDOUT) {
88 ecl_assert_throw(result == 0, threads::throwMutexTimedLockException(LOC,result));
97 bool Mutex::trylock() ecl_assert_throw_decl(StandardException)
99 int result = pthread_mutex_trylock(&
mutex);
102 if (result == EBUSY) {
106 ecl_assert_throw(result == 0, threads::throwMutexLockException(LOC,result));
114 void Mutex::unlock() ecl_assert_throw_decl(StandardException)
117 int result = pthread_mutex_unlock(&
mutex);
118 ecl_assert_throw(result == 0, threads::throwMutexUnLockException(LOC,result));
Embedded control libraries.
#define ecl_assert_throw(expression, exception)
#define ecl_assert_throw_decl(exception)