LRAUV  revA
ThreadHandler.h
Go to the documentation of this file.
1 
9 #ifndef THREADHANDLER_H_
10 #define THREADHANDLER_H_
11 
12 #include <pthread.h>
13 #include "Handler.h"
14 #include "utils/Mutex.h"
15 
25 class ThreadHandler : public Handler
26 {
27 public:
28 
29  static int PthreadJoinTimeout( pthread_t wid, unsigned int msecs, Component &component );
30 
36  ThreadHandler( Component &inComponent, const Str& name, bool idleThread );
37 
39  virtual ~ThreadHandler();
40 
43  virtual void run();
44 
46  static void *ThreadEntryPoint( void *me );
47 
49  static void ThreadCleanup( void *me );
50 
52  void cleanup( void );
53 
57  virtual void runInThread();
58 
60  virtual bool continueLoop( void );
61 
63  virtual void shutdown( void );
64 
65  //=== Functions primarily for running within the thread ===
66 
68  void exitThread( void );
69 
70  //=== Functions primarily for running _outside_ the thread ===
71 
73  void cancelThread( void );
74 
76  void joinThread( void );
77 
79  void killThread( void );
80 
81  const pthread_t& getThreadId()
82  {
83  return threadID_;
84  }
85 
86 protected:
87 
89  bool cancelled_;
90 
91 private:
92 
93  //bool running;
94  //Mutex runningMutex;
95 
97  pthread_t threadID_;
98 
100  pthread_attr_t threadAttributes_;
101 
102 };
103 
104 #endif /*THREADHANDLER_H_*/
A ThreadHandler is a Handler which runs in its own thread.
Definition: ThreadHandler.h:25
void cancelThread(void)
A "soft exit", requests the thread end on next loop.
Definition: ThreadHandler.cpp:235
bool cancelled_
Keeps track of the "cancelled" signal from cancelThread.
Definition: ThreadHandler.h:89
virtual void run()
Overrides Handler::run().
Definition: ThreadHandler.cpp:114
virtual void runInThread()
The new replacement for Handler::run() which runs in the thread., Run from the static threadEntryPoin...
Definition: ThreadHandler.cpp:145
static int PthreadJoinTimeout(pthread_t wid, unsigned int msecs, Component &component)
Definition: ThreadHandler.cpp:56
ThreadHandler(Component &inComponent, const Str &name, bool idleThread)
Constructor.
Definition: ThreadHandler.cpp:92
virtual bool continueLoop(void)
Evaluates additional thread-specific continue conditions.
Definition: ThreadHandler.cpp:168
static void ThreadCleanup(void *me)
A static entry point for a cleanup callback.
Definition: ThreadHandler.cpp:176
pthread_t threadID_
The thread ID.
Definition: ThreadHandler.h:97
Replacement for standard template class string.
Definition: Str.h:12
const pthread_t & getThreadId()
Definition: ThreadHandler.h:81
void joinThread(void)
Join the thread.
Definition: ThreadHandler.cpp:243
Base class for "handlers" of Components.
Definition: Handler.h:49
void cleanup(void)
A member function for the cleanup callback (called from threadCleanup)
Definition: ThreadHandler.cpp:184
Abstract Base class for software components.
Definition: Component.h:53
Contains the Mutex, ThreadCondition, and MutexLocker class declarations.
Contains the Handler class declaration.
static void * ThreadEntryPoint(void *me)
The entry point for the new thread. A static function.
Definition: ThreadHandler.cpp:128
virtual ~ThreadHandler()
Destructor.
Definition: ThreadHandler.cpp:100
pthread_attr_t threadAttributes_
the thread attributes
Definition: ThreadHandler.h:100
virtual void shutdown(void)
Cleanup the component (typically called from outside component)
Definition: ThreadHandler.cpp:194
void killThread(void)
End the thread immediately (uses pthread_cancel)
Definition: ThreadHandler.cpp:267
void exitThread(void)
Called by the thread to end itself (pthread_Exit)
Definition: ThreadHandler.cpp:216