blob: 39d768e5caaf9b767203c2c1a7f905254b6b9b87 [file] [log] [blame]
Marc Slemko66949872006-07-15 01:52:39 +00001#include "Mutex.h"
2
3#include <assert.h>
4#include <pthread.h>
5
6namespace facebook { namespace thrift { namespace concurrency {
7
8class Mutex::impl {
9public:
10 impl() : initialized(false) {
11 assert(pthread_mutex_init(&_pthread_mutex, NULL) == 0);
12 initialized = true;
13 }
14
15 ~impl() {
16 if(initialized) {
17 initialized = false;
18 assert(pthread_mutex_destroy(&_pthread_mutex) == 0);
19 }
20 }
21
22 void lock() const {pthread_mutex_lock(&_pthread_mutex);}
23
24 void unlock() const {pthread_mutex_unlock(&_pthread_mutex);}
25
26private:
27 mutable pthread_mutex_t _pthread_mutex;
28 mutable bool initialized;
29};
30
31Mutex::Mutex() : _impl(new Mutex::impl()) {}
32
33void Mutex::lock() const {_impl->lock();}
34
35void Mutex::unlock() const {_impl->unlock();}
36
37}}} // facebook::thrift::concurrency
38