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 35 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 204 of file recursive_mutex.h.

Constructor & Destructor Documentation

◆ recursive_mutex()

tbb::recursive_mutex::recursive_mutex ( )
inline

Construct unacquired recursive_mutex.

Definition at line 38 of file recursive_mutex.h.

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

38  {
39 #if TBB_USE_ASSERT || TBB_USE_THREADING_TOOLS
41 #else
42  #if _WIN32||_WIN64
43  InitializeCriticalSectionEx(&impl, 4000, 0);
44  #else
45  pthread_mutexattr_t mtx_attr;
46  int error_code = pthread_mutexattr_init( &mtx_attr );
47  if( error_code )
48  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutexattr_init failed");
49 
50  pthread_mutexattr_settype( &mtx_attr, PTHREAD_MUTEX_RECURSIVE );
51  error_code = pthread_mutex_init( &impl, &mtx_attr );
52  if( error_code )
53  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutex_init failed");
54 
55  pthread_mutexattr_destroy( &mtx_attr );
56  #endif /* _WIN32||_WIN64*/
57 #endif /* TBB_USE_ASSERT */
58  };
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:74
pthread_mutex_t impl
Here is the call graph for this function:

◆ ~recursive_mutex()

tbb::recursive_mutex::~recursive_mutex ( )
inline

Definition at line 60 of file recursive_mutex.h.

References impl, and internal_destroy().

60  {
61 #if TBB_USE_ASSERT
63 #else
64  #if _WIN32||_WIN64
65  DeleteCriticalSection(&impl);
66  #else
67  pthread_mutex_destroy(&impl);
68 
69  #endif /* _WIN32||_WIN64 */
70 #endif /* TBB_USE_ASSERT */
71  };
void __TBB_EXPORTED_METHOD internal_destroy()
All checks from mutex destructor using mutex.state were moved here.
pthread_mutex_t impl
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 93 of file recursive_mutex.cpp.

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

Referenced by recursive_mutex().

93  {
94 #if _WIN32||_WIN64
95  InitializeCriticalSectionEx(&impl, 4000, 0);
96  state = INITIALIZED;
97 #else
98  pthread_mutexattr_t mtx_attr;
99  int error_code = pthread_mutexattr_init( &mtx_attr );
100  if( error_code )
101  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutexattr_init failed");
102 
103  pthread_mutexattr_settype( &mtx_attr, PTHREAD_MUTEX_RECURSIVE );
104  error_code = pthread_mutex_init( &impl, &mtx_attr );
105  if( error_code )
106  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutex_init failed");
107  pthread_mutexattr_destroy( &mtx_attr );
108 #endif /* _WIN32||_WIN64*/
109  ITT_SYNC_CREATE(&impl, _T("tbb::recursive_mutex"), _T(""));
110 }
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:119
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:74
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Definition: itt_notify.h:62
pthread_mutex_t impl
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 112 of file recursive_mutex.cpp.

References __TBB_ASSERT, __TBB_ASSERT_EX, and impl.

Referenced by ~recursive_mutex().

112  {
113 #if _WIN32||_WIN64
114  switch( state ) {
115  case INITIALIZED:
116  DeleteCriticalSection(&impl);
117  break;
118  case DESTROYED:
119  __TBB_ASSERT(false,"recursive_mutex: already destroyed");
120  break;
121  default:
122  __TBB_ASSERT(false,"recursive_mutex: illegal state for destruction");
123  break;
124  }
125  state = DESTROYED;
126 #else
127  int error_code = pthread_mutex_destroy(&impl);
128  __TBB_ASSERT_EX(!error_code,"recursive_mutex: pthread_mutex_destroy failed");
129 #endif /* _WIN32||_WIN64 */
130 }
pthread_mutex_t impl
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#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:167
Here is the caller graph for this function:

◆ lock()

void tbb::recursive_mutex::lock ( )
inline

Acquire lock.

Definition at line 154 of file recursive_mutex.h.

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

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

154  {
155 #if TBB_USE_ASSERT
156  aligned_space<scoped_lock> tmp;
157  new(tmp.begin()) scoped_lock(*this);
158 #else
159  #if _WIN32||_WIN64
160  EnterCriticalSection(&impl);
161  #else
162  int error_code = pthread_mutex_lock(&impl);
163  if( error_code )
164  tbb::internal::handle_perror(error_code,"recursive_mutex: pthread_mutex_lock failed");
165  #endif /* _WIN32||_WIN64 */
166 #endif /* TBB_USE_ASSERT */
167  }
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:74
pthread_mutex_t impl
friend class scoped_lock
Here is the call graph for this function:
Here is the caller graph for this function:

◆ native_handle()

native_handle_type tbb::recursive_mutex::native_handle ( )
inline

Definition at line 206 of file recursive_mutex.h.

References impl.

206 { return (native_handle_type) &impl; }
pthread_mutex_t * native_handle_type
Return native_handle.
pthread_mutex_t 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 171 of file recursive_mutex.h.

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

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

171  {
172 #if TBB_USE_ASSERT
173  aligned_space<scoped_lock> tmp;
174  return (new(tmp.begin()) scoped_lock)->internal_try_acquire(*this);
175 #else
176  #if _WIN32||_WIN64
177  return TryEnterCriticalSection(&impl)!=0;
178  #else
179  return pthread_mutex_trylock(&impl)==0;
180  #endif /* _WIN32||_WIN64 */
181 #endif /* TBB_USE_ASSERT */
182  }
pthread_mutex_t impl
friend class scoped_lock
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlock()

void tbb::recursive_mutex::unlock ( )
inline

Release lock.

Definition at line 185 of file recursive_mutex.h.

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

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

185  {
186 #if TBB_USE_ASSERT
187  aligned_space<scoped_lock> tmp;
188  scoped_lock& s = *tmp.begin();
189  s.my_mutex = this;
190  s.internal_release();
191 #else
192  #if _WIN32||_WIN64
193  LeaveCriticalSection(&impl);
194  #else
195  pthread_mutex_unlock(&impl);
196  #endif /* _WIN32||_WIN64 */
197 #endif /* TBB_USE_ASSERT */
198  }
void const char const char int ITT_FORMAT __itt_group_sync s
pthread_mutex_t impl
friend class scoped_lock
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 73 of file recursive_mutex.h.

Member Data Documentation

◆ impl

◆ is_fair_mutex

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

Definition at line 149 of file recursive_mutex.h.

◆ is_recursive_mutex

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

Definition at line 148 of file recursive_mutex.h.

◆ is_rw_mutex

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

Definition at line 147 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.