Debian Codegraph @

rkcommon/tasking/detail/TaskSys.h

raw
1 // Copyright 2009 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5
6 #include "../../common.h"
7 // enkiTS
8 #include "enkiTS/TaskScheduler.h"
9
10 namespace rkcommon {
11 namespace tasking {
12 namespace detail {
13
14 // Public interface to the tasking system ///////////////////////////////
15
16 using Task = enki::ITaskSet;
17
18 void initTaskSystemInternal(int numThreads = -1);
19 void shutdownTaskSystemInternal();
20 int numThreadsTaskSystemInternal();
21
22 void RKCOMMON_INTERFACE scheduleTaskInternal(Task *task);
23 void RKCOMMON_INTERFACE waitInternal(Task *task);
24
25 template <typename TASK_T>
26 inline void parallel_for_internal(int nTasks, TASK_T &&fcn)
27 {
28 struct LocalTask : public Task
29 {
30 const TASK_T &t;
31 LocalTask(int nunTasks, TASK_T &&fcn)
32
33 : Task(nunTasks), t(std::forward<TASK_T>(fcn))
34 {
35 }
36
37 ~LocalTask() override = default;
38
39 void ExecuteRange(enki::TaskSetPartition tp, uint32_t) override
40 {
41 for (auto i = tp.start; i < tp.end; ++i)
42 t(i);
43 }
44 };
45
46 LocalTask task(nTasks, std::forward<TASK_T>(fcn));
47 scheduleTaskInternal(&task);
48 waitInternal(&task);
49 }
50 } // namespace detail
51 } // namespace tasking
52 } // namespace rkcommon