From: boz Date: Sat, 22 Sep 2007 23:08:11 +0000 (+0000) Subject: THRIFT: Make the mutex assignable X-Git-Tag: 0.2.0~1192 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=19cee90ca41922a4437d547a2298201359bbcdcc;p=common%2Fthrift.git THRIFT: Make the mutex assignable Summary: we need to use a shared_ptr instead of an old fashioned one if we're going to stick with this PIMPL model Reviewed By: dreiss, marc Test Plan: test program didn't fail or leak memory, foreman (fb303 client) worked without problem Revert Plan: just make sure you find some other solution to this problem git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665280 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/concurrency/Mutex.cpp b/lib/cpp/src/concurrency/Mutex.cpp index 2674d44f..695d5dc5 100644 --- a/lib/cpp/src/concurrency/Mutex.cpp +++ b/lib/cpp/src/concurrency/Mutex.cpp @@ -46,8 +46,6 @@ class Mutex::impl { Mutex::Mutex() : impl_(new Mutex::impl()) {} -Mutex::~Mutex() { delete impl_; } - void Mutex::lock() const { impl_->lock(); } bool Mutex::trylock() const { return impl_->trylock(); } @@ -93,8 +91,6 @@ private: ReadWriteMutex::ReadWriteMutex() : impl_(new ReadWriteMutex::impl()) {} -ReadWriteMutex::~ReadWriteMutex() { delete impl_; } - void ReadWriteMutex::acquireRead() const { impl_->acquireRead(); } void ReadWriteMutex::acquireWrite() const { impl_->acquireWrite(); } diff --git a/lib/cpp/src/concurrency/Mutex.h b/lib/cpp/src/concurrency/Mutex.h index b19e3c51..dd35edb1 100644 --- a/lib/cpp/src/concurrency/Mutex.h +++ b/lib/cpp/src/concurrency/Mutex.h @@ -7,6 +7,9 @@ #ifndef _THRIFT_CONCURRENCY_MUTEX_H_ #define _THRIFT_CONCURRENCY_MUTEX_H_ 1 +#include +using boost::shared_ptr; + namespace facebook { namespace thrift { namespace concurrency { /** @@ -18,20 +21,21 @@ namespace facebook { namespace thrift { namespace concurrency { class Mutex { public: Mutex(); - virtual ~Mutex(); + virtual ~Mutex() {} virtual void lock() const; virtual bool trylock() const; virtual void unlock() const; private: + class impl; - impl* impl_; + shared_ptr impl_; }; class ReadWriteMutex { public: ReadWriteMutex(); - virtual ~ReadWriteMutex(); + virtual ~ReadWriteMutex() {} // these get the lock and block until it is done successfully virtual void acquireRead() const; @@ -45,8 +49,9 @@ public: virtual void release() const; private: + class impl; - impl* impl_; + shared_ptr impl_; }; class Guard { @@ -75,7 +80,7 @@ class RWGuard { rw_mutex_.release(); } private: - const ReadWriteMutex rw_mutex_; + const ReadWriteMutex& rw_mutex_; };