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

at_thread.h

Go to the documentation of this file.
00001 //
00002 // The Austria library is copyright (c) Gianni Mariani 2004.
00003 // 
00004 // Grant Of License.  Grants to LICENSEE the non-exclusive right to use the Austria
00005 // library subject to the terms of the LGPL.
00006 // 
00007 // A copy of the license is available in this directory or one may be found at this URL:
00008 //      http://www.gnu.org/copyleft/lesser.txt
00009 // 
00015 #ifndef x_at_thread_h_x
00016 #define x_at_thread_h_x 1
00017 
00018 #include "at_exports.h"
00019 #include "at_types.h"
00020 
00021 //
00022 // Include system specific definitions
00023 //
00024 #include AT_THREAD_H
00025 
00026 
00027 // Austria namespace
00028 namespace at
00029 {
00030 
00031 class Conditional;
00032 
00033 // ======== Task ======================================================
00043 class Task
00044 {
00045     public:
00046     
00054     typedef SYS_TaskID                                  TaskID;
00055 
00056 
00057     // ======== Task ==================================================
00063     Task();
00064     
00065     // ======== ~Task =================================================
00072     virtual ~Task();
00073 
00074 
00075     // ======== Work ==================================================
00083     virtual void Work() throw() = 0;
00084 
00085     // ======== Start =================================================
00093     void Start();
00094 
00095     // ======== Wait ==================================================
00103     void Wait();
00104 
00105     // ======== Wait ==================================================
00115     void Wait( const TimeInterval & i_time );
00116 
00117 
00118 
00119     // ======== GetThisId =============================================
00126     TaskID GetThisId();
00127 
00128 
00129     // ======== GetSelfId =============================================
00136     static TaskID GetSelfId();
00137 
00138     private:
00139 
00140     //
00141     // Can't copy a task.
00142     Task( const Task & );
00143     Task & operator= ( const Task & );
00144 
00145     friend struct TaskContext;
00146 
00151     TaskContext                         * m_task_context;
00152 
00153 };
00154 
00155 
00156 // ======== Mutex =====================================================
00163 class Mutex
00164 {
00165     
00166     public:
00167     friend class Conditional;
00168 //    friend class ConditionalMutex;
00169 
00170 
00171     // ======== MutexType =============================================
00177     enum MutexType
00178     {
00183         NonRecursive,
00184 
00189         Recursive,
00190 
00194         Checking
00195     };
00196     
00197 
00198     // ======== Mutex =================================================
00205     Mutex( MutexType i_type = NonRecursive );
00206 
00207 
00208     // ======== Mutex =================================================
00214     ~Mutex();
00215 
00216 
00217     // ======== Lock ==================================================
00225     void Lock();
00226 
00227 
00228     // ======== TryLock ===============================================
00237     bool TryLock();    
00238 
00239 
00240     // ======== Unlock ================================================
00248     void Unlock();
00249     
00250 
00256     struct MutexContext
00257     {
00258         SystemMutexContextType                  m_data;
00259 
00260     };
00261 
00262     private:
00263 
00268     MutexContext                    m_mutex_context;
00269 
00270     // copy constructor and assignment operator are private and
00271     // unimplemented.  It is illegal to copy a mutex.
00272     Mutex( const Mutex & );
00273     Mutex & operator= ( const Mutex & );
00274 };
00275 
00276 
00277 
00278 // ======== Conditional ===============================================
00290 class Conditional
00291 {
00292     public:
00293 //    friend class ConditionalMutex;
00294 
00295 
00296     // ======== Conditional ===========================================
00303     Conditional( Mutex & i_mutex );
00304 
00305     // destructor
00306     ~Conditional();
00307 
00308     // ======== Wait ==================================================
00316     void Wait();
00317 
00318     // ======== Wait ==================================================
00327     bool Wait( const TimeInterval & i_time );
00328 
00329 
00330     // ======== Wait ==================================================
00338     bool Wait( const TimeStamp & i_time );
00339 
00340 
00341     // ======== Post ==================================================
00347     void Post();
00348 
00349 
00350     // ======== PostAll ===============================================
00356     void PostAll();    
00357     
00358 
00364     struct ConditionalContext
00365     {
00366         SystemConditionalContextType            m_data;
00367     };
00368 
00369     private:
00370 
00375     ConditionalContext                 m_conditional_context;
00376 
00377 
00378     // copy constructor and assignment operator are private and
00379     // unimplemented.  It is illegal to copy a Conditional.
00380     Conditional( const Conditional & );
00381     Conditional & operator= ( const Conditional & );
00382 
00383 };
00384 
00385 
00386 
00387 // ======== ConditionalMutex ==========================================
00395 class ConditionalMutex
00396   : public Mutex,
00397     public Conditional
00398 {
00399     public:
00400 
00401 
00402     // ======== ConditionalMutex ======================================
00410     ConditionalMutex( MutexType i_type = NonRecursive );
00411 
00412     private:
00413     ConditionalMutex( const ConditionalMutex & );
00414     ConditionalMutex & operator= ( const ConditionalMutex & );
00415 };
00416 
00417 
00418 // ======== Lock ================================================
00425 template <typename w_MutexType>
00426 class Lock
00427 {
00428     public:
00429 
00430     w_MutexType             & m_mutex;
00431 
00432     Lock( w_MutexType & io_mutex )
00433       : m_mutex( io_mutex )
00434     {
00435         m_mutex.Lock();
00436     }
00437 
00438     ~Lock()
00439     {
00440         m_mutex.Unlock();
00441     }
00442 
00443     void Wait()
00444     {
00445         return m_mutex.Wait();
00446     }
00447 
00448     void Wait( const TimeInterval & i_time )
00449     {
00450         return m_mutex.Wait( i_time );
00451     }
00452 
00453     void Post()
00454     {
00455         return m_mutex.Post();
00456     }
00457 
00458     void PostAll()
00459     {
00460         return m_mutex.PostAll();
00461     }
00462 
00463     private:
00464 
00465     // must not allow the copy or assignment so make
00466     // these methods private.
00467     Lock( const Lock & );
00468     Lock & operator=( const Lock & );
00469 };
00470 
00471 }; // namespace
00472 
00473 
00474 #endif // x_at_thread_h_x
00475 
00476 

Generated for Austria by doxygen and MakeXS at Sun Oct 24 17:35:34 PDT 2004