Esempio n. 1
0
//-----------------------------------------------------------------------------
// 描述: 服务器开始运行后,主线程进行后台守护工作
//-----------------------------------------------------------------------------
void IseMainServer::runBackground()
{
    int adjustThreadInterval = iseApp().iseOptions().getUdpAdjustThreadInterval();
    int secondCount = 0;

    while (!iseApp().isTerminated())
    try
    {
        try
        {
            // 每隔 adjustThreadInterval 秒执行一次
            if ((secondCount % adjustThreadInterval) == 0)
            {
#ifdef ISE_LINUX
                // 暂时屏蔽退出信号
                SignalMasker sigMasker(true);
                sigMasker.setSignals(1, SIGTERM);
                sigMasker.block();
#endif

                // 维护工作者线程的数量
                if (udpServer_) udpServer_->adjustWorkerThreadCount();
            }
        }
        catch (...)
        {}

        secondCount++;
        sleepSeconds(1, true);  // 1秒
    }
    catch (...)
    {}
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
// 描述: 全部 eventLoop 停止工作
//-----------------------------------------------------------------------------
void EventLoopList::stop()
{
    const int MAX_WAIT_FOR_SECS = 10;   // (秒)
    const double SLEEP_INTERVAL = 0.5;  // (秒)

    // 通知停止
    for (int i = 0; i < items_.getCount(); i++)
        items_[i]->stop(false, false);

    // 等待停止
    double waitSecs = 0;
    while (waitSecs < MAX_WAIT_FOR_SECS)
    {
        int runningCount = 0;
        for (int i = 0; i < items_.getCount(); i++)
            if (items_[i]->isRunning()) runningCount++;

        if (runningCount == 0) break;

        sleepSeconds(SLEEP_INTERVAL, true);
        waitSecs += SLEEP_INTERVAL;
    }

    // 强行停止
    for (int i = 0; i < items_.getCount(); i++)
        items_[i]->stop(true, true);
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// 描述: 由系统定时任务线程执行
//-----------------------------------------------------------------------------
void ScheduleTaskMgr::execute(Thread& executorThread)
{
    while (!executorThread.isTerminated())
    {
        try
        {
            AutoLocker locker(mutex_);
            for (int i = 0; i < taskList_.getCount(); i++)
                taskList_[i]->process();
        }
        catch (...)
        {}

        sleepSeconds(1);
    }
}
Esempio n. 4
0
	~InstanceCountChecker()
		{
		long tries = 0;
		while (mCount != InstanceCounter<T>::totalCount() && tries < 20)
			{
			sleepSeconds(.1);
			tries++;
			}	

		if (InstanceCounter<T>::totalCount() != mCount)
			{
			LOG_CRITICAL << "Failed InstanceCountCheck: "
				<< InstanceCounter<T>::totalCount() << " != " << mCount
				;
			asm("int3");
			}
		}