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.cpp
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 
19 #include <ucommon-config.h>
20 #include <ucommon/export.h>
21 #include <ucommon/access.h>
22 
23 namespace ucommon {
24 
26 {
27 }
28 
30 {
31 }
32 
34 {
35 }
36 
38 {
39 }
40 
42 {
43  assert(obj != NULL);
44  lock = obj;
45  modify = false;
46  state = 0;
47  lock->_share();
48 }
49 
51 {
52  assert(copy.modify == false);
53 
54  lock = copy.lock;
55  modify = false;
56  state = 0;
57  if(lock)
58  lock->_share();
59 }
60 
62 {
63  assert(copy.modify == false);
64 
65  release();
66  lock = copy.lock;
67  state = 0;
68  if(lock)
69  lock->_share();
70 
71  return *this;
72 }
73 
75 {
76  assert(obj != NULL);
77  lock = obj;
78  lock->_lock();
79 }
80 
82 {
83  if(lock) {
84  if(modify)
85  lock->share();
86  lock->_unshare();
87  lock = NULL;
88  modify = false;
89  }
90 }
91 
93 {
94  if(lock) {
95  lock->_unlock();
96  lock = NULL;
97  }
98 }
99 
101 {
102  if(lock) {
103  if(modify)
104  lock->share();
105  lock->_unshare();
106  lock = NULL;
107  modify = false;
108  }
109 }
110 
112 {
113  if(lock) {
114  lock->_unlock();
115  lock = NULL;
116  }
117 }
118 
120 {
121  if(lock && !modify) {
122  lock->exclusive();
123  modify = true;
124  }
125 }
126 
128 {
129  if(lock && modify) {
130  lock->share();
131  modify = false;
132  }
133 }
134 
135 } // namespace ucommon
ucommon::SharedProtocol::_share
virtual void _share(void)=0
export.h
ucommon::ExclusiveProtocol::~ExclusiveProtocol
virtual ~ExclusiveProtocol()
Definition: access.cpp:29
ucommon::SharedProtocol::Locking::state
int state
Definition: access.h:146
ucommon
Definition: access.cpp:23
ucommon::SharedProtocol::share
virtual void share(void)
Definition: access.cpp:37
ucommon::SharedProtocol::Locking::~Locking
~Locking()
Definition: access.cpp:81
ucommon::ExclusiveProtocol::Locking::~Locking
~Locking()
Definition: access.cpp:92
ucommon::copy
T copy(const T &src)
Definition: generics.h:395
ucommon::ExclusiveProtocol::Locking::Locking
Locking(ExclusiveProtocol *object)
Definition: access.cpp:74
ucommon::SharedProtocol::~SharedProtocol
virtual ~SharedProtocol()
Definition: access.cpp:25
ucommon::SharedProtocol::Locking::lock
SharedProtocol * lock
Definition: access.h:145
ucommon::SharedProtocol::exclusive
virtual void exclusive(void)
Definition: access.cpp:33
ucommon::SharedProtocol::Locking::exclusive
void exclusive(void)
Definition: access.cpp:119
ucommon::SharedProtocol::Locking::share
void share(void)
Definition: access.cpp:127
ucommon::SharedProtocol::Locking
Definition: access.h:142
ucommon::SharedProtocol::Locking::operator=
Locking & operator=(const Locking &copy)
Definition: access.cpp:61
ucommon::SharedProtocol::Locking::release
void release(void)
Definition: access.cpp:100
ucommon::ExclusiveProtocol::Locking::release
void release(void)
Definition: access.cpp:111
ucommon::ExclusiveProtocol
Definition: access.h:55
access.h
ucommon::ExclusiveProtocol::_lock
virtual void _lock(void)=0
ucommon::SharedProtocol
Definition: access.h:122
ucommon::SharedProtocol::Locking::Locking
Locking(SharedProtocol *object)
Definition: access.cpp:41
ucommon::SharedProtocol::Locking::modify
bool modify
Definition: access.h:147