25 #include "machine/windows_api.h" 31 #include "aligned_space.h" 32 #include "tbb_stddef.h" 33 #include "tbb_profiling.h" 40 class mutex : internal::mutex_copy_deprecated_and_disabled {
44 #if TBB_USE_ASSERT || TBB_USE_THREADING_TOOLS 48 InitializeCriticalSectionEx(&impl, 4000, 0);
50 int error_code = pthread_mutex_init(&impl,NULL);
52 tbb::internal::handle_perror(error_code,
"mutex: pthread_mutex_init failed");
62 DeleteCriticalSection(&impl);
64 pthread_mutex_destroy(&impl);
95 internal_acquire(mutex);
105 return internal_try_acquire (mutex);
129 void __TBB_EXPORTED_METHOD internal_acquire(
mutex& m );
132 bool __TBB_EXPORTED_METHOD internal_try_acquire(
mutex& m );
135 void __TBB_EXPORTED_METHOD internal_release();
141 static const bool is_rw_mutex =
false;
142 static const bool is_recursive_mutex =
false;
143 static const bool is_fair_mutex =
false;
154 EnterCriticalSection(&impl);
156 int error_code = pthread_mutex_lock(&impl);
158 tbb::internal::handle_perror(error_code,
"mutex: pthread_mutex_lock failed");
170 return s.internal_try_acquire(*
this);
173 return TryEnterCriticalSection(&impl)!=0;
175 return pthread_mutex_trylock(&impl)==0;
186 s.internal_release();
189 LeaveCriticalSection(&impl);
191 pthread_mutex_unlock(&impl);
202 native_handle_type native_handle() {
return (native_handle_type) &impl; }
211 CRITICAL_SECTION impl;
214 pthread_mutex_t impl;
218 void __TBB_EXPORTED_METHOD internal_construct();
221 void __TBB_EXPORTED_METHOD internal_destroy();
226 void set_state( state_t to ) { state = to; }
230 __TBB_DEFINE_PROFILING_SET_NAME(
mutex)
~scoped_lock()
Release lock (if lock is held).
Definition: mutex.h:87
scoped_lock()
Construct lock that has not acquired a mutex.
Definition: mutex.h:79
pthread_mutex_t * native_handle_type
Return native_handle.
Definition: mutex.h:200
bool try_acquire(mutex &mutex)
Try acquire lock on given mutex.
Definition: mutex.h:103
The scoped locking pattern.
Definition: mutex.h:76
void release()
Release lock.
Definition: mutex.h:115
void acquire(mutex &mutex)
Acquire lock on given mutex.
Definition: mutex.h:93
Block of space aligned sufficiently to construct an array T with N elements.
Definition: aligned_space.h:33
void unlock()
Release lock.
Definition: mutex.h:181
scoped_lock(mutex &mutex)
Acquire lock on given mutex.
Definition: mutex.h:82
mutex()
Construct unacquired mutex.
Definition: mutex.h:43
bool try_lock()
Try acquiring lock (non-blocking)
Definition: mutex.h:165
void lock()
Acquire lock.
Definition: mutex.h:148
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
Wrapper around the platform's native reader-writer lock.
Definition: mutex.h:40