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

Detailed Description

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

Definition at line 33 of file RunThread.h.


Constructor & Destructor Documentation

template<class T >
Anp::RunThread< T >::RunThread (  )  [inline]

Definition at line 85 of file RunThread.h.

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

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

Definition at line 89 of file RunThread.h.

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

template<class T >
Anp::RunThread< T >::~RunThread (  )  [inline]

Definition at line 93 of file RunThread.h.

00093 {}


Member Function Documentation

template<class T >
Handle< T > Anp::RunThread< T >::GetAlg (  )  [inline]

Definition at line 147 of file RunThread.h.

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

00148    {
00149       return fAlg;
00150    }

template<class T >
int Anp::RunThread< T >::Join ( void   )  [inline]

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 [inline]

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 (  )  [inline]

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  )  [inline]

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 [inline]

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]
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 13 Dec 2018 for loon by  doxygen 1.6.1