X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fthread.hpp;h=b09da7fcef266821e83eed7b5798368dc1b0b570;hb=d9db3f534bc38ea22e83e5529ff93aea4150ab19;hp=25fc09939f2b09909c4c800e94b3fdfbfe1c266a;hpb=17690735658d7b44f91579df91e31da9ae185158;p=m6w6%2Flibmemcached diff --git a/libtest/thread.hpp b/libtest/thread.hpp index 25fc0993..b09da7fc 100644 --- a/libtest/thread.hpp +++ b/libtest/thread.hpp @@ -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; };