MCPcopy Create free account
hub / github.com/MCJack123/craftos2 / queueTask

Function queueTask

src/runtime.cpp:70–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70void* queueTask(const std::function<void*(void*)>& func, void* arg, bool async) {
71 if (std::this_thread::get_id() == mainThreadID && (!async || taskQueue.locked())) return func(arg);
72 TaskQueueItem * task = new TaskQueueItem;
73 task->func = func;
74 task->data = arg;
75 task->async = async;
76 {
77 std::unique_lock<std::mutex> lock(taskQueue.getMutex());
78 taskQueue->push(task);
79 if (selectedRenderer == 0 || selectedRenderer == 5) {
80 SDL_Event e;
81 e.type = task_event_type;
82 SDL_PushEvent(&e);
83 }
84 taskQueueReady = true;
85 taskQueueNotify.notify_all();
86 }
87 if (async) return NULL;
88 {
89 std::unique_lock<std::mutex> lock(task->lock);
90 while (!task->ready) task->notify.wait(lock);
91 if (task->exception != nullptr) {
92 std::exception_ptr e = task->exception;
93 delete task;
94 std::rethrow_exception(e);
95 }
96 arg = task->data;
97 }
98 delete task;
99 return arg;
100}
101
102void awaitTasks(const std::function<bool()>& predicate = []()->bool{return true;}) {
103 while (predicate()) {

Callers 15

runComputerFunction · 0.85
Computer.cppFile · 0.85
eventTimeoutEventFunction · 0.85
getNextEventFunction · 0.85
addMountFunction · 0.85
setListenerModeFunction · 0.85
termPanicFunction · 0.85
debuggerBreakFunction · 0.85
termHookFunction · 0.85
releaseNotesThreadFunction · 0.85
update_threadFunction · 0.85
runRendererFunction · 0.85

Calls 1

lockedMethod · 0.80

Tested by

no test coverage detected