21 #ifndef __TBB_tbb_thread_H 22 #define __TBB_tbb_thread_H 24 #include "tbb_stddef.h" 27 #include "machine/windows_api.h" 28 #define __TBB_NATIVE_THREAD_ROUTINE unsigned WINAPI 29 #define __TBB_NATIVE_THREAD_ROUTINE_PTR(r) unsigned (WINAPI* r)( void* ) 31 #if __TBB_WIN8UI_SUPPORT 32 typedef size_t thread_id_type;
33 #else // __TBB_WIN8UI_SUPPORT 34 typedef DWORD thread_id_type;
35 #endif // __TBB_WIN8UI_SUPPORT 38 #define __TBB_NATIVE_THREAD_ROUTINE void* 39 #define __TBB_NATIVE_THREAD_ROUTINE_PTR(r) void* (*r)( void* ) 42 typedef pthread_t thread_id_type;
44 #endif // _WIN32||_WIN64 47 #include "internal/_tbb_hash_compare_impl.h" 48 #include "tick_count.h" 50 #if !TBB_USE_EXCEPTIONS && _MSC_VER 52 #pragma warning (push) 53 #pragma warning (disable: 4530) 59 #if !TBB_USE_EXCEPTIONS && _MSC_VER 69 inline void swap( internal::tbb_thread_v3& t1, internal::tbb_thread_v3& t2 ) __TBB_NOEXCEPT(
true);
74 void* __TBB_EXPORTED_FUNC allocate_closure_v3(
size_t size );
76 void __TBB_EXPORTED_FUNC free_closure_v3(
void* );
79 void*
operator new(
size_t size ) {
return allocate_closure_v3(size);}
80 void operator delete(
void* ptr ) {free_closure_v3(ptr);}
86 static __TBB_NATIVE_THREAD_ROUTINE start_routine(
void* c ) {
101 self->function(self->arg1);
114 self->function(self->arg1, self->arg2);
118 thread_closure_2(
const F& f,
const X& x,
const Y& y ) :
function(f), arg1(x), arg2(y) {}
123 #if __TBB_IF_NO_COPY_CTOR_MOVE_SEMANTICS_BROKEN 132 typedef HANDLE native_handle_type;
134 typedef pthread_t native_handle_type;
135 #endif // _WIN32||_WIN64 142 #endif // _WIN32||_WIN64 148 internal_start(closure_type::start_routine,
new closure_type(f));
153 internal_start(closure_type::start_routine,
new closure_type(f,x));
158 internal_start(closure_type::start_routine,
new closure_type(f,x,y));
161 #if __TBB_CPP11_RVALUE_REF_PRESENT 163 : my_handle(x.my_handle)
165 , my_thread_id(x.my_thread_id)
177 #else // __TBB_CPP11_RVALUE_REF_PRESENT 182 #endif // __TBB_CPP11_RVALUE_REF_PRESENT 184 void swap(
tbb_thread_v3& t ) __TBB_NOEXCEPT(
true) {tbb::swap( *
this, t );}
185 bool joinable()
const __TBB_NOEXCEPT(
true) {
return my_handle!=0; }
187 void __TBB_EXPORTED_METHOD join();
189 void __TBB_EXPORTED_METHOD detach();
191 inline id get_id()
const __TBB_NOEXCEPT(
true);
192 native_handle_type native_handle() {
return my_handle; }
204 static unsigned __TBB_EXPORTED_FUNC hardware_concurrency() __TBB_NOEXCEPT(
true);
206 native_handle_type my_handle;
208 thread_id_type my_thread_id;
209 #endif // _WIN32||_WIN64 211 void internal_wipe() __TBB_NOEXCEPT(
true) {
218 if (joinable()) detach();
219 my_handle = x.my_handle;
221 my_thread_id = x.my_thread_id;
222 #endif // _WIN32||_WIN64 227 void __TBB_EXPORTED_METHOD internal_start( __TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine),
234 thread_id_type my_id;
235 id( thread_id_type id_ ) : my_id(id_) {}
239 id() __TBB_NOEXCEPT(
true) : my_id(0) {}
248 template<
class charT,
class traits>
249 friend std::basic_ostream<charT, traits>&
250 operator<< (std::basic_ostream<charT, traits> &out,
259 __TBB_STATIC_ASSERT(
sizeof(
id.my_id) <=
sizeof(
size_t),
"Implementaion assumes that thread_id_type fits into machine word");
260 return tbb::tbb_hasher(
id.my_id);
264 friend id atomic_compare_and_swap(
id& location,
const id& value,
const id& comparand){
265 return as_atomic(location.my_id).compare_and_swap(value.my_id, comparand.my_id);
271 return id(my_thread_id);
273 return id(my_handle);
274 #endif // _WIN32||_WIN64 279 void __TBB_EXPORTED_FUNC thread_yield_v3();
284 return x.my_id == y.my_id;
288 return x.my_id != y.my_id;
292 return x.my_id < y.my_id;
296 return x.my_id <= y.my_id;
300 return x.my_id > y.my_id;
304 return x.my_id >= y.my_id;
312 using internal::operator==;
313 using internal::operator!=;
314 using internal::operator<;
315 using internal::operator>;
316 using internal::operator<=;
317 using internal::operator>=;
319 inline void move( tbb_thread& t1, tbb_thread& t2 ) {
320 internal::move_v3(t1, t2);
324 std::swap(t1.my_handle, t2.my_handle);
326 std::swap(t1.my_thread_id, t2.my_thread_id);
330 namespace this_tbb_thread {
331 inline tbb_thread::id get_id() {
return internal::thread_get_id_v3(); }
333 inline void yield() { internal::thread_yield_v3(); }
336 internal::thread_sleep_v3(i);
tbb_thread_v3(F f)
Constructs an object and executes f() in a new thread.
Definition: tbb_thread.h:146
tbb_thread_v3(F f, X x, Y y)
Constructs an object and executes f(x,y) in a new thread.
Definition: tbb_thread.h:156
Versioned thread class.
Definition: tbb_thread.h:122
Definition: tbb_thread.h:83
static __TBB_NATIVE_THREAD_ROUTINE start_routine(void *c)
Routine passed to Windows's _beginthreadex by thread::internal_start() inside tbb.dll.
Definition: tbb_thread.h:99
tbb_thread_v3() __TBB_NOEXCEPT(true)
Constructs a thread object that does not represent a thread of execution.
Definition: tbb_thread.h:139
Definition: tbb_thread.h:78
static __TBB_NATIVE_THREAD_ROUTINE start_routine(void *c)
Routine passed to Windows's _beginthreadex by thread::internal_start() inside tbb.dll.
Definition: tbb_thread.h:112
tbb_thread_v3(F f, X x)
Constructs an object and executes f(x) in a new thread.
Definition: tbb_thread.h:151
Structure used to pass user function with 1 argument to thread.
Definition: tbb_thread.h:95
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
Relative time interval.
Definition: tick_count.h:41
Definition: tbb_thread.h:107
internal::tbb_thread_v3 tbb_thread
Users reference thread class by name tbb_thread.
Definition: tbb_thread.h:310