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


C++ Dispatcher::addTask方法代码示例

本文整理汇总了C++中Dispatcher::addTask方法的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher::addTask方法的具体用法?C++ Dispatcher::addTask怎么用?C++ Dispatcher::addTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dispatcher的用法示例。


在下文中一共展示了Dispatcher::addTask方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[])
{
	// Setup bad allocation handler
	std::set_new_handler(badAllocationHandler);

#ifndef _WIN32
	// ignore sigpipe...
	struct sigaction sigh;
	sigh.sa_handler = SIG_IGN;
	sigh.sa_flags = 0;
	sigemptyset(&sigh.sa_mask);
	sigaction(SIGPIPE, &sigh, nullptr);
#endif

	ServiceManager servicer;

	g_dispatcher.start();
	g_scheduler.start();

	g_dispatcher.addTask(createTask(std::bind(mainLoader, argc, argv, &servicer)));

	g_loaderSignal.wait(g_loaderUniqueLock);

	if (servicer.is_running()) {
		std::cout << ">> " << g_config.getString(ConfigManager::SERVER_NAME) << " Server Online!" << std::endl << std::endl;
#ifdef _WIN32
		SetConsoleCtrlHandler([](DWORD) -> BOOL {
			g_dispatcher.addTask(createTask([]() {
				g_dispatcher.addTask(createTask(
					std::bind(&Game::shutdown, &g_game)
				));
				g_scheduler.stop();
				g_databaseTasks.stop();
				g_dispatcher.stop();
			}));
			ExitThread(0);
		}, 1);
#endif
		servicer.run();
		g_scheduler.join();
		g_databaseTasks.join();
		g_dispatcher.join();
	} else {
		std::cout << ">> No services running. The server is NOT online." << std::endl;
		g_dispatcher.addTask(createTask([]() {
			g_dispatcher.addTask(createTask([]() {
				g_scheduler.shutdown();
				g_databaseTasks.shutdown();
				g_dispatcher.shutdown();
			}));
			g_scheduler.stop();
			g_databaseTasks.stop();
			g_dispatcher.stop();
		}));
		g_scheduler.join();
		g_databaseTasks.join();
		g_dispatcher.join();
	}
	return 0;
}
开发者ID:Testerus,项目名称:forgottenserver,代码行数:60,代码来源:otserv.cpp

示例2: dispatchSignalHandler

void Signals::dispatchSignalHandler(int signal)
{
	switch(signal) {
		case SIGINT: //Shuts the server down
			g_dispatcher.addTask(createTask(sigintHandler));
			break;
		case SIGTERM: //Shuts the server down
			g_dispatcher.addTask(createTask(sigtermHandler));
			break;
#ifndef _WIN32
		case SIGHUP: //Reload config/data
			g_dispatcher.addTask(createTask(sighupHandler));
			break;
		case SIGUSR1: //Saves game state
			g_dispatcher.addTask(createTask(sigusr1Handler));
			break;
#endif
		default:
			break;
	}
}
开发者ID:Alissonfgp,项目名称:forgottenserver,代码行数:21,代码来源:signals.cpp

示例3: main

int main(int argc, char* argv[])
{
    // Setup bad allocation handler
    std::set_new_handler(badAllocationHandler);

#ifndef WIN32
    // ignore sigpipe...
    struct sigaction sigh;
    sigh.sa_handler = SIG_IGN;
    sigh.sa_flags = 0;
    sigemptyset(&sigh.sa_mask);
    sigaction(SIGPIPE, &sigh, NULL);
#endif

    ServiceManager servicer;

    g_dispatcher.start();
    g_scheduler.start();

    g_dispatcher.addTask(createTask(boost::bind(mainLoader, argc, argv, &servicer)));

    g_loaderSignal.wait(g_loaderUniqueLock);

    if (servicer.is_running()) {
        std::cout << ">> " << g_config.getString(ConfigManager::SERVER_NAME) << " Server Online!" << std::endl << std::endl;
        servicer.run();
        g_scheduler.join();
        g_dispatcher.join();
    } else {
        std::cout << ">> No services running. The server is NOT online." << std::endl;
        g_scheduler.stop();
        g_dispatcher.stop();
        g_dispatcher.addTask(createTask(boost::bind(shutdown)));
        g_scheduler.join();
        g_dispatcher.join();
    }
    return 0;
}
开发者ID:nclx,项目名称:forgottenserver,代码行数:38,代码来源:otserv.cpp

示例4: runTask

void DatabaseTasks::runTask(const DatabaseTask& task)
{
	bool success;
	DBResult_ptr result;
	if (task.store) {
		result = db.storeQuery(task.query);
		success = true;
	} else {
		result = nullptr;
		success = db.executeQuery(task.query);
	}

	if (task.callback) {
		g_dispatcher.addTask(createTask(std::bind(task.callback, result, success)));
	}
}
开发者ID:Codex-NG,项目名称:TFS-Flash,代码行数:16,代码来源:databasetasks.cpp

示例5: schedulerThread

void Scheduler::schedulerThread()
{
	srand(time(NULL));

	Dispatcher *dispatcher = Dispatcher::instance();

	boost::unique_lock<boost::mutex> eventLockUnique(m_eventLock, boost::defer_lock);

	while(m_threadState != STATE_TERMINATED) {
		SchedulerTask* task = NULL;
		bool runTask = false;
		bool ret = true;

		eventLockUnique.lock();

		if(m_eventList.empty()) {
			m_eventSignal.wait(eventLockUnique);
		} else {
			ret = m_eventSignal.timed_wait(eventLockUnique, m_eventList.top()->getCycle());
		}

		if(ret == false && (m_threadState != STATE_TERMINATED)) {
			task = m_eventList.top();
			m_eventList.pop();

			EventIdSet::iterator it = m_eventIds.find(task->getEventId());
			if(it != m_eventIds.end()) {
				runTask = true;
				m_eventIds.erase(it);
			}
		}

		eventLockUnique.unlock();

		if(task) {
			if(runTask) {
				task->setDontExpire();
				dispatcher->addTask(task);
			} else {
				delete task;
			}
		}
	}
}
开发者ID:Hixian,项目名称:ddosmon,代码行数:44,代码来源:scheduler.cpp

示例6: luaDispatcherAddTask

int LuaBinder::luaDispatcherAddTask(lua_State* L)
{
	// Dispatcher.addTask(callable, ...)
	int parameters = lua_gettop(L);
	if (lua_isfunction(L, -parameters/*1*/)) {
		LuaEventObject* eventDesc = new LuaEventObject();
		for (int i = 0; i < parameters - 1; ++i) {
			eventDesc->parameters.push_back(luaL_ref(L, LUA_REGISTRYINDEX));
		}

		eventDesc->function = luaL_ref(L, LUA_REGISTRYINDEX);

		g_dispatcher.addTask(createTask(std::bind(&LuaBinder::executeLuaEvent, L, eventDesc)));
		LuaBinder::pushBoolean(L, true);
	} else {
		LuaBinder::reportError("[Error - Scheduler.addTask] Callable(#arg 1) must be function.");
		LuaBinder::pushBoolean(L, false);
	}

	return 1;
}
开发者ID:slavidodo,项目名称:coppem-server,代码行数:21,代码来源:luaenv.cpp

示例7: releaseMessage

void OutputMessagePool::releaseMessage(OutputMessage* msg)
{
	g_dispatcher.addTask(
		createTask(boost::bind(&OutputMessagePool::internalReleaseMessage, this, msg)));
}
开发者ID:Codex-NG,项目名称:TFS-1.0,代码行数:5,代码来源:outputmessage.cpp


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