27 #ifndef NIDAS_UTIL_THREAD_H
28 #define NIDAS_UTIL_THREAD_H
39 namespace nidas {
namespace util {
100 if (thr)
return thr->
getName();
122 Thread(
const std::string& name,
bool detached=
false);
165 virtual
int join() throw(Exception);
170 virtual
void kill(
int sig) throw(Exception);
175 virtual
void cancel() throw(Exception);
302 const std::string&
getName()
const throw();
396 static
int test(
int argc,
char** argv);
428 static void*
thr_run(
void *me);
504 static void sigAction(
int sig, siginfo_t* si,
void* vptr);
static void thr_cleanup_delete(void *me)
Definition: Thread.cc:264
Synchronized is used a simple guard object for critical sections.
Definition: ThreadSupport.h:544
void setThreadSchedulerNolock(enum SchedPolicy policy, int priority)
Definition: Thread.cc:629
bool _cancel_enabled
Definition: Thread.h:487
sigset_t _unblockedSignals
Definition: Thread.h:502
ThreadRunnable & operator=(const ThreadRunnable &)
No assignment.
void interrupt()
Interrupt this thread.
Definition: Thread.h:543
virtual int join()
The calling thread joins this thread, waiting until the thread finishes, which means either that the ...
Definition: Thread.cc:469
static void thr_cleanup(void *me)
Definition: Thread.cc:294
const std::string & getFullName()
Return a name with a bunch of descriptive fields, specifying whether it is detached, the real-time priority, etc.
Definition: Thread.cc:593
pthread_attr_t _thread_attr
Definition: Thread.h:491
virtual void kill(int sig)
Send a signal to this thread.
Definition: Thread.cc:495
bool setRealTimeFIFOPriority(int val)
Definition: Thread.cc:613
int run()
The method which will run in its own thread.
Definition: Thread.cc:666
Mutex _mutex
Mutex for accessing _id.
Definition: Thread.h:475
static int test(int argc, char **argv)
a test method.
Definition: Thread.cc:681
void registerThread()
Register this current thread with a static registry of threads by id.
Definition: Thread.cc:127
bool _cancel_deferred
Definition: Thread.h:489
const std::string & getName() const
Return the name of this thread.
Definition: Thread.cc:548
DetachedThread(const std::string &name)
Definition: Thread.h:526
static void * thr_run_detached(void *me)
Definition: Thread.cc:347
The ThreadRunnable class implements a Thread which uses a Runnable target to supply the run() method...
Definition: Thread.h:535
Runnable * _target
Definition: Thread.h:556
pthread_t _id
Definition: Thread.h:481
void unregisterThread()
Definition: Thread.cc:134
void setCancelEnabled(bool val)
Set the cancel state for this thread - false means cancel requests are ignored.
Definition: Thread.cc:521
static pthread_t currentThreadId()
Definition: Thread.cc:98
pthread_t getId() const
Definition: Thread.h:420
Thread * _thread
Definition: Thread.h:582
virtual ~Runnable()
Definition: Thread.h:44
ThreadRunnable DefaultThread
Definition: Thread.h:591
virtual void start()
Start the thread running, meaning execute the run method in a separate thread.
Definition: Thread.cc:406
ThreadJoiner & operator=(const ThreadJoiner &)
No assignment.
void setCancelDeferred(bool val)
Set the cancel type for this thread.
Definition: Thread.cc:534
void blockSignal(int)
Block a signal in this thread.
Definition: Thread.cc:211
int run()
The method which will run in its own thread.
Definition: Thread.h:548
bool _interrupted
Definition: Thread.h:485
std::string _name
Definition: Thread.h:477
Exception * _exception
Exception thrown by run method.
Definition: Thread.h:496
static std::string unknownName
Definition: Thread.h:453
virtual bool isInterrupted() const
Return true when this thread has been interrupted.
Definition: Thread.h:257
bool _detached
Definition: Thread.h:498
Definition: Exception.h:35
static void thr_add_sig(int sig)
Definition: Thread.cc:246
virtual bool isInterrupted() const =0
Has the run method been interrupted?
std::string _fullname
Definition: Thread.h:479
bool setRealTimeRoundRobinPriority(int val)
Definition: Thread.cc:607
virtual bool isJoined() const
Has this thread been joined?
Definition: Thread.h:275
sigset_t _blockedSignals
Definition: Thread.h:500
static Thread * lookupThread(pthread_t id)
Definition: Thread.cc:112
virtual int pRun()
Definition: Thread.cc:369
SchedPolicy
Definition: Thread.h:316
virtual void signalHandler(int, siginfo_t *)
Signal handler function for this thread.
Definition: Thread.h:448
static std::string getPolicyString(int policy)
Convenience function to return a string for the given scheduler policy: "Non-RT", "RT:FIFO"...
Definition: Thread.cc:554
bool isCancelEnabled() const
Return true if the cancel state of this thread is PTHREAD_CANCEL_ENABLE.
Definition: Thread.cc:531
void makeFullName()
Definition: Thread.cc:565
~ThreadJoiner()
Definition: Thread.cc:663
runStatus
Values that can be returned by run method.
Definition: Thread.h:110
virtual int run()=0
The method which will run in its own thread.
bool isCancelDeferred() const
Return true if the cancel type of this thread is PTHREAD_CANCEL_DEFERRED.
Definition: Thread.cc:544
A Thread with a constructor that sets detached=true.
Definition: Thread.h:524
ThreadJoiner(Thread *thrd)
Definition: Thread.cc:659
virtual void interrupt()=0
Interrupt this run method.
static const std::string & currentName()
Convenience routine to return the name for the current thread, or a string indicating that the name o...
Definition: Thread.h:97
ThreadRunnable(const std::string &name, Runnable *target=0)
Definition: Thread.h:538
static Thread * currentThread()
Return the thread object for the current thread.
Definition: Thread.cc:105
void testCancel() const
Check if we have been cancelled.
Definition: Thread.h:70
void setThreadScheduler(enum SchedPolicy policy, int priority)
Definition: Thread.cc:624
static void sigAction(int sig, siginfo_t *si, void *vptr)
Definition: Thread.cc:74
bool _running
Definition: Thread.h:483
bool setNonRealTimePriority()
Definition: Thread.cc:619
virtual bool amInterrupted() const
Call testCancel, and return true when this thread has been interrupted.
Definition: Thread.cc:67
virtual void interrupt()
Interrupt this thread.
Definition: Thread.cc:600
In certain situations one needs to "join oneself", which would be a deadlock.
Definition: Thread.h:573
virtual bool isDetached() const
Is this a detached thread.
Definition: Thread.h:283
void unblockSignal(int)
Install a signal handler and unblock the signal.
Definition: Thread.cc:236
static void * thr_run(void *me)
Definition: Thread.cc:317
Thread & operator=(const Thread &x)
Assignment operator not supported.
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
virtual bool isRunning() const
Is this thread running?
Definition: Thread.h:266
void unsetId()
Definition: Thread.h:506
virtual ~Thread()
Thread destructor.
Definition: Thread.cc:192
Thread(const std::string &name, bool detached=false)
Constructor for a thread, giving it a name.
Definition: Thread.cc:141
virtual void cancel()
Cancel this thread.
Definition: Thread.cc:510