1 
2 // vim:sw=2:ai
3 
4 /*
5  * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved.
6  * See COPYRIGHT.txt for details.
7  */
8 
9 #ifndef DENA_MUTEX_HPP
10 #define DENA_MUTEX_HPP
11 
12 #include "fatal.hpp"
13 #include "util.hpp"
14 
15 namespace dena {
16 
17 struct condition;
18 
19 struct mutex : private noncopyable {
20   friend struct condition;
mutexdena::mutex21   mutex() {
22     if (pthread_mutex_init(&mtx, 0) != 0) {
23       fatal_abort("pthread_mutex_init");
24     }
25   }
~mutexdena::mutex26   ~mutex() {
27     if (pthread_mutex_destroy(&mtx) != 0) {
28       fatal_abort("pthread_mutex_destroy");
29     }
30   }
lockdena::mutex31   void lock() const {
32     if (pthread_mutex_lock(&mtx) != 0) {
33       fatal_abort("pthread_mutex_lock");
34     }
35   }
unlockdena::mutex36   void unlock() const {
37     if (pthread_mutex_unlock(&mtx) != 0) {
38       fatal_abort("pthread_mutex_unlock");
39     }
40   }
41  private:
42   mutable pthread_mutex_t mtx;
43 };
44 
45 };
46 
47 #endif
48 
49