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

📄 warlogthread.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include "WarLogThread.h"   // class implemented#ifndef WAR_LOG_ENGINE_H#   include "WarLogEngine.h"#endif#ifndef WAR_SHUTDOWN_ENGINE_H#   include "WarShutdownEngine.h"#endif#ifndef WAR_AUTO_LOCK_H#   include "WarAutoLock.h"#endif#define AUTO_LOCK WarAutoLock my_lock(WarLogEngine::GetEngine().mLock);/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarLogThread::WarLogThread(){}// WarLogThreadWarLogThread::~WarLogThread(){}// ~WarLogThread//============================= OPERATORS ====================================//============================= OPERATIONS ===================================void WarLogThread::PushEvent(war_logevent_ptr_t& logEventPtr){    AUTO_LOCK    mLogEvents.push_back(logEventPtr);    mEvent.Signal();    // Adjust the therad priority after the size of the queue    int num_pending = mLogEvents.size();    if (num_pending > 50000)    {        // Flush log entries before we use up all the the memory :/        mLogEvents.erase(mLogEvents.begin(), mLogEvents.end());    }    else if (num_pending > 25000)    {        if (GetPriority() != WAR_THRD_PRI_HIGH)            SetPriority(WAR_THRD_PRI_HIGH);    }    else if (num_pending > 10000)    {        if (GetPriority() != WAR_THRD_PRI_NORMAL)            SetPriority(WAR_THRD_PRI_NORMAL);    }    else if (num_pending < 100)    {        if (GetPriority() != WAR_THRD_PRI_VERYLOW)            SetPriority(WAR_THRD_PRI_VERYLOW);    }    else if (num_pending < 500)    {        if (GetPriority() != WAR_THRD_PRI_LOW)            SetPriority(WAR_THRD_PRI_LOW);    }}//============================= ACCESS     ===================================//============================= INQUIRY    ===================================/////////////////////////////// PROTECTED  ///////////////////////////////////void WarLogThread::OnShutdown(war_cptr_t parg){    ((WarLogThread *)parg)->SetExitFlag();    WarPtrWrapper<WarLogThread> my_ptr = (WarLogThread *)parg;    my_ptr->SetExitFlag();    my_ptr->SetPriority(WAR_THRD_PRI_HIGH);    while(my_ptr->IsActive())    {        my_ptr->mEvent.Signal();        WarTime::Sleep(100);    }    // Remove the pointer from the log engine    {        AUTO_LOCK        WarLogEngine::GetEngine().mLogThreadPtr = NULL;    }    // Wait for the thread to kill it's own reference to itself    while(my_ptr->GetReferenceCount() > 1)        WarTime::Sleep(100);    my_ptr = NULL;}/////////////////////////////// PRIVATE    ///////////////////////////////////void WarLogThread::Run(){    war_logevent_ptr_t log_event;    WarShutdownEngine::GetEngine().AddEvent(OnShutdown, this);    while(!IsExiting())    {        {            AUTO_LOCK            if (!mLogEvents.empty())            {                log_event = mLogEvents.front();                mLogEvents.pop_front();            }        }        if (log_event.IsEmpty())            mEvent.WaitForEvent();        else        {#if WAR_CATCH_ALL            try#endif            {                WarLogEngine::GetEngine().OnLogEvent(log_event);            }#if WAR_CATCH_ALL            catch(...)            {                // Just in case...                ;            }#endif            log_event = NULL;        }    }}

⌨️ 快捷键说明

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