Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::recursive_mutex Class Reference

Mutex that allows recursive mutex acquisition. More...

#include <recursive_mutex.h>

Inheritance diagram for tbb::recursive_mutex:
Collaboration diagram for tbb::recursive_mutex:

Classes

class  scoped_lock
 The scoped locking pattern. More...
 

Public Types

typedef pthread_mutex_t * native_handle_type
 Return native_handle. More...
 

Public Member Functions

 recursive_mutex ()
 Construct unacquired recursive_mutex. More...
 
 ~recursive_mutex ()
 
void lock ()
 Acquire lock. More...
 
bool try_lock ()
 Try acquiring lock (non-blocking) More...
 
void unlock ()
 Release lock. More...
 
native_handle_type native_handle ()
 

Static Public Attributes

static const bool is_rw_mutex = false
 
static const bool is_recursive_mutex = true
 
static const bool is_fair_mutex = false
 

Private Member Functions

void __TBB_EXPORTED_METHOD internal_construct ()
 All checks from mutex constructor using mutex.state were moved here. More...
 
void __TBB_EXPORTED_METHOD internal_destroy ()
 All checks from mutex destructor using mutex.state were moved here. More...
 

Private Attributes

pthread_mutex_t impl
 

Friends

class scoped_lock
 

Detailed Description

Mutex that allows recursive mutex acquisition.

Mutex that allows recursive mutex acquisition.

Definition at line 39 of file recursive_mutex.h.

Member Typedef Documentation

◆ native_handle_type

typedef pthread_mutex_t* tbb::recursive_mutex::native_handle_type

Return native_handle.

Definition at line 208 of file recursive_mutex.h.

Constructor & Destructor Documentation

◆ recursive_mutex()

tbb::recursive_mutex::recursive_mutex ( )
inline

Construct unacquired recursive_mutex.

Definition at line 42 of file recursive_mutex.h.

42  {
43 #if TBB_USE_ASSERT || TBB_USE_THREADING_TOOLS
45 #else
46  #if _WIN32||_WIN64
47  InitializeCriticalSectionEx(&impl, 4000, 0);
48  #else
49  pthread_mutexattr_t mtx_attr;
50  int error_code = pthread_mutexattr_init( &mtx_attr );
51  if( error_code )
52  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutexattr_init failed");
53 
54  pthread_mutexattr_settype( &mtx_attr, PTHREAD_MUTEX_RECURSIVE );
55  error_code = pthread_mutex_init( &impl, &mtx_attr );
56  if( error_code )
57  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutex_init failed");
58 
59  pthread_mutexattr_destroy( &mtx_attr );
60  #endif /* _WIN32||_WIN64*/
61 #endif /* TBB_USE_ASSERT */
62  };
pthread_mutex_t impl
void __TBB_EXPORTED_METHOD internal_construct()
All checks from mutex constructor using mutex.state were moved here.
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info.
Definition: tbb_misc.cpp:78

References tbb::internal::handle_perror(), impl, and internal_construct().

Here is the call graph for this function:

◆ ~recursive_mutex()

tbb::recursive_mutex::~recursive_mutex ( )
inline

Definition at line 64 of file recursive_mutex.h.

64  {
65 #if TBB_USE_ASSERT
67 #else
68  #if _WIN32||_WIN64
69  DeleteCriticalSection(&impl);
70  #else
71  pthread_mutex_destroy(&impl);
72 
73  #endif /* _WIN32||_WIN64 */
74 #endif /* TBB_USE_ASSERT */
75  };
void __TBB_EXPORTED_METHOD internal_destroy()
All checks from mutex destructor using mutex.state were moved here.
pthread_mutex_t impl

References impl, and internal_destroy().

Here is the call graph for this function:

Member Function Documentation

◆ internal_construct()

void tbb::recursive_mutex::internal_construct ( )
private

All checks from mutex constructor using mutex.state were moved here.

Definition at line 97 of file recursive_mutex.cpp.

97  {
98 #if _WIN32||_WIN64
99  InitializeCriticalSectionEx(&impl, 4000, 0);
100  state = INITIALIZED;
101 #else
102  pthread_mutexattr_t mtx_attr;
103  int error_code = pthread_mutexattr_init( &mtx_attr );
104  if( error_code )
105  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutexattr_init failed");
106 
107  pthread_mutexattr_settype( &mtx_attr, PTHREAD_MUTEX_RECURSIVE );
108  error_code = pthread_mutex_init( &impl, &mtx_attr );
109  if( error_code )
110  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutex_init failed");
111  pthread_mutexattr_destroy( &mtx_attr );
112 #endif /* _WIN32||_WIN64*/
113  ITT_SYNC_CREATE(&impl, _T("tbb::recursive_mutex"), _T(""));
114 }
pthread_mutex_t impl
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:123
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Definition: itt_notify.h:66
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info.
Definition: tbb_misc.cpp:78

