source: rrlib_thread/tRecursiveMutex.h @ 29:2106283fc9a9

Last change on this file since 29:2106283fc9a9 was 15:d0e7b92ad22f, checked in by Tobias Föhst <foehst@…>, 6 years ago

Added and updated license information

File size: 3.7 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    rrlib/thread/tRecursiveMutex.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2012-07-04
27 *
28 * \brief   Contains tRecursiveMutex
29 *
30 * \b tRecursiveMutex
31 *
32 * Recursive Mutex with info on lock order.
33 * Note, that some comments suggest that using recursive mutexes indicates suboptimal design.
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__thread__tRecursiveMutex_h__
37#define __rrlib__thread__tRecursiveMutex_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42#include <mutex>
43
44//----------------------------------------------------------------------
45// Internal includes with ""
46//----------------------------------------------------------------------
47#include "rrlib/thread/tOrderedMutexBaseClass.h"
48
49//----------------------------------------------------------------------
50// Namespace declaration
51//----------------------------------------------------------------------
52namespace rrlib
53{
54namespace thread
55{
56
57//----------------------------------------------------------------------
58// Forward declarations / typedefs / enums
59//----------------------------------------------------------------------
60class tLock;
61
62//----------------------------------------------------------------------
63// Class declaration
64//----------------------------------------------------------------------
65//! Recursive Mutex with info on lock order.
66/*!
67 * After acquiring such a mutex, only simple mutexes, mutexes with a higher lock order and recursive mutexes already locked may may be acquired.
68 * Note, that some comments suggest that using recursive mutexes indicates suboptimal design.
69 */
70class tRecursiveMutex : public tOrderedMutexBaseClass
71{
72  friend class tLock;
73
74//----------------------------------------------------------------------
75// Public methods and typedefs
76//----------------------------------------------------------------------
77public:
78
79  typedef rrlib::thread::tLock tLock;
80
81  explicit tRecursiveMutex(const char* description, int primary = 0x7FFFFFFF, int secondary = 0) : // per default, we have an innermost mutex
82    tOrderedMutexBaseClass(description, primary, secondary)
83#ifndef RRLIB_SINGLE_THREADED
84    , wrapped()
85#endif
86  {}
87
88//----------------------------------------------------------------------
89// Private fields and methods
90//----------------------------------------------------------------------
91private:
92
93#ifndef RRLIB_SINGLE_THREADED
94
95  /*! Wrapped mutex class */
96  mutable std::recursive_mutex wrapped;
97
98#endif
99};
100
101//----------------------------------------------------------------------
102// End of namespace declaration
103//----------------------------------------------------------------------
104}
105}
106
107
108#endif
Note: See TracBrowser for help on using the repository browser.