identt
SharedObject.hpp
Go to the documentation of this file.
1 
33 #ifndef _IDENTT_UTILS_SHARED_OBJECT_HPP_
34 #define _IDENTT_UTILS_SHARED_OBJECT_HPP_
35 
36 #include <functional>
37 #include <boost/thread/locks.hpp>
38 #include <boost/thread/shared_mutex.hpp>
39 
40 namespace identt {
41 namespace utils {
42 template <class T>
43 class SharedObject {
44 public:
45  using LockT = boost::shared_mutex;
46  using WriteLockT = boost::unique_lock< LockT >;
47  using ReadLockT = boost::shared_lock< LockT >;
48 
53  SharedObject(const SharedObject&) = delete;
54  SharedObject& operator=(const SharedObject&) = delete;
55 
64  SharedObject(T t) : t_(t) {}
65 
69  virtual ~SharedObject () {}
70 
80  void Set(T t)
81  {
82  WriteLockT writelock(mutex_);
83  t_=t;
84  }
85 
92  T Get()
93  {
94  ReadLockT readlock(mutex_);
95  return t_;
96  }
97 
98  T t_;
99  LockT mutex_;
100 
101 };
102 } // namespace utils
103 } // namespace identt
104 #endif /* _IDENTT_UTILS_SHARED_OBJECT_HPP_ */
T Get()
Get : get.
Definition: SharedObject.hpp:92
virtual ~SharedObject()
destructor
Definition: SharedObject.hpp:69
void Set(T t)
Set : set.
Definition: SharedObject.hpp:80
Definition: SharedObject.hpp:43
SharedObject()
Constructor : default.
Definition: SharedObject.hpp:63
Definition: CryptoBase.hpp:49