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

📄 warthreadwin32.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include "WarThread.h"   // class implemented#ifndef WAR_ASSERT_H_INCLUDED#   include <assert.h>#endif#ifndef WAR_AUTO_LOCK_H#   include "WarAutoLock.h"#endif#ifndef WAR_LOG_H#   include "WarLog.h"#endif// the Win32 spesific part of the WarThread class/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================//============================= OPERATORS ====================================static int PrioritiesTable [] ={    THREAD_PRIORITY_TIME_CRITICAL,    THREAD_PRIORITY_HIGHEST,    THREAD_PRIORITY_NORMAL,    THREAD_PRIORITY_BELOW_NORMAL,    THREAD_PRIORITY_LOWEST,    THREAD_PRIORITY_IDLE,    THREAD_PRIORITY_NORMAL};void WarThread::SetPriority(const WarPrioritiesDefE Priority){    if ((Priority < WAR_THRD_PRI_VERYHIGH)        || (Priority > WAR_THRD_PRI_INVALID))        WarThrow(WarError(WAR_ERR_INVALID_ARGUMENT), NULL);    // WAR_THRD_PRI_INVALID means "do not set"    if (Priority != WAR_THRD_PRI_INVALID)    {           if (NULL == mThreadHandle)            WarThrow(WarError(WAR_ERR_INTERNAL_DATA_NOT_INITIALIZED), NULL);        if (!::SetThreadPriority(mThreadHandle,            PrioritiesTable[Priority]))            WarThrow(WarError(WAR_ERR_SYSTEM_ERROR,             ::GetLastError()), NULL);        mCurrentPriority = Priority;    }}//============================= OPERATIONS ===================================//============================= ACESS      ===================================//============================= INQUIRY    ===================================/////////////////////////////// PROTECTED  ////////////////////////////////////////////////////////////////// PRIVATE    ///////////////////////////////////void WarThread::CreateThread (war_thread_id_t & thread_id)    throw(WarException){    if (!::CreateThread (NULL, 0, war_thread_entry,        (LPVOID) this, 0, (LPDWORD) &thread_id))    {        WarThrow(WarError(WAR_THREADERR_FAILED_TO_CREATE,            ::GetLastError()), NULL);    }}void WarThread::ExitThread(){    ::ExitThread(0);}WarThread::war_thread_id_t WarThread::GetCurrentThreadId(){    return (war_thread_id_t) ::GetCurrentThreadId();}void WarThread::InitializeThread() throw(WarException){    // Initialize the Thread-spesific storage#if WAR_USE_WIN32_TLS    if (msTlsIndex == 0)    {        msTlsIndex = TlsAlloc();        if (msTlsIndex == 0xffffffff)            WarThrow(WarError(WAR_THREADERR_FAILED_TO_INITIALIZE_TLS),            ::GetLastError()), NULL);    }    ::TlsSetValue(msTlsIndex, new WarThreadSpesificData);#elif WAR_USE_WIN32_FAST_TD    mspThreadData = new WarThreadSpesificData;#endif}DWORD WINAPI WarThread::war_thread_entry(LPVOID lParam){    WarThread *pThread = (WarThread *) lParam;    WarPtrWrapper<WarThread> MySmartie(pThread); // Prevent destruction while the thread is running    #if WAR_CATCH_ALL    try#endif    {        pThread->mThreadHandle = ::GetCurrentThread();        pThread->StartFunc();    }#if WAR_CATCH_ALL        catch(...)    {        WarLogError("WarThread::war_thread_entry()",             "Caught unknown exception from StartFunc()", NULL);    }#endif    return 0;}

⌨️ 快捷键说明

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