cpp: Let Monitors share Mutex instances
- Let Monitor objects share a Mutex() instance so that more than one
condition can be implemented on top of a single mutex protecting an
important data structure.
- Make Mutex and Monitor noncopyable
- Add an accessor to Mutex() so the underlying pthread_mutex_t* can be
retrieved for passing to pthread_condwait
- Change Monitor to use the actual Mutex class instead of creating a
naked pthread_mutex_t on its own
- Add new constructors to Monitor
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@920666 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Mutex.cpp b/lib/cpp/src/concurrency/Mutex.cpp
index 045dbdf..5d33c11 100644
--- a/lib/cpp/src/concurrency/Mutex.cpp
+++ b/lib/cpp/src/concurrency/Mutex.cpp
@@ -52,6 +52,8 @@
void unlock() const { pthread_mutex_unlock(&pthread_mutex_); }
+ void* getUnderlyingImpl() const { return (void*) &pthread_mutex_; }
+
private:
mutable pthread_mutex_t pthread_mutex_;
mutable bool initialized_;
@@ -59,6 +61,8 @@
Mutex::Mutex(Initializer init) : impl_(new Mutex::impl(init)) {}
+void* Mutex::getUnderlyingImpl() const { return impl_->getUnderlyingImpl(); }
+
void Mutex::lock() const { impl_->lock(); }
bool Mutex::trylock() const { return impl_->trylock(); }