21 #ifndef _TBB_CRITICAL_SECTION_H_ 22 #define _TBB_CRITICAL_SECTION_H_ 25 #include "machine/windows_api.h" 29 #endif // _WIN32||WIN64 31 #include "tbb_stddef.h" 32 #include "tbb_thread.h" 33 #include "tbb_exception.h" 35 #include "tbb_profiling.h" 42 CRITICAL_SECTION my_impl;
44 pthread_mutex_t my_impl;
49 void __TBB_EXPORTED_METHOD internal_construct();
53 InitializeCriticalSectionEx( &my_impl, 4000, 0 );
55 pthread_mutex_init(&my_impl, NULL);
61 __TBB_ASSERT(my_tid ==
tbb_thread::id(),
"Destroying a still-held critical section");
63 DeleteCriticalSection(&my_impl);
65 pthread_mutex_destroy(&my_impl);
84 if(local_tid == my_tid) throw_exception( eid_improper_lock );
86 EnterCriticalSection( &my_impl );
88 int rval = pthread_mutex_lock(&my_impl);
89 __TBB_ASSERT_EX(!rval,
"critical_section::lock: pthread_mutex_lock failed");
98 if(local_tid == my_tid)
return false;
100 gotlock = TryEnterCriticalSection( &my_impl ) != 0;
102 int rval = pthread_mutex_trylock(&my_impl);
104 __TBB_ASSERT(rval == 0 || rval == EBUSY,
"critical_section::trylock: pthread_mutex_trylock failed");
114 __TBB_ASSERT(this_tbb_thread::get_id() == my_tid,
"thread unlocking critical_section is not thread that locked it");
117 LeaveCriticalSection( &my_impl );
119 int rval = pthread_mutex_unlock(&my_impl);
120 __TBB_ASSERT_EX(!rval,
"critical_section::unlock: pthread_mutex_unlock failed");
124 static const bool is_rw_mutex =
false;
125 static const bool is_recursive_mutex =
false;
126 static const bool is_fair_mutex =
true;
131 __TBB_DEFINE_PROFILING_SET_NAME(critical_section)
133 #endif // _TBB_CRITICAL_SECTION_H_ Definition: critical_section.h:40
Definition: _flow_graph_async_msg_impl.h:32
Definition: tbb_thread.h:233
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
Definition: critical_section.h:69