taskschedulertbb.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "../sys/platform.h"
  18. #include "../sys/alloc.h"
  19. #include "../sys/barrier.h"
  20. #include "../sys/thread.h"
  21. #include "../sys/mutex.h"
  22. #include "../sys/condition.h"
  23. #include "../sys/ref.h"
  24. #if defined(__WIN32__)
  25. # define NOMINMAX
  26. #endif
  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 index of the current thread */
  38. static __forceinline size_t threadIndex()
  39. {
  40. #if TBB_INTERFACE_VERSION >= 9100
  41. return tbb::this_task_arena::current_thread_index();
  42. #elif TBB_INTERFACE_VERSION >= 9000
  43. return tbb::task_arena::current_thread_index();
  44. #else
  45. return 0;
  46. #endif
  47. }
  48. /* returns the total number of threads */
  49. static __forceinline size_t threadCount() {
  50. #if TBB_INTERFACE_VERSION >= 9100
  51. return tbb::this_task_arena::max_concurrency();
  52. #else
  53. return tbb::task_scheduler_init::default_num_threads();
  54. #endif
  55. }
  56. };
  57. };