Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

thread.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           thread.h  -  Thread abstraction
00003                              -------------------
00004     begin                : Tue Feb 12 2002
00005     copyright            : (C) 2002 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, thread.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2002
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NETHREAD_H
00028 #define __NETHREAD_H
00029 
00030 
00031 
00032 #include "base.h"
00033 
00034 #if defined(POSIX) || defined(__APPLE__)
00035 #  include <pthread.h>
00036 #  include <sys/time.h>
00037 #endif
00038 
00039 
00045 namespace NeoEngine
00046 {
00047 
00048 
00049 //external classes
00050 class TaskManager;
00051 
00052 
00053 //forward declarations
00054 class Thread;
00055 class ThreadMethod;
00056 class ThreadCallback;
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00069 class NEOENGINE_API Thread
00070 {
00071     public:
00072 
00074         enum THREADEVENT
00075         {
00076             START,
00077             TERMINATE
00078         };
00079 
00080 
00081     protected:
00082 
00083 #ifdef WIN32
00084 
00085         unsigned long                 m_ulThread;
00086 #elif defined(POSIX) || defined(__APPLE__)
00087 
00088         pthread_t                     m_kThread;
00089 #endif      
00090 
00092         void                         *m_pUserData;
00093 
00095         int                           m_iThreadID;
00096 
00098         TaskManager                  *m_pkTaskManager;
00099 
00101         ThreadMethod                 *m_pkMethod;       
00102 
00104         ThreadCallback               *m_pkCallback;
00105         
00107         static int                    s_iThreadCounter;
00108 
00109 
00110     public:
00111 
00113         bool                          m_bTerminate;
00114 
00116         bool                          m_bTerminated;
00117 
00119         bool                          m_bStarted;
00120 
00121 
00129                                       Thread( ThreadMethod *pkMethod, void *pData, ThreadCallback *pkCallback = 0, TaskManager *pkTaskManager = 0 );
00130 
00134         virtual                      ~Thread();
00135 
00139         ThreadMethod                 *GetThreadMethod() { return m_pkMethod; }
00140 
00144         void                         *GetUserData() { return m_pUserData; }
00145 
00149         int                           GetThreadID() const { return m_iThreadID; }
00150 
00154         bool operator < ( const Thread &rkThread ) const { return( m_iThreadID < rkThread.GetThreadID() ); }
00155 
00159         bool operator == ( const Thread &rkThread ) const { return( m_iThreadID == rkThread.GetThreadID() ); }
00160 };
00161 
00162 
00163 
00164 
00170 class NEOENGINE_API ThreadMethod
00171 {
00172     public:
00173 
00179         virtual void                *ThreadEntry( Thread *pkThread, void *pData ) = 0;
00180 
00185         static void                  Sleep( int iTime );
00186 };
00187 
00188 
00189 
00190 
00191 
00192 
00198 class NEOENGINE_API ThreadCallback
00199 {
00200     public:
00201 
00208         virtual void                 ThreadEvent( int iThreadID, Thread::THREADEVENT eEvent, void *pData = 0 ) = 0;
00209 };
00210 
00211 
00212 }; // namespace NeoEngine
00213 
00214 
00215 #endif
00216 

Generated on Wed Jan 21 14:21:07 2004 for NeoEngine by doxygen 1.3.5