21 #ifndef __TBB_recursive_mutex_H 22 #define __TBB_recursive_mutex_H 25 #include "machine/windows_api.h" 31 #include "aligned_space.h" 32 #include "tbb_stddef.h" 33 #include "tbb_profiling.h" 43 #if TBB_USE_ASSERT || TBB_USE_THREADING_TOOLS 47 InitializeCriticalSectionEx(&impl, 4000, 0);
49 pthread_mutexattr_t mtx_attr;
50 int error_code = pthread_mutexattr_init( &mtx_attr );
52 tbb::internal::handle_perror(error_code,
"recursive_mutex: pthread_mutexattr_init failed");
54 pthread_mutexattr_settype( &mtx_attr, PTHREAD_MUTEX_RECURSIVE );
55 error_code = pthread_mutex_init( &impl, &mtx_attr );
57 tbb::internal::handle_perror(error_code,
"recursive_mutex: pthread_mutex_init failed");
59 pthread_mutexattr_destroy( &mtx_attr );
69 DeleteCriticalSection(&impl);
71 pthread_mutex_destroy(&impl);
105 internal_acquire( mutex );
115 return internal_try_acquire( mutex );
145 void __TBB_EXPORTED_METHOD internal_release();
151 static const bool is_rw_mutex =
false;
152 static const bool is_recursive_mutex =
true;
153 static const bool is_fair_mutex =
false;
164 EnterCriticalSection(&impl);
166 int error_code = pthread_mutex_lock(&impl);
168 tbb::internal::handle_perror(error_code,
"recursive_mutex: pthread_mutex_lock failed");
181 return TryEnterCriticalSection(&impl)!=0;
183 return pthread_mutex_trylock(&impl)==0;
194 s.internal_release();
197 LeaveCriticalSection(&impl);
199 pthread_mutex_unlock(&impl);
210 native_handle_type native_handle() {
return (native_handle_type) &impl; }
214 CRITICAL_SECTION impl;
220 pthread_mutex_t impl;
224 void __TBB_EXPORTED_METHOD internal_construct();
227 void __TBB_EXPORTED_METHOD internal_destroy();
pthread_mutex_t * native_handle_type
Return native_handle.
Definition: recursive_mutex.h:208
void unlock()
Release lock.
Definition: recursive_mutex.h:189
recursive_mutex()
Construct unacquired recursive_mutex.
Definition: recursive_mutex.h:42
Block of space aligned sufficiently to construct an array T with N elements.
Definition: aligned_space.h:33
void acquire(recursive_mutex &mutex)
Acquire lock on given mutex.
Definition: recursive_mutex.h:103
scoped_lock()
Construct lock that has not acquired a recursive_mutex.
Definition: recursive_mutex.h:86
Mutex that allows recursive mutex acquisition.
Definition: recursive_mutex.h:39
scoped_lock(recursive_mutex &mutex)
Acquire lock on given mutex.
Definition: recursive_mutex.h:89
T * begin()
Pointer to beginning of array.
Definition: aligned_space.h:39
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
bool try_acquire(recursive_mutex &mutex)
Try acquire lock on given recursive_mutex.
Definition: recursive_mutex.h:113
The scoped locking pattern.
Definition: recursive_mutex.h:83
~scoped_lock()
Release lock (if lock is held).
Definition: recursive_mutex.h:97
Wrapper around the platform's native reader-writer lock.
Definition: mutex.h:40
bool try_lock()
Try acquiring lock (non-blocking)
Definition: recursive_mutex.h:175
void release()
Release lock.
Definition: recursive_mutex.h:125
void lock()
Acquire lock.
Definition: recursive_mutex.h:158