mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
add rwlock helper classes
This commit is contained in:
parent
a809a057e4
commit
fdca4b0a88
1 changed files with 32 additions and 0 deletions
|
@ -62,4 +62,36 @@ class SocketWriteLock {
|
||||||
int m_socket;
|
int m_socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RWReadLock {
|
||||||
|
public:
|
||||||
|
RWReadLock( pthread_rwlock_t* rwl ) {
|
||||||
|
logf( "locking rwlock for read" );
|
||||||
|
pthread_rwlock_rdlock( rwl );
|
||||||
|
logf( "locked rwlock for read" );
|
||||||
|
_rwl = rwl;
|
||||||
|
}
|
||||||
|
~RWReadLock() {
|
||||||
|
pthread_rwlock_unlock( _rwl );
|
||||||
|
logf( "unlocked rwlock" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
pthread_rwlock_t* _rwl;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RWWriteLock {
|
||||||
|
public:
|
||||||
|
RWWriteLock( pthread_rwlock_t* rwl ) : _rwl(rwl) {
|
||||||
|
logf( "locking rwlock for write" );
|
||||||
|
pthread_rwlock_wrlock( rwl );
|
||||||
|
logf( "locked rwlock for write" );
|
||||||
|
}
|
||||||
|
~RWWriteLock() {
|
||||||
|
pthread_rwlock_unlock( _rwl );
|
||||||
|
logf( "unlocked rwlock" );
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
pthread_rwlock_t* _rwl;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue