Converted concurrency classes to use boost::shared_ptr and boost::weak_ptr:

Wrapped all thrift code in facebook::thrift:: namespace


	


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664735 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Monitor.cc b/lib/cpp/src/concurrency/Monitor.cc
index b1d7b72..7493ec3 100644
--- a/lib/cpp/src/concurrency/Monitor.cc
+++ b/lib/cpp/src/concurrency/Monitor.cc
@@ -22,35 +22,26 @@
  public:
 
   Impl() : 
-    mutexInitialized(false) {
+    mutexInitialized(false),
+    condInitialized(false) {
     
-    /* XXX
-       Need to fix this to handle failures without leaking.  */
+    try {
 
-    assert(pthread_mutex_init(&_pthread_mutex, NULL) == 0);
+      assert(pthread_mutex_init(&_pthread_mutex, NULL) == 0);
 
-    mutexInitialized = true;
+      mutexInitialized = true;
 
-    assert(pthread_cond_init(&_pthread_cond, NULL) == 0);
-  }
+      assert(pthread_cond_init(&_pthread_cond, NULL) == 0);
 
-  ~Impl() {
+      condInitialized = true;
 
-    if(mutexInitialized) {
-
-      mutexInitialized = false;
-
-      assert(pthread_mutex_destroy(&_pthread_mutex) == 0);
-    }
-
-    if(condInitialized) {
-
-      condInitialized = false;
-
-      assert(pthread_cond_destroy(&_pthread_cond) == 0);
+    } catch(...) {
+      cleanup();
     }
   }
 
+  ~Impl() {cleanup();}
+
   void lock() const {pthread_mutex_lock(&_pthread_mutex);}
 
   void unlock() const {pthread_mutex_unlock(&_pthread_mutex);}
@@ -98,6 +89,23 @@
 
 private:
 
+  void cleanup() {
+
+    if(mutexInitialized) {
+
+      mutexInitialized = false;
+
+      assert(pthread_mutex_destroy(&_pthread_mutex) == 0);
+    }
+
+    if(condInitialized) {
+
+      condInitialized = false;
+
+      assert(pthread_cond_destroy(&_pthread_cond) == 0);
+    }
+  }
+
   mutable pthread_mutex_t _pthread_mutex;
 
   mutable bool mutexInitialized;