References _T, tbb::internal::handle_perror(), impl, and ITT_SYNC_CREATE.

Referenced by recursive_mutex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_destroy()

void tbb::recursive_mutex::internal_destroy ( )
private

All checks from mutex destructor using mutex.state were moved here.

Definition at line 116 of file recursive_mutex.cpp.

116  {
117 #if _WIN32||_WIN64
118  switch( state ) {
119  case INITIALIZED:
120  DeleteCriticalSection(&impl);
121  break;
122  case DESTROYED:
123  __TBB_ASSERT(false,"recursive_mutex: already destroyed");
124  break;
125  default:
126  __TBB_ASSERT(false,"recursive_mutex: illegal state for destruction");
127  break;
128  }
129  state = DESTROYED;
130 #else
131  int error_code = pthread_mutex_destroy(&impl);
132  __TBB_ASSERT_EX(!error_code,"recursive_mutex: pthread_mutex_destroy failed");
133 #endif /* _WIN32||_WIN64 */
134 }
pthread_mutex_t impl
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
Definition: tbb_stddef.h:171

References __TBB_ASSERT, __TBB_ASSERT_EX, and impl.

Referenced by ~recursive_mutex().

Here is the caller graph for this function:

◆ lock()

void tbb::recursive_mutex::lock ( )
inline

Acquire lock.

Definition at line 158 of file recursive_mutex.h.

158  {
159 #if TBB_USE_ASSERT
160  aligned_space<scoped_lock> tmp;
161  new(tmp.begin()) scoped_lock(*this);
162 #else
163  #if _WIN32||_WIN64
164  EnterCriticalSection(&impl);
165  #else
166  int error_code = pthread_mutex_lock(&impl);
167  if( error_code )
168  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutex_lock failed");
169  #endif /* _WIN32||_WIN64 */
170 #endif /* TBB_USE_ASSERT */
171  }
pthread_mutex_t impl
friend class scoped_lock
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info.
Definition: tbb_misc.cpp:78

References tbb::aligned_space< T, N >::begin(), tbb::internal::handle_perror(), impl, and scoped_lock.

Here is the call graph for this function:

◆ native_handle()

native_handle_type tbb::recursive_mutex::native_handle ( )
inline

Definition at line 210 of file recursive_mutex.h.

210 { return (native_handle_type) &impl; }
pthread_mutex_t impl
pthread_mutex_t * native_handle_type
Return native_handle.

References impl.

◆ try_lock()

bool tbb::recursive_mutex::try_lock ( )
inline

Try acquiring lock (non-blocking)

Return true if lock acquired; false otherwise.

Definition at line 175 of file recursive_mutex.h.

175  {
176 #if TBB_USE_ASSERT
177  aligned_space<scoped_lock> tmp;
178  return (new(tmp.begin()) scoped_lock)->internal_try_acquire(*this);
179 #else
180  #if _WIN32||_WIN64
181  return TryEnterCriticalSection(&impl)!=0;
182  #else
183  return pthread_mutex_trylock(&impl)==0;
184  #endif /* _WIN32||_WIN64 */
185 #endif /* TBB_USE_ASSERT */
186  }
pthread_mutex_t impl
friend class scoped_lock

References tbb::aligned_space< T, N >::begin(), and impl.

Here is the call graph for this function:

◆ unlock()

void tbb::recursive_mutex::unlock ( )
inline

Release lock.

Definition at line 189 of file recursive_mutex.h.

189  {
190 #if TBB_USE_ASSERT
191  aligned_space<scoped_lock> tmp;
192  scoped_lock& s = *tmp.begin();
193  s.my_mutex = this;
194  s.internal_release();
195 #else
196  #if _WIN32||_WIN64
197  LeaveCriticalSection(&impl);
198  #else
199  pthread_mutex_unlock(&impl);
200  #endif /* _WIN32||_WIN64 */
201 #endif /* TBB_USE_ASSERT */
202  }
pthread_mutex_t impl
friend class scoped_lock
void const char const char int ITT_FORMAT __itt_group_sync s

References tbb::aligned_space< T, N >::begin(), impl, and s.

Referenced by tbb::recursive_mutex::scoped_lock::release().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ scoped_lock

friend class scoped_lock
friend

Definition at line 77 of file recursive_mutex.h.

Referenced by lock().

Member Data Documentation

◆ impl

◆ is_fair_mutex

const bool tbb::recursive_mutex::is_fair_mutex = false
static

Definition at line 153 of file recursive_mutex.h.

◆ is_recursive_mutex

const bool tbb::recursive_mutex::is_recursive_mutex = true
static

Definition at line 152 of file recursive_mutex.h.

◆ is_rw_mutex

const bool tbb::recursive_mutex::is_rw_mutex = false
static

Definition at line 151 of file recursive_mutex.h.


The documentation for this class was generated from the following files:

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.