Checkpoint of initial cut at thread pool manager for thrift and related concurrency classes.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664721 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Mutex.cc b/lib/cpp/src/concurrency/Mutex.cc
new file mode 100644
index 0000000..39d768e
--- /dev/null
+++ b/lib/cpp/src/concurrency/Mutex.cc
@@ -0,0 +1,38 @@
+#include "Mutex.h"
+
+#include <assert.h>
+#include <pthread.h>
+
+namespace facebook { namespace thrift { namespace concurrency { 
+
+class Mutex::impl {
+public:
+  impl() : initialized(false) {
+    assert(pthread_mutex_init(&_pthread_mutex, NULL) == 0);
+    initialized = true;
+  }
+
+  ~impl() {
+    if(initialized) {
+      initialized = false;
+      assert(pthread_mutex_destroy(&_pthread_mutex) == 0);
+    }
+  }
+
+  void lock() const {pthread_mutex_lock(&_pthread_mutex);}
+
+  void unlock() const {pthread_mutex_unlock(&_pthread_mutex);}
+
+private:
+  mutable pthread_mutex_t _pthread_mutex;
+  mutable bool initialized;
+};
+
+Mutex::Mutex() : _impl(new Mutex::impl()) {}
+
+void Mutex::lock() const {_impl->lock();}
+
+void Mutex::unlock() const {_impl->unlock();}
+
+}}} // facebook::thrift::concurrency
+