Merge bzr://10.0.3.21 Build: jenkins-Libmemcached-469
[awesomized/libmemcached] / libtest / thread.hpp
index 25fc09939f2b09909c4c800e94b3fdfbfe1c266a..b09da7fcef266821e83eed7b5798368dc1b0b570 100644 (file)
@@ -46,30 +46,32 @@ namespace thread
 class Mutex
 {
 public:
-  Mutex()
+  Mutex() :
+    _err(0)
   {
-    int err;
-    if ((err= pthread_mutex_init(&_mutex, NULL)))
-    {
-      throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(err));
-    }
+    _err= pthread_mutex_init(&_mutex, NULL);
   }
 
   ~Mutex()
   {
-    int err;
-    if ((err= pthread_mutex_destroy(&_mutex)))
+    if ((_err= pthread_mutex_destroy(&_mutex)))
     {
-      throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(err));
+      throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_cond_destroy: %s", strerror(_err));
     }
   }
 
   pthread_mutex_t* handle()
   {
+    if (_err != 0)
+    {
+      throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "pthread_mutex_init: %s", strerror(_err));
+    }
+
     return &_mutex;
   }
 
 private:
+  int _err;
   pthread_mutex_t _mutex;
 };