You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by eplinux <ep...@126.com> on 2011/11/30 07:10:49 UTC
ReadWriteMutex
I' sorry! my previous mailbox not receive reply.
ReadWriteMutex is implemented in Mutex.cpp,it use pthread_rwlock_t rw_lock_ ,then don't implement in the BoostMutex.cpp,
So FaceBookBase.cpp don't compile in windows .
my Implementation in the BoostMutex.cpp :
class ReadWriteMutex::impl {
public:
impl() : initialized_(false) {
#ifndef THRIFT_NO_CONTENTION_PROFILING
profileTime_ = 0;
#endif
initialized_ = true;
is_write_ = false;
}
~impl() {
if(initialized_) {
initialized_ = false;
is_write_ = false;
}
}
void acquireRead() const {
PROFILE_MUTEX_START_LOCK();
rw_lock_.lock_shared();
is_write_ = false;
PROFILE_MUTEX_NOT_LOCKED(); // not exclusive, so use not-locked path
}
void acquireWrite() const {
PROFILE_MUTEX_START_LOCK();
rw_lock_.lock();
is_write_ = true;
PROFILE_MUTEX_LOCKED();
}
bool attemptRead() const {
bool ret = rw_lock_.try_lock_shared();
if (ret) {
is_write_ = false;
}
return ret;
}
bool attemptWrite() const {
bool ret = rw_lock_.try_lock();
if (ret) {
is_write_ = true;
}
return ret;
}
void release() const {
PROFILE_MUTEX_START_UNLOCK();
if ( is_write_) {
rw_lock_.unlock();
} else {
rw_lock_.unlock_shared();
}
is_write_ = false;
PROFILE_MUTEX_UNLOCKED();
}
private:
mutable boost::shared_mutex rw_lock_;
mutable bool is_write_;
mutable bool initialized_;
#ifndef THRIFT_NO_CONTENTION_PROFILING
mutable int64_t profileTime_;
#endif
};
isn't OK?
eplinux