Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

CToxiThread.cpp

Go to the documentation of this file.
00001 
00009 /* 
00010         ---- Copyright (C) 2002  Jose Eduardo R. Mourão (eduardo_rdm@hotmail.com) ----
00011           
00012         This file is part of ToxiTea.
00013 
00014     ToxiTea is free software; you can redistribute it and/or modify
00015     it under the terms of the GNU General Public License as published by
00016     the Free Software Foundation; either version 2 of the License, or
00017     (at your option) any later version.
00018 
00019     ToxiTea is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022     GNU General Public License for more details.
00023 
00024     You should have received a copy of the GNU General Public License
00025     along with ToxiTea; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 
00028         For more information and updates visit: 
00029         http://toxitea.sourceforge.net
00030         or mail to: eduardo_rdm@hotmail.com
00031 
00032         COMPILING AND/OR USING YOU ARE ACCEPTING ALL TERMS ABOVE.
00033         THIS LICENSE CAN BE CHANGED ANY TIME FOR ANY REASON WITHOUT NO COMMUNICATION.
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); // fuck
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  

Generated on Mon Sep 23 23:07:01 2002 for ToxiTea by doxygen1.2.18