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

ansi/Thread.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2003-2005 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 
00061 
00068 class DWFThread
00069 {
00070 
00071 public:
00072 
00085     typedef enum
00086     {
00091         eNone,
00092 
00098         eRun,
00099 
00104         eEnd,
00105 
00110         eWork,
00111 
00115         eKill,
00116 
00122         eSuspend
00123 
00124     } teState;
00125 
00126 public:
00127 
00133     ~DWFThread()
00134         throw();
00135 
00142     void run()
00143         throw();
00144 
00150     void end()
00151         throw( DWFException );
00152 
00158     void kill()
00159         throw( DWFException );
00160 
00166     void suspend()
00167         throw( DWFException );
00168 
00174     void resume()
00175         throw( DWFException );
00176 
00177 private:
00178     friend class DWFThreadPool;
00179 
00180     //
00181     // Constructor
00182     //
00183     DWFThread( DWFThreadPool& rPool )
00184         throw();
00185 
00186     //
00187     // Begins the thread
00188     //
00189     void _begin()
00190         throw( DWFException );
00191 
00192     //
00193     // Joins the thread
00194     //
00195     void _join()
00196         throw( DWFException );
00197 
00198     //
00199     // Runs a worker in the thread
00200     //
00201     void _work( DWFThreadWorker& rWorker )
00202         throw( DWFException );
00203 
00204     //
00205     // returns the current run state
00206     //
00207     teState _state()
00208         throw( DWFException );
00209 
00210     //
00211     // sets the current run state
00212     //
00213     void _setstate( teState eState )
00214         throw( DWFException );
00215 
00216     //
00217     // returns the current state change request
00218     //
00219     teState _requeststate()
00220         throw( DWFException );
00221 
00222     //
00223     // requests a state change
00224     //
00225     void _setrequest( teState eState )
00226         throw( DWFException );
00227 
00228 private:
00229 
00230     DWFThreadPool&      _rPool;
00231 
00232     pthread_t           _tThread;
00233     pthread_attr_t      _tThreadAttributes;
00234 
00235     pthread_mutex_t     _tStateMutex;
00236 
00237     DWFSignal           _oWorkSignal;
00238     DWFThreadWorker*    _pWorker;
00239 
00240     volatile teState    _eRunState;
00241     volatile teState    _eRequestState;
00242 
00243 private:
00244 
00245     //
00246     // Not Implemented
00247     //
00248     DWFThread( const DWFThread& );
00249     DWFThread& operator=( const DWFThread& );
00250 };
00251 
00252 }
00253 
00254 
00255 #else
00256 #error  This header file is incompatible with your current system configuration
00257 #endif
00258 
00259 #endif

Generated on Tue May 17 12:05:10 2005 for Autodesk DWF Core Library by  doxygen 1.4.1