00001 00002 00003 #ifndef RWLOCK_H 00004 #define RWLOCK_H 00005 00006 #include <iostream> 00007 #include <pthread.h> 00008 #include <stdio.h> 00009 00010 #include "common.h" 00011 00012 using namespace Borealis; 00013 00014 00021 class RWLock 00022 { 00023 public: 00027 RWLock(); 00028 00035 void readlock( int32 id = 0 ); 00036 00043 void writelock( int32 id = 0 ); 00044 00048 void readunlock(); 00049 00053 void writeunlock(); 00054 00055 private: 00056 pthread_mutex_t mutex; 00057 pthread_mutexattr_t mutexattr; 00058 pthread_cond_t writeOK; 00059 pthread_cond_t readOK; 00060 00061 int32 writers; 00062 int32 readers; 00063 int32 waiting; 00064 }; 00065 00066 #endif // RWLOCK_H