fixed the task executor
This commit is contained in:
parent
539d94e724
commit
dd8ea1c8d9
@ -316,38 +316,47 @@ void task_executor::executor(std::shared_ptr<executor_context> executor_context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto execute_timestamp = system_clock::now();
|
auto execute_timestamp = system_clock::now();
|
||||||
if(task_context->task_recurring_head && task_context->task_recurring_head->scheduled_invoke <= execute_timestamp) {
|
std::chrono::system_clock::time_point next_timestamp{};
|
||||||
auto task = task_context->task_recurring_head;
|
if(task_context->task_recurring_head) {
|
||||||
task_context->task_recurring_head = task->next;
|
if(task_context->task_recurring_head->scheduled_invoke <= execute_timestamp) {
|
||||||
|
auto task = task_context->task_recurring_head;
|
||||||
|
task_context->task_recurring_head = task->next;
|
||||||
|
|
||||||
executor_context->executing_recurring_task = task;
|
executor_context->executing_recurring_task = task;
|
||||||
task_lock.unlock();
|
|
||||||
|
|
||||||
try {
|
|
||||||
task->callback(task->last_invoked);
|
|
||||||
} catch (...) {
|
|
||||||
auto exception = std::current_exception();
|
|
||||||
|
|
||||||
task_lock.lock();
|
|
||||||
auto handler = task_context->exception_handler;
|
|
||||||
task_lock.unlock();
|
task_lock.unlock();
|
||||||
|
|
||||||
handler(task->name, exception);
|
try {
|
||||||
}
|
task->callback(task->last_invoked);
|
||||||
|
} catch (...) {
|
||||||
|
auto exception = std::current_exception();
|
||||||
|
|
||||||
task->last_invoked = execute_timestamp;
|
task_lock.lock();
|
||||||
task->scheduled_invoke = std::min(system_clock::now(), execute_timestamp + task->interval);
|
auto handler = task_context->exception_handler;
|
||||||
|
task_lock.unlock();
|
||||||
|
|
||||||
task_lock.lock();
|
handler(task->name, exception);
|
||||||
executor_context->executing_recurring_task = nullptr;
|
}
|
||||||
if(task->shutdown) {
|
|
||||||
delete task;
|
task->last_invoked = execute_timestamp;
|
||||||
|
task->scheduled_invoke = std::max(system_clock::now(), execute_timestamp + task->interval);
|
||||||
|
|
||||||
|
task_lock.lock();
|
||||||
|
executor_context->executing_recurring_task = nullptr;
|
||||||
|
if(task->shutdown) {
|
||||||
|
delete task;
|
||||||
|
} else {
|
||||||
|
executor_context->handle->enqueue_recurring_task(task);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
executor_context->handle->enqueue_recurring_task(task);
|
next_timestamp = task_context->task_recurring_head->scheduled_invoke;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task_context->notify.wait(task_lock);
|
if(next_timestamp.time_since_epoch().count() > 0) {
|
||||||
|
task_context->notify.wait_until(task_lock, next_timestamp);
|
||||||
|
} else {
|
||||||
|
task_context->notify.wait(task_lock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user