当前位置: 首页>>代码示例>>C++>>正文


C++ Task::callback方法代码示例

本文整理汇总了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);
}
开发者ID:ShikChen,项目名称:judge,代码行数:20,代码来源:core.cpp

示例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;
}
开发者ID:laochailan,项目名称:taisei,代码行数:82,代码来源:taskmanager.c


注:本文中的Task::callback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。