thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eplinux <epli...@126.com>
Subject ReadWriteMutex
Date Wed, 30 Nov 2011 06:10:49 GMT
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
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message