00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00040 #include "CToxiThread.h"
00041
00042
00043 static DWORD WINAPI cThreadProc( CToxiThread *pThis )
00044 {
00045 return pThis->ThreadProc();
00046 }
00047
00048 bool CToxiThread::setThreadFunc(void (*Action)(void))
00049 {
00050 if(Action==NULL)
00051 return false;
00052 pAction=Action;
00053
00054 if(pAction==NULL)
00055 return false;
00056 else
00057 return true;
00058 }
00059
00060
00061 CToxiThread::CToxiThread()
00062 {
00063 d_threadID = 0;
00064 d_threadHandle = NULL;
00065 d_bIsRunning = false;
00066 this->setPriority(THREAD_PRIORITY_NORMAL);
00067 }
00068
00069 CToxiThread::CToxiThread(int priority)
00070 {
00071 d_threadID = 0;
00072 d_threadHandle = NULL;
00073 d_bIsRunning = false;
00074 this->setPriority(priority);
00075 }
00076
00077 CToxiThread::~CToxiThread()
00078 {
00079 end();
00080 }
00081
00082
00083 void CToxiThread::begin()
00084 {
00085 if( d_threadHandle )
00086 end();
00087
00088 d_threadHandle = CreateThread( NULL,
00089 0,
00090 (LPTHREAD_START_ROUTINE)cThreadProc,
00091 this,
00092 0,
00093 (LPDWORD)&d_threadID );
00094 if( d_threadHandle == NULL )
00095 {
00096 MessageBox(NULL,"THREAD HANDLE NULL",ERROR_TITLE,MB_OK|MB_ICONEXCLAMATION);
00097 }
00098 d_bIsRunning = true;
00099 }
00100
00101 void CToxiThread::setPriority(int priority)
00102 {
00103 SetThreadPriority(d_threadHandle,priority);
00104 }
00105
00106 int CToxiThread::getPriority()
00107 {
00108 return GetThreadPriority(d_threadHandle);
00109 }
00110
00111 void CToxiThread::end()
00112 {
00113 if( d_threadHandle != NULL ) {
00114 d_bIsRunning = false;
00115 WaitForSingleObject( d_threadHandle, INFINITE );
00116 CloseHandle( d_threadHandle );
00117 d_threadHandle = NULL;
00118 }
00119 }
00120
00121 DWORD CToxiThread::ThreadProc()
00122 {
00123 pAction();
00124 return 0;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133