HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Threading.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
4 /// @file Threading.h
5 
6 #ifndef OPENVDB_THREAD_THREADING_HAS_BEEN_INCLUDED
7 #define OPENVDB_THREAD_THREADING_HAS_BEEN_INCLUDED
8 
9 #include <openvdb/version.h>
10 
11 #ifndef __TBB_show_deprecation_message_task_H
12  #define __TBB_show_deprecation_message_task_H
13  #define OPENVDB_THREAD_THREADING_RESTORE_DEPRECATION_MESSAGE_TASK
14 #endif
15 
16 
17 /// @note tbb/blocked_range.h is the ONLY include that persists from TBB 2020
18 /// to TBB 2021 that itself includes the TBB specific version header files.
19 /// In TBB 2020, the version header was called tbb/stddef.h. In 2021, it's
20 /// called tbb/version.h. We include tbb/blocked_range.h here to indirectly
21 /// access the version defines in a consistent way so that downstream
22 /// software doesn't need to provide compile time defines.
23 #include <tbb/blocked_range.h>
24 #include <tbb/task.h>
25 #include <tbb/task_group.h>
26 
27 namespace openvdb {
29 namespace OPENVDB_VERSION_NAME {
30 namespace thread {
31 
32 /// @note This UBSAN suppression may not be needed when we transition to TBB21
33 inline OPENVDB_UBSAN_SUPPRESS("vptr") bool cancelGroupExecution()
34 {
35  // @note 12000 was the 2021.1-beta05 release. The 2021.1-beta08 release
36  // introduced current_context().
37 #if TBB_INTERFACE_VERSION >= 12002
38  auto ctx = tbb::task::current_context();
39  return ctx ? ctx->cancel_group_execution() : false;
40 #else
41  return tbb::task::self().cancel_group_execution();
42 #endif
43 }
44 
45 /// @note This UBSAN suppression may not be needed when we transition to TBB21
46 inline OPENVDB_UBSAN_SUPPRESS("vptr") bool isGroupExecutionCancelled()
47 {
48  // @note 12000 was the 2021.1-beta05 release. The 2021.1-beta08 release
49  // introduced current_context().
50 #if TBB_INTERFACE_VERSION >= 12002
51  auto ctx = tbb::task::current_context();
52  return ctx ? ctx->is_group_execution_cancelled() : false;
53 #else
54  return tbb::task::self().is_cancelled();
55 #endif
56 }
57 
58 } // namespace thread
59 } // namespace OPENVDB_VERSION_NAME
60 } // namespace openvdb
61 
62 #ifdef OPENVDB_THREAD_THREADING_RESTORE_DEPRECATION_MESSAGE_TASK
63  #undef __TBB_show_deprecation_message_task_H
64  #undef OPENVDB_THREAD_THREADING_RESTORE_DEPRECATION_MESSAGE_TASK
65 #endif
66 
67 
68 #endif // OPENVDB_THREAD_THREADING_HAS_BEEN_INCLUDED
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:239
OPENVDB_UBSAN_SUPPRESS("vptr") bool cancelGroupExecution()
Definition: Threading.h:33
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
Library and file format version numbers.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:119