Orocos Real-Time Toolkit  2.8.3
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 {
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 
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 
135  bool successful;
136 
137  };
138 
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 
196  bool successful;
197 
198  };
199 }}
200 
201 #endif
double Seconds
Seconds are stored as a double precision float.
Definition: Time.hpp:53
#define RTT_API
Definition: rtt-config.h:97
~MutexLock()
Remove a lock from a Mutex object.
Definition: MutexLock.hpp:69
virtual void lock()=0
MutexTimedLock(MutexInterface &mutex, Seconds timeout)
Lock a Mutex object, but don't block longer than a specified timeout.
Definition: MutexLock.hpp:158
bool isSuccessful()
Return if the locking of the Mutex was succesfull.
Definition: MutexLock.hpp:107
A MutexTimedLock locks a Mutex object on construction and if successful, unlocks it on destruction of...
Definition: MutexLock.hpp:146
~MutexTimedLock()
Releases, if any, a lock on the previously try-locked Mutex.
Definition: MutexLock.hpp:176
~MutexTryLock()
Releases, if any, a lock on the previously try-locked Mutex.
Definition: MutexLock.hpp:115
bool isSuccessful()
Return if the locking of the Mutex was succesfull.
Definition: MutexLock.hpp:168
MutexInterface * _mutex
Definition: MutexLock.hpp:75
MutexLock(MutexInterface &mutex)
Create a lock on a Mutex object.
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)
Try to lock a Mutex object.
Definition: MutexLock.hpp:97
MutexInterface * _mutex
The Mutex to lock and unlock.
Definition: MutexLock.hpp:186
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
MutexInterface * _mutex
The Mutex to lock and unlock.
Definition: MutexLock.hpp:125
An interface to a Mutex.
Definition: Mutex.hpp:61
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
Definition: MutexLock.hpp:51