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


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

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


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

示例1: run

int MainLoop::run()
{
	while (m_epoll != -1 && (m_monitors.size() != 0 || m_timers.size() != 0))
	{
		// Get desired timeout
		int timeout = -1;
		TimerMap::const_iterator timer = m_timers.begin();
		if (timer != m_timers.end())
		{
			timeout = timer->second->timeout();
		}

		// Wait for events
		epoll_event events[32];
		int count = ::epoll_wait(m_epoll, events, sizeof(events) / sizeof(events[0]), timeout);
		if (count == -1 && errno == EINTR)
			continue;
		if (count == -1)
			break;

#ifdef MAINLOOP_THREADS
		std::unique_lock<std::mutex> lock(m_mutex);
#endif // MAINLOOP_THREADS

		// Handle events
		for (int i = 0; i != count; ++i)
		{
			auto it = m_monitors.find(events[i].data.fd);
			if (it == m_monitors.end())
				continue;

			Monitor *monitor = it->second;
			if (monitor->callback)
			{
				Direction dir;
				switch (events[i].events & (EPOLLIN|EPOLLOUT))
				{
					case EPOLLIN:
						dir = In;
						break;

					case EPOLLOUT:
						dir = Out;
						break;

					case EPOLLIN | EPOLLOUT:
						dir = InOut;
						break;

					default:
						dir = Error;
				}
#ifdef MAINLOOP_THREADS
				lock.unlock();
#endif // MAINLOOP_THREADS
				monitor->callback(dir);
#ifdef MAINLOOP_THREADS
				lock.lock();
#endif // MAINLOOP_THREADS
			}
		}

		// Handle expired timers
		unsigned long long int t = Timer::currentTime();
		for (TimerMap::iterator it = m_timers.begin(); it != m_timers.end() && it->first <= t; it = m_timers.begin())
		{
			Timer *timer = it->second;
			m_timers.erase(it);

#ifdef MAINLOOP_THREADS
			lock.unlock();
#endif // MAINLOOP_THREADS
			timer->callback()();
#ifdef MAINLOOP_THREADS
			lock.lock();
#endif // MAIN_LOOP_THREADS
		}
	}

	return m_exitCode;
}
开发者ID:pchri03,项目名称:libeventcore,代码行数:81,代码来源:mainloop.cpp


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