00001 #ifndef COIN_SBRWMUTEX_H
00002 #define COIN_SBRWMUTEX_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <Inventor/C/threads/rwmutex.h>
00028
00029 class SbRWMutex {
00030 public:
00031 enum Precedence {
00032 READ_PRECEDENCE,
00033 WRITE_PRECEDENCE
00034 };
00035
00036 SbRWMutex(Precedence policy) {
00037 this->rwmutex = cc_rwmutex_construct_etc(
00038 (policy == WRITE_PRECEDENCE)? CC_WRITE_PRECEDENCE : CC_READ_PRECEDENCE);
00039 }
00040 ~SbRWMutex(void) { cc_rwmutex_destruct(this->rwmutex); }
00041
00042 int writeLock(void) {
00043 return cc_rwmutex_write_lock(this->rwmutex) == CC_OK ? 0 : 1;
00044 }
00045 SbBool tryWriteLock(void) {
00046 return cc_rwmutex_write_try_lock(this->rwmutex) == CC_OK;
00047 }
00048 int writeUnlock(void) {
00049 return cc_rwmutex_write_unlock(this->rwmutex) == CC_OK ? 0 : 1;
00050 }
00051
00052 int readLock(void) {
00053 return cc_rwmutex_read_lock(this->rwmutex) == CC_OK ? 0 : 1;
00054 }
00055 int tryReadLock(void) {
00056 return cc_rwmutex_read_try_lock(this->rwmutex) == CC_OK;
00057 }
00058 int readUnlock(void) {
00059 return cc_rwmutex_read_unlock(this->rwmutex) == CC_OK ? 0 : 1;
00060 }
00061
00062 private:
00063 cc_rwmutex * rwmutex;
00064 };
00065
00066 #endif // !COIN_SBRWMUTEX_H