MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / runInMainSync

Method runInMainSync

Source/Common/Async.cpp:99–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99void Async::runInMainSync(const std::function<void()>& worker) {
100 if (_stopped.load(std::memory_order_acquire)) {
101 return;
102 }
103 AssertUnless(SharedApplication.getLogicThread() == std::this_thread::get_id(), "Async runner should be invoked from logic thread");
104 std::list<std::variant<WorkPtr, WorkDonePtr>> jobs;
105 for (auto event = _workerEvent.poll();
106 event != nullptr;
107 event = _workerEvent.poll()) {
108 switch (Switch::hash(event->getName())) {
109 case "Work"_hash: {
110 Own<std::function<void()>> worker;
111 event->get(worker);
112 jobs.push_back(std::move(worker));
113 break;
114 }
115 case "WorkDone"_hash: {
116 Own<WorkDone> workDone;
117 event->get(workDone);
118 jobs.push_back(std::move(workDone));
119 break;
120 }
121 }
122 }
123 run([&]() {
124 worker();
125 _mainThreadSemaphore.post();
126 });
127 if (_stopped.load(std::memory_order_acquire)) {
128 return;
129 }
130 _mainThreadSemaphore.wait();
131 for (auto& job : jobs) {
132 if (std::holds_alternative<WorkPtr>(job)) {
133 _workerEvent.post("Work"_slice, std::move(std::get<WorkPtr>(job)));
134 } else {
135 _workerEvent.post("WorkDone"_slice, std::move(std::get<WorkDonePtr>(job)));
136 }
137 }
138 notifyWorker();
139}
140
141int Async::work(bx::Thread* thread, void* userData) {
142 DORA_UNUSED_PARAM(thread);

Callers 14

copyMethod · 0.80
loadInMainUnsafeMethod · 0.80
existDBMethod · 0.80
existMethod · 0.80
execMethod · 0.80
insertMethod · 0.80
transactionMethod · 0.80
queryMethod · 0.80
getTealVersionMethod · 0.80
compileTealToLuaMethod · 0.80
clearTealCompilerMethod · 0.80
loadMethod · 0.80

Calls 12

moveFunction · 0.85
workerFunction · 0.85
getLogicThreadMethod · 0.80
hashFunction · 0.70
loadMethod · 0.65
getNameMethod · 0.65
getMethod · 0.65
postMethod · 0.65
runFunction · 0.50
pollMethod · 0.45
push_backMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected