UniSet  2.8.0
Mutex.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
20 // --------------------------------------------------------------------------
21 #ifndef UniSet_MUTEX_H_
22 #define UniSet_MUTEX_H_
23 // -----------------------------------------------------------------------------------------
24 #include <string>
25 #include <memory>
26 #include <Poco/RWLock.h>
27 // -----------------------------------------------------------------------------------------
28 namespace uniset
29 {
30  // rwmutex..
32  {
33  public:
34  uniset_rwmutex( const std::string& name );
36  ~uniset_rwmutex();
37 
38  void lock();
39  void unlock();
40 
41  void wrlock();
42  void rlock();
43 
44  bool try_lock();
45  bool try_rlock();
46  bool try_wrlock();
47 
48  uniset_rwmutex( const uniset_rwmutex& r ) = delete;
49  uniset_rwmutex& operator=(const uniset_rwmutex& r) = delete;
50 
51  uniset_rwmutex( uniset_rwmutex&& r ) = default;
52  uniset_rwmutex& operator=(uniset_rwmutex&& r) = default;
53 
54  inline std::string name() const
55  {
56  return nm;
57  }
58 
59  inline void setName( const std::string& name )
60  {
61  nm = name;
62  }
63 
64  private:
65  std::string nm;
66  friend class uniset_rwmutex_lock;
67  std::unique_ptr<Poco::RWLock> m;
68  };
69 
70  std::ostream& operator<<(std::ostream& os, uniset_rwmutex& m );
71  // -------------------------------------------------------------------------
73  {
74  public:
77 
78  private:
80  uniset_rwmutex_wrlock& operator=(const uniset_rwmutex_wrlock&) = delete;
81  uniset_rwmutex& m;
82  };
83 
85  {
86  public:
89 
90  private:
92  uniset_rwmutex_rlock& operator=(const uniset_rwmutex_rlock&) = delete;
93  uniset_rwmutex& m;
94  };
95  // -------------------------------------------------------------------------
96 } // end of UniSetTypes namespace
97 
98 #endif
Definition: CommonEventLoop.h:14
Definition: Mutex.h:72
Definition: Mutex.h:31
Definition: Mutex.h:84