Repository navigation
Expand file tree
/
Copy pathtask.cpp
More file actions
99 lines (92 loc) · 2.12 KB
/
Copy pathtask.cpp
File metadata and controls
99 lines (92 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "SkrTask/fib_task.hpp"
#include "SkrBase/misc/debug.h"
namespace skr::task
{
#if !defined(SKR_TASK_MARL)
scheudler_config_t::scheudler_config_t()
{
numThreads = ftl::GetNumHardwareThreads();
}
counter_t::counter_t(bool inverse)
{
internal = skr::make_shared<ftl::TaskCounter>(nullptr, inverse);
}
event_t::event_t()
{
internal = skr::make_shared<ftl::TaskCounter>(nullptr);
internal->Add(1);
}
thread_local scheduler_t* scheduler = nullptr;
void scheduler_t::initialize(const scheudler_config_t& config)
{
options.ThreadPoolSize = config.numThreads;
}
void scheduler_t::bind()
{
SKR_ASSERT(scheduler == nullptr);
SKR_ASSERT(internal == nullptr);
internal = new ftl::TaskScheduler();
options.Callbacks.Context = this;
options.Callbacks.OnWorkerThreadStarted = [](void* context, unsigned threadIndex)
{
scheduler = (scheduler_t*)context;
ftl::BindScheduler(scheduler->internal);
};
options.Callbacks.OnWorkerThreadEnded = [](void* context, unsigned threadIndex)
{
scheduler = nullptr;
ftl::UnbindScheduler();
};
internal->Init(options);
scheduler = this;
ftl::BindScheduler(internal);
}
void scheduler_t::unbind()
{
SKR_ASSERT(internal);
SKR_ASSERT(scheduler == this);
scheduler = nullptr;
delete internal;
internal = nullptr;
ftl::UnbindScheduler();
}
scheduler_t* details::get_scheduler()
{
SKR_ASSERT(scheduler != nullptr);
return scheduler;
}
scheduler_t::~scheduler_t()
{
if(internal)
delete internal;
}
void* scheduler_t::current_fiber()
{
return internal->GetCurrentFiber();
}
void* current_fiber()
{
return details::get_scheduler()->current_fiber();
}
#else
void scheduler_t::initialize(const scheudler_config_t& config)
{
marl::Scheduler::Config cfg;
cfg.workerThread.count = config.numThreads;
if (!cfg.workerThread.count)
{
cfg.allCores();
}
internal = new marl::Scheduler(cfg);
}
scheudler_config_t::scheudler_config_t()
{
numThreads = marl::Thread::numLogicalCPUs();
}
scheduler_t::~scheduler_t()
{
if(internal)
delete internal;
}
#endif
}