1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#ifndef MT_RW_LOCK_H
#define MT_RW_LOCK_H
#include "base.h"
#include <pthread.h>
namespace mt
{
class rw_lock
{
MT_PREVENT_COPY(rw_lock)
public:
typedef rw_lock this_type;
typedef void base_type;
rw_lock(void)
{
pthread_rwlock_init(&(this->rw), 0);
}
~rw_lock(void)
{
pthread_rwlock_destroy(&(this->rw));
}
void lock_read(void)
{
pthread_rwlock_rdlock(&(this->rw));
}
void unlock_read(void)
{
pthread_rwlock_unlock(&(this->rw));
}
void lock_write(void)
{
pthread_rwlock_wrlock(&(this->rw));
}
void unlock_write(void)
{
pthread_rwlock_unlock(&(this->rw));
}
private:
pthread_rwlock_t rw;
};
}
#endif // MT_RW_LOCK_H
|