Usermode/libc++ - Implement map::insert and map::erase
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / include_exp / mutex
1 /*
2  * Acess2 C++ Library
3  * - By John Hodge (thePowersGang)
4  *
5  * mutex (header)
6  * - C++11's tutex handling
7  */
8 #ifndef _LIBCXX_MUTEX_
9 #define _LIBCXX_MUTEX_
10
11 #include "_libcxx_helpers.h"
12
13 #if !_CXX11_AVAIL
14 # error "<mutex> requires C++11 support"
15 #endif
16
17 namespace std {
18
19 #if _CXX11_AVAIL
20
21 class mutex
22 {
23 public:
24         constexpr mutex() noexcept:
25                 m_flag(false)
26         {
27         }
28         mutex(const mutex&) = delete;
29         mutex& operator=(const mutex&) = delete;
30         ~mutex();
31         
32         void lock();
33         bool try_lock();
34         void unlock();
35
36         typedef void*   native_handle;
37 private:
38         // TODO: Proper userland mutex support
39         bool    m_flag;
40 };
41
42 struct defer_lock_t {};
43 struct try_to_lock_t {};
44 struct adopt_lock_t {};
45
46 template< class Mutex >
47 class lock_guard
48 {
49 public:
50         typedef Mutex   mutex_type;
51 private:
52         mutex_type&     m_lock;
53 public:
54         lock_guard(mutex_type& m):
55                 m_lock(m)
56         {
57                 m_lock.lock();
58         }
59         lock_guard(mutex_type& m, std::adopt_lock_t t):
60                 m_lock(m)
61         {
62                 // Adopted
63         }
64         ~lock_guard() {
65                 m_lock.unlock();
66         }
67 };
68
69 #endif
70
71 };      // namespace std
72
73 #endif
74
75 // vim: ft=cpp
76

UCC git Repository :: git.ucc.asn.au