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

Anp::RunThread< T > Class Template Reference

#include <RunThread.h>

List of all members.

Public Member Functions

 RunThread ()
 RunThread (Handle< T > alg)
 ~RunThread ()
void Run (bool new_thread)
int Join (void)
Handle< T > GetAlg ()
T * operator-> () const
void release ()
bool valid () const

Private Attributes

Mutex fMutex
pthread_t fThread
int fThreadStatus
Handle< T > fAlg

template<class T>
class Anp::RunThread< T >


Constructor & Destructor Documentation

template<class T>
Anp::RunThread< T >::RunThread  ) 
 

Definition at line 85 of file RunThread.h.

00086       : fMutex(), fThread(),  fThreadStatus(1), fAlg() {}

template<class T>
Anp::RunThread< T >::RunThread Handle< T >  alg  )  [explicit]
 

Definition at line 89 of file RunThread.h.

00090       : fMutex(), fThread(),  fThreadStatus(1), fAlg(alg) {}

template<class T>
Anp::RunThread< T >::~RunThread  ) 
 

Definition at line 93 of file RunThread.h.

00093 {}


Member Function Documentation

template<class T>
Handle< T > Anp::RunThread< T >::GetAlg  ) 
 

Definition at line 147 of file RunThread.h.

00148    {
00149       return fAlg;
00150    }

template<class T>
int Anp::RunThread< T >::Join void   ) 
 

Definition at line 133 of file RunThread.h.

References Anp::RunThread< T >::fThread, and Anp::RunThread< T >::fThreadStatus.

00134    {  
00135       //
00136       // If there is parallel thread running then attempt to join to main thread
00137       //
00138       if(fThreadStatus == 0)
00139       {
00140          return pthread_join(fThread, NULL);
00141       }
00142       
00143       return fThreadStatus;
00144    }

template<class T>
T * Anp::RunThread< T >::operator->  )  const
 

Definition at line 153 of file RunThread.h.

References Anp::RunThread< T >::fAlg.

00154    { 
00155       if(fAlg.valid()) return fAlg.get();
00156       return 0;
00157    }

template<class T>
void Anp::RunThread< T >::release  ) 
 

Definition at line 166 of file RunThread.h.

References Anp::RunThread< T >::fAlg.

00167    { 
00168       fAlg.release();
00169    }

template<class T>
void Anp::RunThread< T >::Run bool  new_thread  ) 
 

Definition at line 96 of file RunThread.h.

References Anp::RunThread< T >::fAlg, Anp::RunThread< T >::fMutex, Anp::RunThread< T >::fThread, and Anp::RunThread< T >::fThreadStatus.

00097    {   
00098       if(!fAlg.valid()) return;
00099 
00100       if(new_thread)
00101       {
00102          //
00103          // Lock mutex ONLY when starting new thread
00104          //
00105          Anp::Lock<Mutex> lock(fMutex);
00106          
00107          //
00108          // Run algorithm in NEW thread
00109          //
00110          fThreadStatus = pthread_create(&fThread, NULL, Anp::get_thread_done<T>, fAlg.get());
00111          
00112          if(fThreadStatus != 0)
00113          {
00114             std::cerr << "RunThread::Run - invalid thread status: " << fThreadStatus << std::endl;
00115          }
00116       }
00117       else
00118       {
00119          //
00120          // No thread is created, set thread status to 1,
00121          // so that we do not try later to join same thread.
00122          //
00123          fThreadStatus = 1;
00124          
00125          //
00126          // Run algorithm in this thread
00127          //
00128          Anp::get_thread_done<T>(fAlg.get());
00129       }
00130    }

template<class T>
bool Anp::RunThread< T >::valid  )  const
 

Definition at line 160 of file RunThread.h.

References Anp::RunThread< T >::fAlg.

00161    { 
00162       return fAlg.valid();
00163    }


Member Data Documentation

template<class T>
Handle<T> Anp::RunThread< T >::fAlg [private]
 

Definition at line 59 of file RunThread.h.

Referenced by Anp::RunThread< T >::operator->(), Anp::RunThread< T >::release(), Anp::RunThread< T >::Run(), and Anp::RunThread< T >::valid().

template<class T>
Mutex Anp::RunThread< T >::fMutex [private]
 

Definition at line 55 of file RunThread.h.

Referenced by Anp::RunThread< T >::Run().

template<class T>
pthread_t Anp::RunThread< T >::fThread [private]
 

Definition at line 56 of file RunThread.h.

Referenced by Anp::RunThread< T >::Join(), and Anp::RunThread< T >::Run().

template<class T>
int Anp::RunThread< T >::fThreadStatus [private]
 

Definition at line 57 of file RunThread.h.

Referenced by Anp::RunThread< T >::Join(), and Anp::RunThread< T >::Run().


The documentation for this class was generated from the following file:
Generated on Mon Feb 15 11:10:35 2010 for loon by  doxygen 1.3.9.1