27#ifndef NIDAS_UTIL_THREAD_H
28#define NIDAS_UTIL_THREAD_H
40namespace nidas {
namespace util {
52 virtual int run() = 0;
103 if (thr)
return thr->getName();
125 Thread(
const std::string& name,
bool detached=
false);
154 virtual void start();
173 virtual void kill(
int sig);
307 const std::string&
getName()
const throw();
415 static int test(
int argc,
char** argv);
447 static void*
thr_run(
void *me);
539 static void sigAction(
int sig, siginfo_t* si,
void* vptr);
A Thread with a constructor that sets detached=true.
Definition Thread.h:558
DetachedThread(const std::string &name)
Definition Thread.h:560
Definition Exception.h:35
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
virtual bool isInterrupted() const =0
Has the run method been interrupted?
virtual ~Runnable()
Definition Thread.h:45
virtual void interrupt()=0
Interrupt this run method.
void testCancel() const
Check if we have been cancelled.
Definition Thread.h:73
virtual int run()=0
The method which will run in its own thread.
virtual bool amInterrupted() const
Call testCancel, and return true when this thread has been interrupted.
Definition Thread.cc:62
Synchronized is used a simple guard object for critical sections.
Definition ThreadSupport.h:575
In certain situations one needs to "join oneself", which would be a deadlock.
Definition Thread.h:608
int run()
The method which will run in its own thread.
Definition Thread.cc:633
ThreadJoiner & operator=(const ThreadJoiner &)
No assignment.
ThreadJoiner(const ThreadJoiner &)
No copy.
~ThreadJoiner()
Definition Thread.cc:630
ThreadJoiner(Thread *thrd)
Definition Thread.cc:626
Thread * _thread
Definition Thread.h:616
The ThreadRunnable class implements a Thread which uses a Runnable target to supply the run() method.
Definition Thread.h:570
ThreadRunnable & operator=(const ThreadRunnable &)
No assignment.
Runnable * _target
Definition Thread.h:590
ThreadRunnable(const ThreadRunnable &)
No copy.
int run()
The method which will run in its own thread.
Definition Thread.h:582
void interrupt()
Interrupt this thread.
Definition Thread.h:577
ThreadRunnable(const std::string &name, Runnable *target=0)
Definition Thread.h:572
std::atomic< bool > _interrupted
Definition Thread.h:520
static void thr_cleanup(void *me)
Definition Thread.cc:264
virtual void kill(int sig)
Send a signal to this thread.
Definition Thread.cc:458
static pthread_t currentThreadId()
Definition Thread.cc:93
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:100
static void thr_add_sig(int sig)
Definition Thread.cc:216
void blockSignal(int)
Block a signal in this thread.
Definition Thread.cc:181
void registerThread()
Register this current thread with a static registry of threads by id.
Definition Thread.cc:122
void unblockSignal(int)
Install a signal handler and unblock the signal.
Definition Thread.cc:206
bool _running
Definition Thread.h:518
sigset_t _blockedSignals
Definition Thread.h:535
static Thread * lookupThread(pthread_t id)
Definition Thread.cc:107
void setCancelDeferred(bool val)
Set the cancel type for this thread.
Definition Thread.cc:497
virtual void interrupt()
Interrupt this thread.
Definition Thread.cc:563
void setCancelEnabled(bool val)
Set the cancel state for this thread - false means cancel requests are ignored.
Definition Thread.cc:484
virtual void start()
Start the thread running, meaning execute the run method in a separate thread.
Definition Thread.cc:375
bool _cancel_deferred
Definition Thread.h:524
virtual bool isJoined() const
Has this thread been joined?
Definition Thread.h:280
Mutex _mutex
Mutex for accessing _id.
Definition Thread.h:510
SchedPolicy _policy
Definition Thread.h:532
Thread(const std::string &name, bool detached=false)
Constructor for a thread, giving it a name.
Definition Thread.cc:136
virtual ~Thread()
Thread destructor.
Definition Thread.cc:163
int _priority
Definition Thread.h:533
virtual void signalHandler(int, siginfo_t *)
Signal handler function for this thread.
Definition Thread.h:467
virtual int pRun()
Definition Thread.cc:339
const std::string & getName() const
Return the name of this thread.
Definition Thread.cc:511
static Thread * currentThread()
Return the thread object for the current thread.
Definition Thread.cc:100
bool setNonRealTimePriority()
Definition Thread.cc:582
static void thr_cleanup_delete(void *me)
Definition Thread.cc:234
virtual bool isRunning() const
Is this thread running?
Definition Thread.h:271
pthread_t getId() const
Definition Thread.h:439
static void * thr_run_detached(void *me)
Definition Thread.cc:317
runStatus
Values that can be returned by run method.
Definition Thread.h:113
@ NOT_RUNNING
Definition Thread.h:113
@ RUN_CANCELED
Definition Thread.h:113
@ RUN_OK
Definition Thread.h:113
@ RUN_EXCEPTION
Definition Thread.h:113
bool _detached
Definition Thread.h:531
void unsetId()
Definition Thread.h:541
virtual int join()
The calling thread joins this thread, waiting until the thread finishes, which means either that the ...
Definition Thread.cc:432
virtual bool isInterrupted() const
Return true when this thread has been interrupted.
Definition Thread.h:262
Thread(const Thread &x)=delete
static void sigAction(int sig, siginfo_t *si, void *vptr)
Definition Thread.cc:69
const std::string & getFullName()
Return a name with a bunch of descriptive fields, specifying whether it is detached,...
Definition Thread.cc:556
static std::string unknownName
Definition Thread.h:472
SchedPolicy
Definition Thread.h:321
@ NU_THREAD_OTHER
Definition Thread.h:321
@ NU_THREAD_FIFO
Definition Thread.h:322
@ NU_THREAD_RR
Definition Thread.h:322
void unregisterThread()
Definition Thread.cc:129
virtual void cancel()
Cancel this thread.
Definition Thread.cc:473
bool setRealTimeRoundRobinPriority(int val)
Definition Thread.cc:570
std::string _name
Definition Thread.h:512
void makeFullName()
Definition Thread.cc:528
static int test(int argc, char **argv)
a test method.
Definition Thread.cc:648
bool setRealTimeFIFOPriority(int val)
Definition Thread.cc:576
Thread & operator=(const Thread &x)=delete
Copy and assignment not needed so not supported.
pthread_t _id
Definition Thread.h:516
bool isCancelDeferred() const
Return true if the cancel type of this thread is PTHREAD_CANCEL_DEFERRED.
Definition Thread.cc:507
virtual bool isDetached() const
Is this a detached thread.
Definition Thread.h:288
sigset_t _unblockedSignals
Definition Thread.h:537
void setThreadSchedulerNolock()
If the thread is running, set the scheduling policy according to the current policy and priority attr...
Definition Thread.cc:599
void setThreadScheduler(enum SchedPolicy policy, int priority)
Definition Thread.cc:587
static std::string getPolicyString(int policy)
Convenience function to return a string for the given scheduler policy: "Non-RT", "RT:FIFO",...
Definition Thread.cc:517
bool _cancel_enabled
Definition Thread.h:522
bool isCancelEnabled() const
Return true if the cancel state of this thread is PTHREAD_CANCEL_ENABLE.
Definition Thread.cc:494
std::string _fullname
Definition Thread.h:514
Exception * _exception
Exception thrown by run method.
Definition Thread.h:529
static void * thr_run(void *me)
Definition Thread.cc:287
ThreadRunnable DefaultThread
Definition Thread.h:625
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31