taskschedulertbb.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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__) && !defined(NOMINMAX)
  12. # define NOMINMAX
  13. #endif
  14. // We need to define these to avoid implicit linkage against
  15. // tbb_debug.lib under Windows. When removing these lines debug build
  16. // under Windows fails.
  17. #define __TBB_NO_IMPLICIT_LINKAGE 1
  18. #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
  19. #define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
  20. #define TBB_PREVIEW_ISOLATED_TASK_GROUP 1
  21. #include "tbb/tbb.h"
  22. #include "tbb/parallel_sort.h"
  23. namespace embree
  24. {
  25. struct TaskScheduler
  26. {
  27. /*! initializes the task scheduler */
  28. static void create(size_t numThreads, bool set_affinity, bool start_threads);
  29. /*! destroys the task scheduler again */
  30. static void destroy();
  31. /* returns the ID of the current thread */
  32. static __forceinline size_t threadID()
  33. {
  34. return threadIndex();
  35. }
  36. /* returns the index (0..threadCount-1) of the current thread */
  37. static __forceinline size_t threadIndex()
  38. {
  39. #if TBB_INTERFACE_VERSION >= 9100
  40. return tbb::this_task_arena::current_thread_index();
  41. #elif TBB_INTERFACE_VERSION >= 9000
  42. return tbb::task_arena::current_thread_index();
  43. #else
  44. return 0;
  45. #endif
  46. }
  47. /* returns the total number of threads */
  48. static __forceinline size_t threadCount() {
  49. #if TBB_INTERFACE_VERSION >= 9100
  50. return tbb::this_task_arena::max_concurrency();
  51. #else
  52. return tbb::task_scheduler_init::default_num_threads();
  53. #endif
  54. }
  55. };
  56. };