ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

access.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
32 // we do this twice because of some bizarre issue in just this file that
33 // otherwise breaks doxygen and lists all items outside the namespace...
34 #include <ucommon/platform.h>
35 
36 #ifndef _UCOMMON_ACCESS_H_
37 #define _UCOMMON_ACCESS_H_
38 
39 #ifndef _UCOMMON_CPR_H_
40 #include <ucommon/cpr.h>
41 #endif
42 
43 #ifndef _UCOMMON_PROTOCOLS_H_
44 #include <ucommon/protocols.h>
45 #endif
46 
47 namespace ucommon {
48 
56 {
57 protected:
58  virtual ~ExclusiveProtocol();
59 
60  virtual void _lock(void) = 0;
61 
62  virtual void _unlock(void) = 0;
63 
64 public:
73  {
74  private:
76 
78 
79  public:
84  Locking(ExclusiveProtocol *object);
85 
89  ~Locking();
90 
95  inline bool operator!() const {
96  return lock == NULL;
97  }
98 
103  inline operator bool() const {
104  return lock != NULL;
105  }
106 
112  void release(void);
113  };
114 };
115 
123 {
124 protected:
125  virtual ~SharedProtocol();
126 
130  virtual void _share(void) = 0;
131 
132  virtual void _unshare(void) = 0;
133 
134 public:
143  {
144  private:
146  int state;
147  bool modify;
148 
149  public:
154  Locking(SharedProtocol *object);
155 
156  Locking(const Locking& copy);
157 
158  Locking& operator=(const Locking& copy);
159 
163  ~Locking();
164 
169  inline bool operator!() const {
170  return lock == NULL;
171  }
172 
177  inline operator bool() const {
178  return lock != NULL;
179  }
180 
186  void release(void);
187 
191  void exclusive(void);
192 
196  void share(void);
197  };
198 
205  virtual void share(void);
206 
214  virtual void exclusive(void);
215 };
216 
225 {
226 private:
228  int state;
229  bool modify;
230 
231 public:
236  shared_access(SharedProtocol *object);
237 
239 
240  shared_access& operator=(const shared_access& copy);
241 
245  ~shared_access();
246 
251  inline bool operator!() const {
252  return lock == NULL;
253  }
254 
259  inline operator bool() const {
260  return lock != NULL;
261  }
262 
268  void release(void);
269 
273  void exclusive(void);
274 
278  void share(void);
279 };
280 
281 template<class T>
283 {
284 private:
286 
287 public:
288  inline autoexclusive(T *lock) :
290 };
291 
292 template<class T>
294 {
295 private:
297 
298 public:
299  inline autoshared(T *lock) :
301 };
302 
303 // Special macros to allow member functions of an object with a protocol
304 // to create self locking states while the member functions are called by
305 // placing an exclusive_lock or shared_lock smart object on their stack
306 // frame to reference their self.
307 
308 #define __EXCLUSIVE(x) exclusive_access __autolock__ = x
309 #define __SHARE(x) shared_access __autolock__ = x
310 
311 } // namespace ucommon
312 
313 #endif
ucommon::SharedProtocol::Locking::state
int state
Definition: access.h:146
ucommon
Definition: access.cpp:23
ucommon::autoshared
Definition: access.h:293
ucommon::autoshared::autoshared
autoshared(T *lock)
Definition: access.h:299
protocols.h
ucommon::ExclusiveProtocol::Locking::operator!
bool operator!() const
Definition: access.h:95
polystatic_cast
T polystatic_cast(S *s)
Definition: platform.h:587
ucommon::ExclusiveProtocol::Locking::lock
ExclusiveProtocol * lock
Definition: access.h:75
ucommon::shared_access::lock
SharedProtocol * lock
Definition: access.h:227
ucommon::copy
T copy(const T &src)
Definition: generics.h:395
ucommon::ExclusiveProtocol::Locking::Locking
Locking(ExclusiveProtocol *object)
Definition: access.cpp:74
ucommon::autoshared::__DELETE_DEFAULTS
__DELETE_DEFAULTS(autoshared)
ucommon::SharedProtocol::Locking::lock
SharedProtocol * lock
Definition: access.h:145
ucommon::autoexclusive
Definition: access.h:282
ucommon::ExclusiveProtocol::Locking
Definition: access.h:72
ucommon::shared_access
Definition: access.h:224
__EXPORT
#define __EXPORT
Definition: config.h:49
ucommon::shared_access::state
int state
Definition: access.h:228
cpr.h
ucommon::shared_access::operator!
bool operator!() const
Definition: access.h:251
ucommon::SharedProtocol::Locking
Definition: access.h:142
__DELETE_COPY
#define __DELETE_COPY(x)
Definition: platform.h:160
platform.h
ucommon::autoexclusive::autoexclusive
autoexclusive(T *lock)
Definition: access.h:288
ucommon::ExclusiveProtocol
Definition: access.h:55
ucommon::autoexclusive::__DELETE_DEFAULTS
__DELETE_DEFAULTS(autoexclusive)
ucommon::SharedProtocol
Definition: access.h:122
ucommon::SharedProtocol::Locking::operator!
bool operator!() const
Definition: access.h:169
ucommon::SharedProtocol::Locking::Locking
Locking(SharedProtocol *object)
Definition: access.cpp:41
ucommon::SharedProtocol::Locking::modify
bool modify
Definition: access.h:147
ucommon::shared_access::modify
bool modify
Definition: access.h:229