blob: 39d768e5caaf9b767203c2c1a7f905254b6b9b87 [file] [log] [blame]
#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