⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warthreadforpool.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include "WarThreadForPool.h"   // class implemented#ifndef WAR_THREAD_POOL_H#   include "WarThreadPool.h"#endif#ifndef WAR_THREAD_POOL_TASK_H#   include "WarThreadPoolTask.h"#endif#ifndef WAR_LOG_H#   include "WarLog.h"#endif/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarThreadForPool::WarThreadForPool(WarThreadPool * pPool)    : mpPool(pPool),    mAutoCnt(pPool->mCntThreadsExist, pPool->mLock){}//============================= OPERATORS ====================================//============================= OPERATIONS ===================================//============================= ACCESS     ===================================//============================= INQUIRY    ===================================/////////////////////////////// PROTECTED  ///////////////////////////////////void WarThreadForPool::ProcessRequest(WarThreadPoolTask * pTask){    // The default processing is to let the task object    // handle its own buisness    pTask->OnProcessing(this);}WarThreadForPool::~WarThreadForPool(){}/////////////////////////////// PRIVATE    ///////////////////////////////////voidWarThreadForPool::Run(){    SetState(STATE_HOUSEKEEPING);    mpPool->Attach(this);    while (!IsExiting())    {        ResetCancelFlag();        WarThreadPoolTask * pTask = mpPool->PopTask();        if (pTask)        {            WarPtrWrapper<WarThreadPoolTask> MySmartie(pTask);            pTask->mpThread = this;                        SetState(STATE_BUSY);            pTask->SetState(WarThreadPoolTask::STATE_PROCESSING);            try            {                ProcessRequest(pTask);            }            catch(WarException& ex)            {                WarLogError("WarThreadForPool::Run()",                    "Caught unhandled WarException",                    &ex);            }#if WAR_CATCH_ALL                        catch(...)            {                WarLogError("WarThreadForPool::Run()",                    "Caught unknown exception", NULL);                break;            }#endif            pTask->mpThread = NULL;#if WAR_CATCH_ALL            try#endif            {                mpPool->TaskDone(MySmartie, GetCancelFlag());            }#if WAR_CATCH_ALL                        catch(...)            {                WarLogError("WarThreadForPool::Run()",                    "Caught unknown exception", NULL);                break;            }#endif        }        if (IsExiting())	// New test            break;        SetState(STATE_IDLE);        mpPool->mSignal.WaitForEvent();        SetState(STATE_HOUSEKEEPING);    }    mpPool->Detach(this);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -