跨平台(windows和unix系列)读写锁

未添加文件包含


//**********************************************************************

//处理读写锁的区别
//**********************************************************************
#ifdef WINDOWS
//适用于vista以及server 2008及以上系统
#define RWLOCK_VAR          SRWLOCK
#define INIT_RWLOCK_VAR(v)      InitializeSRWLock(&(v))
#define ENTER_READ_LOCK_VAR(v)  AcquireSRWLockShared(&(v))
#define LEAVE_READ_LOCK_VAR(v)  ReleaseSRWLockShared(&(v))
#define ENTER_WRITE_LOCK_VAR(v)  AcquireSRWLockExclusive(&(v))
#define LEAVE_WRITE_LOCK_VAR(v)  ReleaseSRWLockExclusive(&(v))
#define DELETE_RWLOCK_VAR(v)  
#endif


#ifdef UNIX
#define RWLOCK_VAR          pthread_rwlock_t
#define INIT_RWLOCK_VAR(v)      pthread_rwlock_init(&(v), NULL)
#define ENTER_READ_LOCK_VAR(v)  pthread_rwlock_rdlock(&(v))
#define LEAVE_READ_LOCK_VAR(v)  pthread_rwlock_unlock(&(v))
#define ENTER_WRITE_LOCK_VAR(v)  pthread_rwlock_wrlock(&(v))
#define LEAVE_WRITE_LOCK_VAR(v)  pthread_rwlock_unlock(&(v))
#define DELETE_RWLOCK_VAR(v)      pthread_rwlock_destroy(&(v))
#endif

你可能感兴趣的:(C++,C++,线程,同步)