12 #ifndef THREAD_HELPER_H_
13 #define THREAD_HELPER_H_
18 #include "croflexception.h"
26 pthread_rwlock_t rwlock;
30 pthread_rwlock_init(&rwlock, attr);
33 pthread_rwlock_destroy(&rwlock);
57 mutex(mutex), locked(
false)
60 pthread_mutex_lock(this->mutex);
62 if (pthread_mutex_trylock(this->mutex) < 0) {
67 throw eSysCall(
"pthread_mutex_trylock failed");
78 pthread_mutex_unlock(this->mutex);
83 pthread_mutex_t *mutex;
90 pthread_rwlock_t *rwlock;
94 enum rwlock_rwtype_t {
103 uint8_t rwtype = RWLOCK_WRITE,
105 rwlock(rwlock), locked(false)
110 pthread_rwlock_rdlock(rwlock);
113 pthread_rwlock_wrlock(rwlock);
116 throw eLockInval(
"RwLock::RwLock() invalid locking type");
123 rc = pthread_rwlock_tryrdlock(rwlock);
126 rc = pthread_rwlock_trywrlock(rwlock);
129 throw eLockInval(
"RwLock::RwLock() invalid locking type");
135 throw eLockWouldBlock(
"RwLock::RwLock() pthread_mutex_trylock");
138 throw eSysCall(
"pthread_mutex_trylock failed");
149 uint8_t rwtype = RWLOCK_WRITE,
151 rwlock(&(pthreadRwLock.rwlock)), locked(false)
156 pthread_rwlock_rdlock(rwlock);
159 pthread_rwlock_wrlock(rwlock);
162 throw eLockInval(
"RwLock::RwLock() invalid locking type");
169 rc = pthread_rwlock_tryrdlock(rwlock);
172 rc = pthread_rwlock_trywrlock(rwlock);
175 throw eLockInval(
"RwLock::RwLock() invalid locking type");
181 throw eLockWouldBlock(
"RwLock::RwLock() pthread_mutex_trylock");
184 throw eSysCall(
"pthread_rwlock_trylock failed");
200 pthread_rwlock_unlock(rwlock);
Definition: thread_helper.h:48
Definition: thread_helper.h:53
virtual ~RwLock()
Definition: thread_helper.h:197
Definition: thread_helper.h:25
Definition: thread_helper.h:38
RwLock(pthread_rwlock_t *rwlock, uint8_t rwtype=RWLOCK_WRITE, bool blocking=true)
Definition: thread_helper.h:102
Definition: thread_helper.h:88
RwLock(PthreadRwLock &pthreadRwLock, uint8_t rwtype=RWLOCK_WRITE, bool blocking=true)
Definition: thread_helper.h:148
Definition: thread_helper.h:43
Definition: croflexception.h:40
Definition: croflexception.h:27