win32/Thread.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2003-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 #ifndef _DWFCORE_THREAD_WIN32_H
00023 #define _DWFCORE_THREAD_WIN32_H
00024 
00038 
00039 
00040 #include "dwfcore/Core.h"
00041 
00042 #ifdef  _DWFCORE_WIN32_SYSTEM
00043 
00044 #ifndef _DWFCORE_SYNCHRONIZATION_H
00045 #error  This header should not be included directly - use "dwfcore/Synchronization.h" instead
00046 #endif
00047 
00048 
00049 namespace DWFCore
00050 {
00051 
00052 //
00053 // fwd decl
00054 //
00055 class DWFThreadWorker;
00056 
00057 
00065 class DWFThread : virtual public DWFCoreMemory
00066 {
00067 
00068 public:
00069 
00083     typedef enum
00084     {
00089         eNone,
00090 
00095         eRun,
00096 
00101         eEnd,
00102 
00106         eKill,
00107 
00113         eSuspend
00114 
00115     } teState;
00116 
00117 public:
00118 
00124     ~DWFThread()
00125         throw();
00126 
00133     void run()
00134         throw();
00135 
00141     void end()
00142         throw( DWFException );
00143 
00149     void kill()
00150         throw( DWFException );
00151 
00157     void suspend()
00158         throw( DWFException );
00159 
00165     void resume()
00166         throw( DWFException );
00167 
00168 private:
00169     friend class DWFThreadPool;
00170 
00171     //
00172     // Constructor
00173     //
00174     DWFThread( DWFThreadPool& rPool )
00175         throw();
00176 
00177     //
00178     // Begins the thread
00179     //
00180     void _begin()
00181         throw( DWFException );
00182 
00183     //
00184     // Joins the thread
00185     //
00186     void _join()
00187         throw( DWFException );
00188 
00189     //
00190     // Runs a worker in the thread
00191     //
00192     void _work( DWFThreadWorker& rWorker )
00193         throw( DWFException );
00194 
00195     //
00196     // returns the current run state
00197     //
00198     teState _state()
00199         throw( DWFException );
00200 
00201     //
00202     // sets the current run state
00203     //
00204     void _setstate( teState eState )
00205         throw( DWFException );
00206 
00207     //
00208     // returns the current state change request
00209     //
00210     teState _requeststate()
00211         throw( DWFException );
00212 
00213     //
00214     // requests a state change
00215     //
00216     void _setrequest( teState eState )
00217         throw( DWFException );
00218 
00219 private:
00220 
00221     DWFThreadPool&      _rPool;
00222 
00223     HANDLE              _hThread;
00224     CRITICAL_SECTION    _oStateLock;
00225 
00226     DWFSignal           _oWorkSignal;
00227     DWFThreadWorker*    _pWorker;
00228 
00229     volatile teState    _eRunState;
00230     volatile teState    _eRequestState;
00231     volatile teState    _eLastSuspendedState;
00232 
00233 private:
00234 
00235     //
00236     // Not Implemented
00237     //
00238     DWFThread( const DWFThread& );
00239     DWFThread& operator=( const DWFThread& );
00240 };
00241 
00242 }
00243 
00244 
00245 
00246 #else
00247 #error  This is a Win32 header file and is incompatible with your current system configuration
00248 #endif 
00249 
00250 #endif
00251 
00252 

Generated on Tue Jan 6 22:39:29 2009 for Autodesk DWF Core Library by  doxygen 1.4.5