taskschedulerppl.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "taskschedulerppl.h"
  17. namespace embree
  18. {
  19. static bool g_ppl_threads_initialized = false;
  20. void TaskScheduler::create(size_t numThreads, bool set_affinity, bool start_threads)
  21. {
  22. assert(numThreads);
  23. /* first terminate threads in case we configured them */
  24. if (g_ppl_threads_initialized) {
  25. g_ppl_threads_initialized = false;
  26. }
  27. /* now either keep default settings or configure number of threads */
  28. if (numThreads == std::numeric_limits<size_t>::max())
  29. {
  30. g_ppl_threads_initialized = false;
  31. numThreads = threadCount();
  32. }
  33. else
  34. {
  35. g_ppl_threads_initialized = true;
  36. try {
  37. concurrency::Scheduler::SetDefaultSchedulerPolicy(concurrency::SchedulerPolicy(2, concurrency::MinConcurrency, numThreads, concurrency::MaxConcurrency, numThreads));
  38. }
  39. catch(concurrency::default_scheduler_exists &) {
  40. }
  41. }
  42. }
  43. void TaskScheduler::destroy()
  44. {
  45. if (g_ppl_threads_initialized) {
  46. g_ppl_threads_initialized = false;
  47. }
  48. }
  49. }