Allocator Builder
Policy Based C++ Template Allocator Library
 All Classes Functions Variables Enumerations Enumerator Groups Pages
shared_helpers.hpp
1 //
3 // Copyright 2014 Felix Petriconi
4 //
5 // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0
6 //
7 // Authors: http://petriconi.net, Felix Petriconi
8 //
10 #pragma once
11 
12 #include <boost/thread.hpp>
13 #include <mutex>
14 
15 namespace alb {
16  inline namespace v_100 {
17  namespace shared_helpers {
18 
24  class NullLock {
25  public:
26  explicit NullLock(boost::shared_mutex &) noexcept
27  {
28  }
29  };
30 
36  class SharedLock {
37  boost::shared_lock<boost::shared_mutex> _lock;
38 
39  public:
40  explicit SharedLock(boost::shared_mutex &m) noexcept
41  : _lock(m)
42  {
43  }
44  };
45 
51  class UniqueLock {
52  boost::unique_lock<boost::shared_mutex> _lock;
53 
54  public:
55  explicit UniqueLock(boost::shared_mutex &m) noexcept
56  : _lock(m)
57  {
58  }
59  };
60 
61  struct null_mutex {
62  };
63 
64  struct null_lock {
65  explicit null_lock(null_mutex &) noexcept
66  {
67  }
68  };
69 
70  template <class M> struct lock_guard;
71 
72  template <> struct lock_guard<null_mutex> {
73  lock_guard(null_mutex &) noexcept
74  {
75  }
76  };
77 
78  template <> struct lock_guard<std::mutex> {
79  std::unique_lock<std::mutex> _lock;
80 
81  private:
82  explicit lock_guard(std::mutex &m) noexcept
83  : _lock(m)
84  {
85  }
86  };
87 
88  } // namespace helpers
89  }
90  using namespace v_100;
91 } // namespace alb