本文整理汇总了C++中Task::callback方法的典型用法代码示例。如果您正苦于以下问题:C++ Task::callback方法的具体用法?C++ Task::callback怎么用?C++ Task::callback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task::callback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sandbox_stop_callback
/*!
Handle sandbox stop event. It will call the corresponding task stop callback,
and remove the task from task_map.
@param id Task ID.
*/
static void sandbox_stop_callback(uint64_t id) {
auto task_it = task_map.find(id);
assert(task_it != task_map.end());
Task task = task_it->second;
assert(task.callback != NULL);
task.callback(id, task.sdbx->stat, task.data);
task_map.erase(task_it);
INFO("Task %lu finished.\n", id);
}
示例2: taskmgr_thread
static int taskmgr_thread(void *arg) {
TaskManager *mgr = arg;
attr_unused SDL_threadID tid = SDL_ThreadID();
if(SDL_SetThreadPriority(mgr->thread_prio) < 0) {
log_sdl_error(LOG_WARN, "SDL_SetThreadPriority");
}
bool running;
bool aborted;
do {
SDL_LockMutex(mgr->mutex);
running = mgr->running;
aborted = mgr->aborted;
if(!running && !aborted) {
SDL_CondWait(mgr->cond, mgr->mutex);
}
SDL_UnlockMutex(mgr->mutex);
} while(!running && !aborted);
while(running && !aborted) {
SDL_LockMutex(mgr->mutex);
Task *task = alist_pop(&mgr->queue);
running = mgr->running;
aborted = mgr->aborted;
if(running && task == NULL && !aborted) {
SDL_CondWait(mgr->cond, mgr->mutex);
}
SDL_UnlockMutex(mgr->mutex);
if(task != NULL) {
SDL_LockMutex(task->mutex);
bool task_disowned = task->disowned;
if(aborted && task->status == TASK_PENDING) {
task->status = TASK_CANCELLED;
}
if(task->status == TASK_PENDING) {
task->status = TASK_RUNNING;
SDL_UnlockMutex(task->mutex);
task->result = task->callback(task->userdata);
SDL_LockMutex(task->mutex);
assert(task->in_queue);
task->in_queue = false;
(void)SDL_AtomicDecRef(&mgr->numtasks);
if((task_disowned = task->disowned)) {
SDL_UnlockMutex(task->mutex);
task_free(task);
} else {
task->status = TASK_FINISHED;
SDL_CondBroadcast(task->cond);
SDL_UnlockMutex(task->mutex);
}
} else if(task->status == TASK_CANCELLED) {
assert(task->in_queue);
task->in_queue = false;
(void)SDL_AtomicDecRef(&mgr->numtasks);
SDL_UnlockMutex(task->mutex);
if(task_disowned) {
task_free(task);
}
} else {
UNREACHABLE;
}
}
}
return 0;
}