MutexLock.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 10 16:16:57 CEST 2002 MutexLock.hpp
3 
4  MutexLock.hpp - description
5  -------------------
6  begin : Thu October 10 2002
7  copyright : (C) 2002 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 #ifndef OS_MUTEXLOCK_HPP
39 #define OS_MUTEXLOCK_HPP
40 
41 #include "fosi.h"
42 
43 #include "Mutex.hpp"
44 
45 namespace RTT
46 { namespace os {
51  class RTT_API MutexLock
52  {
53 
54  public:
61  {
62  _mutex = &mutex;
63  _mutex->lock ();
64  }
65 
70  {
71  _mutex->unlock();
72  }
73 
74  protected:
76 
78  {}
79 
80  };
81 
87  class RTT_API MutexTryLock
88  {
89 
90  public:
91 
98  : _mutex( &mutex), successful( mutex.trylock() )
99  {
100  }
101 
108  {
109  return successful;
110  }
111 
116  {
117  if ( successful )
118  _mutex->unlock();
119  }
120 
121  protected:
126 
128  {}
129 
130  private:
131 
136 
137  };
138 
146  class RTT_API MutexTimedLock
147  {
148 
149  public:
150 
159  : _mutex( &mutex), successful( mutex.timedlock(timeout) )
160  {
161  }
162 
169  {
170  return successful;
171  }
172 
177  {
178  if ( successful )
179  _mutex->unlock();
180  }
181 
182  protected:
187 
189  {}
190 
191  private:
192 
197 
198  };
199 
204  class RTT_API SharedMutexLock
205  {
206 
207  public:
214  {
215  _mutex = &mutex;
216  _mutex->lock_shared ();
217  }
218 
223  {
224  _mutex->unlock_shared();
225  }
226 
227  protected:
229 
231  {}
232  };
233 }}
234 
235 #endif
double Seconds
Definition: os/Time.hpp:53
SharedMutexLock(MutexInterface &mutex)
Definition: MutexLock.hpp:213
virtual void lock_shared()
Definition: Mutex.hpp:75
virtual void lock()=0
MutexTimedLock(MutexInterface &mutex, Seconds timeout)
Definition: MutexLock.hpp:158
MutexInterface * _mutex
Definition: MutexLock.hpp:228
A MutexTimedLock locks a Mutex object on construction and if successful, unlocks it on destruction of...
Definition: MutexLock.hpp:146
MutexInterface * _mutex
Definition: MutexLock.hpp:75
SharedMutexLock is a scope based Monitor, protecting critical sections with a SharedMutex object thro...
Definition: MutexLock.hpp:204
MutexLock(MutexInterface &mutex)
Definition: MutexLock.hpp:60
A MutexTryLock tries to lock an Mutex object on construction and if successful, unlocks it on destruc...
Definition: MutexLock.hpp:87
MutexTryLock(MutexInterface &mutex)
Definition: MutexLock.hpp:97
MutexInterface * _mutex
Definition: MutexLock.hpp:186
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
MutexInterface * _mutex
Definition: MutexLock.hpp:125
An interface to a Mutex.
Definition: Mutex.hpp:67
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
Definition: MutexLock.hpp:51


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:34