taskschedulertbb.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "../sys/platform.h"
  5. #include "../sys/alloc.h"
  6. #include "../sys/barrier.h"
  7. #include "../sys/thread.h"
  8. #include "../sys/mutex.h"
  9. #include "../sys/condition.h"
  10. #include "../sys/ref.h"
  11. #if defined(__WIN32__)
  12. // -- GODOT start --
  13. #if !defined(NOMINMAX)
  14. // -- GODOT end --
  15. # define NOMINMAX
  16. // -- GODOT start --
  17. #endif
  18. // -- GODOT end --
  19. #endif
  20. // We need to define these to avoid implicit linkage against
  21. // tbb_debug.lib under Windows. When removing these lines debug build
  22. // under Windows fails.
  23. #define __TBB_NO_IMPLICIT_LINKAGE 1
  24. #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
  25. #define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
  26. #define TBB_PREVIEW_ISOLATED_TASK_GROUP 1
  27. #include "tbb/tbb.h"
  28. #include "tbb/parallel_sort.h"
  29. namespace embree
  30. {
  31. struct TaskScheduler
  32. {
  33. /*! initializes the task scheduler */
  34. static void create(size_t numThreads, bool set_affinity, bool start_threads);
  35. /*! destroys the task scheduler again */
  36. static void destroy();
  37. /* returns the ID of the current thread */
  38. static __forceinline size_t threadID()
  39. {
  40. return threadIndex();
  41. }
  42. /* returns the index (0..threadCount-1) of the current thread */
  43. static __forceinline size_t threadIndex()
  44. {
  45. #if TBB_INTERFACE_VERSION >= 9100
  46. return tbb::this_task_arena::current_thread_index();
  47. #elif TBB_INTERFACE_VERSION >= 9000
  48. return tbb::task_arena::current_thread_index();
  49. #else
  50. return 0;
  51. #endif
  52. }
  53. /* returns the total number of threads */
  54. static __forceinline size_t threadCount() {
  55. #if TBB_INTERFACE_VERSION >= 9100
  56. return tbb::this_task_arena::max_concurrency();
  57. #else
  58. return tbb::task_scheduler_init::default_num_threads();
  59. #endif
  60. }
  61. };
  62. };