Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "DcThread.h"
00026
00027 CdcThread::~CdcThread ()
00028 {
00029 CloseThread ();
00030 }
00031
00032 void CdcThread::MakeThread (int (*pfunc) (void*), void* pdata, int stack_size)
00033 throw (CdcException)
00034 {
00035 pFunc = pfunc;
00036 pData = pdata;
00037
00038 DWORD ThreadId;
00039
00040 if (IsStillActive ())
00041 throw CdcException ("Thread is already running");
00042
00043 pThread = CreateThread (NULL, stack_size * 1024,
00044 (LPTHREAD_START_ROUTINE) pFunc, (void*) pData,
00045 0, &ThreadId);
00046
00047 if (pThread == NULL)
00048 throw CdcException ("Cannot create thread");
00049 }
00050
00051
00052 void CdcThread::CloseThread ()
00053 {
00054 if (pThread)
00055 CloseHandle (pThread);
00056 pThread = NULL;
00057 }
00058
00059 bool CdcThread::SetPriority (t_thread_priority priority)
00060 {
00061 int ret;
00062
00063 switch (priority)
00064 {
00065 case DC_TP_LOWER :
00066 ret = SetThreadPriority (pThread, THREAD_PRIORITY_LOWEST);
00067 break;
00068 case DC_TP_LOW :
00069 ret = SetThreadPriority (pThread, THREAD_PRIORITY_BELOW_NORMAL);
00070 break;
00071 case DC_TP_NORNAL :
00072 ret = SetThreadPriority (pThread, THREAD_PRIORITY_NORMAL);
00073 break;
00074 case DC_TP_HIGH :
00075 ret = SetThreadPriority (pThread, THREAD_PRIORITY_ABOVE_NORMAL);
00076 break;
00077 case DC_TP_HIGHER :
00078 ret = SetThreadPriority (pThread, THREAD_PRIORITY_HIGHEST);
00079 break;
00080 }
00081 return (ret != 0);
00082 }
00083
00084 bool CdcThread::IsStillActive ()
00085 {
00086 if (!pThread) return false;
00087 unsigned long code;
00088 GetExitCodeThread (pThread, &code);
00089 return code == STILL_ACTIVE;
00090 }