MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / getTaskAndRegister

Method getTaskAndRegister

src/common/task_system/task_scheduler.cpp:179–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177}
178
179std::shared_ptr<ScheduledTask> TaskScheduler::getTaskAndRegister() {
180 if (taskQueue.empty()) {
181 return nullptr;
182 }
183 auto it = taskQueue.begin();
184 while (it != taskQueue.end()) {
185 auto task = (*it)->task;
186 if (!task->registerThread()) {
187 // If we cannot register for a thread it is because of three possibilities:
188 // (i) maximum number of threads have registered for task and the task is completed
189 // without an exception; or (ii) same as (i) but the task has not yet successfully
190 // completed; or (iii) task has an exception; Only in (i) we remove the task from the
191 // queue. For (ii) and (iii) we keep the task in queue. Recall erroring tasks need to be
192 // manually removed.
193 if (task->isCompletedSuccessfully()) { // option (i)
194 it = taskQueue.erase(it);
195 } else { // option (ii) or (iii): keep the task in the queue.
196 ++it;
197 }
198 } else {
199 return *it;
200 }
201 }
202 return nullptr;
203}
204
205void TaskScheduler::removeErroringTask(uint64_t scheduledTaskID) {
206 lock_t lck{taskSchedulerMtx};

Callers

nothing calls this directly

Calls 5

registerThreadMethod · 0.80
eraseMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected