ansi/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_H
00023 #define _DWFCORE_THREAD_H
00024 
00025 
00042 
00043 
00044 #include "dwfcore/Core.h"
00045 
00046 #ifdef  _DWFCORE_FOR_ANSI_SYSTEM_ONLY
00047 
00048 #ifndef _DWFCORE_SYNCHRONIZATION_H
00049 #error  This header should not be included directly - use "dwfcore/Synchronization.h" instead
00050 #endif
00051 
00052 
00053 namespace DWFCore
00054 {
00055 
00056 //
00057 // fwd decl
00058 //
00059 class DWFThreadWorker;
00060 class DWFThreadPool;
00061 
00062 
00069 class DWFThread
00070 {
00071 
00072 public:
00073 
00086     typedef enum
00087     {
00092         eNone,
00093 
00099         eRun,
00100 
00105         eEnd,
00106 
00111         eWork,
00112 
00116         eKill,
00117 
00123         eSuspend
00124 
00125     } teState;
00126 
00127 public:
00128 
00134     ~DWFThread()
00135         throw();
00136 
00143     void run()
00144         throw();
00145 
00151     void end()
00152         throw( DWFException );
00153 
00159     void kill()
00160         throw( DWFException );
00161 
00167     void suspend()
00168         throw( DWFException );
00169 
00175     void resume()
00176         throw( DWFException );
00177 
00178 private:
00179     friend class DWFThreadPool;
00180 
00181     //
00182     // Constructor
00183     //
00184     DWFThread( DWFThreadPool& rPool )
00185         throw();
00186 
00187     //
00188     // Begins the thread
00189     //
00190     void _begin()
00191         throw( DWFException );
00192 
00193     //
00194     // Joins the thread
00195     //
00196     void _join()
00197         throw( DWFException );
00198 
00199     //
00200     // Runs a worker in the thread
00201     //
00202     void _work( DWFThreadWorker& rWorker )
00203         throw( DWFException );
00204 
00205     //
00206     // returns the current run state
00207     //
00208     teState _state()
00209         throw( DWFException );
00210 
00211     //
00212     // sets the current run state
00213     //
00214     void _setstate( teState eState )
00215         throw( DWFException );
00216 
00217     //
00218     // returns the current state change request
00219     //
00220     teState _requeststate()
00221         throw( DWFException );
00222 
00223     //
00224     // requests a state change
00225     //
00226     void _setrequest( teState eState )
00227         throw( DWFException );
00228 
00229 private:
00230 
00231     DWFThreadPool&      _rPool;
00232 
00233     pthread_t           _tThread;
00234     pthread_attr_t      _tThreadAttributes;
00235 
00236     pthread_mutex_t     _tStateMutex;
00237 
00238     DWFSignal           _oWorkSignal;
00239     DWFThreadWorker*    _pWorker;
00240 
00241     volatile teState    _eRunState;
00242     volatile teState    _eRequestState;
00243 
00244 private:
00245 
00246     //
00247     // Not Implemented
00248     //
00249     DWFThread( const DWFThread& );
00250     DWFThread& operator=( const DWFThread& );
00251 };
00252 
00253 }
00254 
00255 
00256 #else
00257 #error  This header file is incompatible with your current system configuration
00258 #endif
00259 
00260 #endif

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