nidas v1.2.3
|
Interface for a Thread for buffering samples. More...
#include <SampleThread.h>
Public Types | |
enum | runStatus { RUN_CANCELED = -1 , RUN_OK = 0 , NOT_RUNNING = 1 , RUN_EXCEPTION = 2 } |
Values that can be returned by run method. More... | |
enum | SchedPolicy { NU_THREAD_OTHER =SCHED_OTHER , NU_THREAD_FIFO =SCHED_FIFO , NU_THREAD_RR =SCHED_RR } |
Public Member Functions | |
SampleThread (const std::string &name) | |
virtual | ~SampleThread () |
virtual void | flush () throw () =0 |
Both SampleClient and SampleSource have a flush() method. | |
virtual void | setKeepStats (bool val)=0 |
virtual bool | getKeepStats () const =0 |
virtual size_t | size () const =0 |
Number of samples that have not be distributed. | |
virtual void | setLengthSecs (float val)=0 |
virtual float | getLengthSecs () const =0 |
virtual void | setHeapMax (size_t val)=0 |
Set the maximum amount of heap memory to use for sorting samples. | |
virtual size_t | getHeapMax () const =0 |
virtual size_t | getHeapSize () const =0 |
Get the current amount of heap being used for sorting. | |
virtual void | setHeapBlock (bool val)=0 |
virtual bool | getHeapBlock () const =0 |
virtual size_t | getNumDiscardedSamples () const =0 |
Number of samples discarded because of _heapSize > _heapMax and heapBlock == true. | |
virtual size_t | getNumFutureSamples () const =0 |
Number of samples discarded because their timetags were in the future. | |
virtual void | setRealTime (bool val)=0 |
Is this thread running in real-time, meaning is it handling recently sampled data? If so then we can screen for bad sample time-tags by checking against the system clock, which is trusted. | |
virtual bool | getRealTime () const =0 |
virtual void | setLateSampleCacheSize (unsigned int val)=0 |
virtual unsigned int | getLateSampleCacheSize () const =0 |
virtual void | start () |
Start the thread running, meaning execute the run method in a separate thread. | |
virtual int | join () |
The calling thread joins this thread, waiting until the thread finishes, which means either that the run() method returned, the thread called pthread_exit() or the thread was cancelled. | |
virtual void | kill (int sig) |
Send a signal to this thread. | |
virtual void | cancel () |
Cancel this thread. | |
virtual void | interrupt () |
Interrupt this thread. | |
virtual bool | isInterrupted () const |
Return true when this thread has been interrupted. | |
virtual bool | isRunning () const |
Is this thread running? | |
virtual bool | isJoined () const |
Has this thread been joined? | |
virtual bool | isDetached () const |
Is this a detached thread. | |
bool | isCancelEnabled () const |
Return true if the cancel state of this thread is PTHREAD_CANCEL_ENABLE. | |
bool | isCancelDeferred () const |
Return true if the cancel type of this thread is PTHREAD_CANCEL_DEFERRED. | |
const std::string & | getName () const throw () |
Return the name of this thread. | |
const std::string & | getFullName () throw () |
Return a name with a bunch of descriptive fields, specifying whether it is detached, the real-time priority, etc. | |
bool | setRealTimeRoundRobinPriority (int val) |
bool | setRealTimeFIFOPriority (int val) |
bool | setNonRealTimePriority () |
void | setThreadScheduler (enum SchedPolicy policy, int priority) |
void | blockSignal (int) |
Block a signal in this thread. | |
void | unblockSignal (int) |
Install a signal handler and unblock the signal. | |
virtual int | run ()=0 |
The method which will run in its own thread. | |
virtual bool | receive (const Sample *s)=0 |
Method called to pass a sample to this client. | |
virtual SampleSource * | getRawSampleSource ()=0 |
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples. | |
virtual SampleSource * | getProcessedSampleSource ()=0 |
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples. | |
virtual void | addSampleTag (const SampleTag *)=0 |
Add a SampleTag to this SampleSource. | |
virtual void | removeSampleTag (const SampleTag *)=0 |
virtual std::list< const SampleTag * > | getSampleTags () const =0 |
What SampleTags am I a SampleSource for? | |
virtual SampleTagIterator | getSampleTagIterator () const =0 |
virtual void | addSampleClient (SampleClient *c)=0 |
Add a SampleClient of all Samples to this SampleSource. | |
virtual void | removeSampleClient (SampleClient *c)=0 |
Remove a SampleClient from this SampleSource. | |
virtual void | addSampleClientForTag (SampleClient *c, const SampleTag *)=0 |
Add a SampleClient to this SampleSource. | |
virtual void | removeSampleClientForTag (SampleClient *c, const SampleTag *)=0 |
Remove a SampleClient for a given SampleTag from this SampleSource. | |
virtual int | getClientCount () const =0 |
How many SampleClients are currently in my list. | |
virtual const SampleStats & | getSampleStats () const =0 |
Static Public Member Functions | |
static Thread * | currentThread () |
Return the thread object for the current thread. | |
static pthread_t | currentThreadId () |
static Thread * | lookupThread (pthread_t id) |
static const std::string & | currentName () |
Convenience routine to return the name for the current thread, or a string indicating that the name of the thread is unknown. | |
static std::string | getPolicyString (int policy) |
Convenience function to return a string for the given scheduler policy: "Non-RT", "RT:FIFO", "RT:RR" or "RT:Unknown". | |
static int | test (int argc, char **argv) |
a test method. | |
Protected Member Functions | |
void | setCancelEnabled (bool val) |
Set the cancel state for this thread - false means cancel requests are ignored. | |
void | setCancelDeferred (bool val) |
Set the cancel type for this thread. | |
pthread_t | getId () const |
void | testCancel () const |
Check if we have been cancelled. | |
virtual bool | amInterrupted () const |
Call testCancel, and return true when this thread has been interrupted. | |
Private Member Functions | |
virtual void | signalHandler (int, siginfo_t *) |
Signal handler function for this thread. | |
virtual int | pRun () |
void | setThreadSchedulerNolock (enum SchedPolicy policy, int priority) |
Set the scheduler policy and priority for this thread, then call setThreadSchedulerNolock() to effect the settings if the thread is running. | |
void | setThreadSchedulerNolock () |
If the thread is running, set the scheduling policy according to the current policy and priority attributes in this Thread. | |
void | makeFullName () |
void | registerThread () |
Register this current thread with a static registry of threads by id. | |
void | unregisterThread () |
void | unsetId () |
Static Private Member Functions | |
static void * | thr_run (void *me) |
static void * | thr_run_detached (void *me) |
static void | thr_cleanup (void *me) |
static void | thr_cleanup_delete (void *me) |
static void | thr_add_sig (int sig) |
static void | sigAction (int sig, siginfo_t *si, void *vptr) |
Private Attributes | |
Mutex | _mutex |
Mutex for accessing _id. | |
std::string | _name |
std::string | _fullname |
pthread_t | _id |
bool | _running |
std::atomic< bool > | _interrupted |
bool | _cancel_enabled |
bool | _cancel_deferred |
Exception * | _exception |
Exception thrown by run method. | |
bool | _detached |
SchedPolicy | _policy |
int | _priority |
sigset_t | _blockedSignals |
sigset_t | _unblockedSignals |
Static Private Attributes | |
static std::string | unknownName = std::string("unknown") |
Interface for a Thread for buffering samples.
Samples are received by the SampleClient side of this interface. The SampleSource side runs in a separate thread, sending out samples when they are ready. This interface can be inplemented by a SampleSorter if time-sorting is desired, or by a simple FIFO buffer. Either implementation provides thread separation where the thread using the SampleClient side could run as a high-priority real-time thread, doing time-critical time-tagging and acquisition, and the SampleSource runs as a normal-priority thread, doing less time-critical things like post-processing, or sample archiving.
|
inherited |
Values that can be returned by run method.
User can define other values greater than RUN_EXCEPTION. These values are then returned by int join()
. Note that PTHREAD_CANCELLED is -1
Enumerator | |
---|---|
RUN_CANCELED | |
RUN_OK | |
NOT_RUNNING | |
RUN_EXCEPTION |
|
inherited |
|
inline |
|
inlinevirtual |
|
pure virtualinherited |
Add a SampleClient of all Samples to this SampleSource.
The pointer to the SampleClient must remain valid, until after it is removed.
)
Implemented in nidas::dynld::SampleInputStream, nidas::core::DSMSensor, nidas::core::SampleSourceSupport, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::dynld::raf::SyncRecordGenerator, nidas::dynld::raf::SyncRecordSource, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::dynld::AsciiOutput::connect(), nidas::core::SampleArchiver::connect(), nidas::dynld::SampleProcessor::connect(), nidas::core::SampleArchiver::connectSource(), and nidas::dynld::SampleProcessor::connectSource().
|
pure virtualinherited |
Add a SampleClient to this SampleSource.
The pointer to the SampleClient must remain valid, until after it is removed.
)
Implemented in nidas::dynld::SampleInputStream, nidas::core::SamplePipeline, nidas::core::SampleSourceSupport, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::dynld::raf::SyncRecordSource, nidas::dynld::StatisticsCruncher, nidas::core::DSMSensor, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SampleSorter, and nidas::dynld::raf::SyncRecordGenerator.
Referenced by nidas::dynld::StatisticsCruncher::attach(), nidas::dynld::raf::CVIProcessor::attachLVInput(), nidas::core::NearestResamplerAtRate::connect(), nidas::core::SampleAverager::connect(), and nidas::core::NearestResampler::connect().
Add a SampleTag to this SampleSource.
This SampleSource does not own the SampleTag.
nidas::util::InvalidParameterException |
Implemented in nidas::dynld::SampleInputStream, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordSource, nidas::dynld::StatisticsCruncher, and nidas::core::DSMSensor.
Referenced by nidas::core::SamplePipeline::addSampleTag(), and nidas::dynld::RawSampleService::schedule().
|
protectedvirtualinherited |
Call testCancel, and return true when this thread has been interrupted.
This is protected because it should only called within the run method of the thread.
References nidas::util::Runnable::isInterrupted(), and nidas::util::Runnable::testCancel().
Referenced by nidas::core::Looper::run(), nidas::core::SampleOutputRequestThread::run(), and nidas::core::DSMServerStat::run().
|
inherited |
Block a signal in this thread.
This method is usually called before this Thread has started. If this Thread is currently running, then this method is only effective if called from this Thread, i.e. from its own run() method.
Because SIGINT, SIGTERM and SIGHUP are typically caught in the main thread, they are blocked by default in a Thread. Call unblockSignal(sig) if you want to catch them in a Thread.
References nidas::util::Thread::_blockedSignals, nidas::util::Thread::_unblockedSignals, nidas::util::Thread::currentThread(), nidas::util::Thread::isRunning(), and nidas::util::Thread::thr_add_sig().
Referenced by nidas::dynld::UDPSampleOutput::ConnectionMonitor::ConnectionMonitor(), nidas::core::ServerSocket::ConnectionThread::ConnectionThread(), nidas::core::DerivedDataReader::DerivedDataReader(), nidas::util::McSocketListener::McSocketListener(), nidas::util::McSocketMulticaster< SocketTT >::McSocketMulticaster(), nidas::core::SensorHandler::SensorHandler(), nidas::core::SensorOpener::SensorOpener(), nidas::dynld::RawSampleService::Worker::Worker(), nidas::core::XmlRpcThread::XmlRpcThread(), and nidas::dynld::UDPSampleOutput::XMLSocketListener::XMLSocketListener().
|
virtualinherited |
Cancel this thread.
Exception |
References nidas::util::Thread::_id, nidas::util::Thread::_mutex, nidas::util::Exception::errnoToString(), and nidas::util::Thread::getName().
Convenience routine to return the name for the current thread, or a string indicating that the name of the thread is unknown.
References nidas::util::Thread::currentThread(), and nidas::util::Thread::unknownName.
Referenced by nidas::util::Logger::msg().
|
staticinherited |
Return the thread object for the current thread.
Returns null if not found.
References nidas::util::Thread::currentThreadId(), and nidas::util::Thread::lookupThread().
Referenced by nidas::util::Thread::blockSignal(), nidas::util::Thread::currentName(), nidas::util::Thread::sigAction(), and nidas::util::Thread::unblockSignal().
|
staticinherited |
Referenced by nidas::util::Thread::currentThread(), and nidas::util::Thread::sigAction().
Both SampleClient and SampleSource have a flush() method.
Redeclaring it here as pure virtual removes the ambiguity.
Implements nidas::core::SampleClient.
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::flush().
How many SampleClients are currently in my list.
)
Implemented in nidas::core::DSMSensor, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordGenerator, nidas::dynld::raf::SyncRecordSource, nidas::dynld::SampleInputStream, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::core::SamplePipeline::getClientCount().
|
inherited |
Return a name with a bunch of descriptive fields, specifying whether it is detached, the real-time priority, etc.
References nidas::util::Thread::_fullname.
Referenced by nidas::util::Thread::pRun().
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Get the current amount of heap being used for sorting.
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::getSorterNumProcBytes(), and nidas::core::SamplePipeline::getSorterNumRawBytes().
|
inlineprotectedinherited |
References nidas::util::Thread::_id, and nidas::util::Thread::_mutex.
Referenced by nidas::util::Thread::isJoined(), nidas::util::Thread::join(), and nidas::core::Looper::removeClient().
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
|
inherited |
Return the name of this thread.
References nidas::util::Thread::_name.
Referenced by nidas::util::Thread::cancel(), nidas::core::SensorHandler::PolledDSMSensor::checkTimeout(), nidas::core::SensorHandler::PolledDSMSensor::close(), nidas::core::SensorHandler::PolledDSMSensor::handlePollEvents(), nidas::core::SampleSorter::heapDecrement(), nidas::core::XmlRpcThread::interrupt(), nidas::core::SamplePipeline::join(), nidas::util::Thread::join(), nidas::util::Thread::kill(), nidas::core::FsMountWorkerThread::run(), nidas::core::SampleSorter::run(), nidas::util::ThreadJoiner::run(), nidas::util::Thread::setThreadSchedulerNolock(), nidas::util::Thread::start(), nidas::core::SampleSorter::~SampleSorter(), and nidas::util::Thread::~Thread().
Number of samples discarded because of _heapSize > _heapMax and heapBlock == true.
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::getNumDiscardedProcSamples(), and nidas::core::SamplePipeline::getNumDiscardedRawSamples().
Number of samples discarded because their timetags were in the future.
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::getNumFutureProcSamples(), and nidas::core::SamplePipeline::getNumFutureRawSamples().
|
staticinherited |
Convenience function to return a string for the given scheduler policy: "Non-RT", "RT:FIFO", "RT:RR" or "RT:Unknown".
References nidas::util::Thread::NU_THREAD_FIFO, nidas::util::Thread::NU_THREAD_OTHER, and nidas::util::Thread::NU_THREAD_RR.
Referenced by nidas::util::Thread::makeFullName().
|
pure virtualinherited |
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
SampleClients use this method to get a pointer to whatever sample source they are interested in. Derived classes can return NULL if they are not a SampleSource of processed samples.
Implemented in nidas::core::DSMSensor, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordSource, nidas::dynld::SampleInputStream, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::core::SampleArchiver::connectSource(), nidas::dynld::raf::CVIProcessor::connectSource(), nidas::dynld::SampleProcessor::connectSource(), nidas::dynld::StatisticsProcessor::connectSource(), and nidas::core::SampleArchiver::disconnectSource().
|
pure virtualinherited |
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
SampleClients use this method to get a pointer to whatever sample source they are interested in. Derived classes can return NULL if they are not a SampleSource of raw samples.
Implemented in nidas::core::DSMSensor, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordSource, nidas::dynld::SampleInputStream, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::core::SamplePipeline::connect(), nidas::core::SampleArchiver::connectSource(), nidas::core::SamplePipeline::disconnect(), and nidas::core::SampleArchiver::disconnectSource().
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
|
pure virtualinherited |
Implemented in nidas::core::DSMSensor, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordGenerator, nidas::dynld::raf::SyncRecordSource, nidas::dynld::SampleInputStream, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::core::SamplePipeline::getSampleStats(), nidas::core::SampleArchiver::printStatus(), nidas::dynld::raf::SyncRecordGenerator::printStatus(), and nidas::dynld::RawSampleService::printStatus().
|
pure virtualinherited |
Implemented in nidas::core::DSMSensor, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordGenerator, nidas::dynld::raf::SyncRecordSource, nidas::dynld::SampleInputStream, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::dynld::StatisticsCruncher::connect(), nidas::dynld::raf::CVIProcessor::connectSource(), and nidas::core::SamplePipeline::getSampleTagIterator().
|
pure virtualinherited |
What SampleTags am I a SampleSource for?
Implemented in nidas::core::DSMSensor, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordGenerator, nidas::dynld::raf::SyncRecordSource, nidas::dynld::SampleInputStream, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::dynld::StatisticsCruncher::attach(), nidas::core::NearestResamplerAtRate::connect(), nidas::core::SampleAverager::connect(), nidas::core::NearestResampler::connect(), nidas::core::SampleArchiver::connectSource(), nidas::dynld::SampleProcessor::connectSource(), nidas::dynld::StatisticsProcessor::connectSource(), nidas::core::SamplePipeline::getSampleTags(), and nidas::dynld::RawSampleService::schedule().
|
virtualinherited |
Interrupt this thread.
This sets a boolean which can be tested with isInterrupted(). It is up to the run() implementation to return when interrupted. This is a "soft" request to terminate the thread.
What follows is a discussion of when to use cancel(), kill(), or interrupt() to terminate a thread.
If you can consistently check the state of isInterrupted() in the run method, and return if it is true, at a time interval which is an acceptable amount of time to wait for the thread to terminate, then using interrupt() should work well.
If the run method does I/O, then things are usually a bit more complicated.
If all I/O is guaranteed to finish quickly, which is a rare situation, or is done with a timeout, such as using select/poll with a timeout before every read/write, then one could still use interrupt() as above, and the thread will terminate within the timeout period.
If the thread does blocking I/O operations, and the I/O might block for a period of time longer than you're willing to wait for the thread to terminate, then you need to use kill(sig) or cancel().
If a signal is sent to the thread with kill(sig) while the thread is blocking on an I/O operation, the I/O will immediately return with an errno of EINTR, and one could then return from the run method, after any necessary cleanup.
However there is a possibility that the signal could be missed. In order to make sure you receive a signal, you must block it, so that any received signals are held as pending, and then atomically unblock it with pselect/ppoll/epoll_pwait before performing the I/O operation.
If you do not use I/O timeouts, or kill(sig) with pselect/ppoll/epoll_pwait, or other tricks such as writing to a pipe that is watched with select/poll in the run method, then using cancel() is the only way to guarantee that your thread will terminate in an acceptable amount of time.
All NIDAS Threads support deferred cancelation. Immediate asynchronous cancellation is not fully supported (and is very hard to get right). Deferred cancelation means that cancellation is delayed until the thread next calls a system function that is a cancellation point. At that point the thread run method will simply terminate without any return value from the system function, and then execute any cleanup methods that may have been registered with pthread_cleanup_push.
A list of cancellation points is provided in the pthreads(7) man page. Cancellation points are typically I/O operations, waits or sleeps.
This immediate thread termination can be a problem if there is a possibility that your objects could be left in a bad state, such as with a mutex locked, though it isn't generally a good practice to hold mutexes during a time-consuming I/O operation, wait or sleep.
One should check the run method to see if the state of the objects is OK if execution stops at any of the cancellation points. Note that logging a message, or writing to cerr is a cancellation point. Typically there is error/exception handling associated with an I/O operation. Ensuring the state is OK upon a cancellation is similar to preparation for a fatal I/O error that requires a return of the run method. One can use setCancelEnabled() to defer cancellation.
One can use pthread_cleanup_push and pthread_cleanup_pop to register cleanup routines that are called when a thread is cancelled if special handling is required.
Implements nidas::util::Runnable.
Reimplemented in nidas::core::DerivedDataReader, nidas::core::SampleBuffer, nidas::core::SampleOutputRequestThread, nidas::core::SampleSorter, nidas::core::SensorHandler, nidas::core::SensorOpener, nidas::core::Socket::ConnectionThread, nidas::core::ServerSocket::ConnectionThread, nidas::core::XmlRpcThread, nidas::dynld::raf::SyncServer, nidas::dynld::RawSampleService::Worker, nidas::dynld::UDPSampleOutput::VariableListWorker, nidas::dynld::UDPSampleOutput::XMLSocketListener, nidas::dynld::XMLConfigService::Worker, nidas::util::McSocketListener, nidas::util::McSocketMulticaster< SocketTT >, and nidas::util::ThreadRunnable.
References nidas::util::Thread::_interrupted, and nidas::util::Thread::_mutex.
Referenced by nidas::dynld::UDPSampleOutput::close(), nidas::core::DSMEngine::interrupt(), nidas::core::SamplePipeline::interrupt(), nidas::util::McSocketListener::interrupt(), nidas::core::SamplePipeline::join(), nidas::core::Looper::removeClient(), and nidas::dynld::UDPSampleOutput::~UDPSampleOutput().
|
inherited |
Return true if the cancel type of this thread is PTHREAD_CANCEL_DEFERRED.
References nidas::util::Thread::_cancel_deferred.
|
inherited |
Return true if the cancel state of this thread is PTHREAD_CANCEL_ENABLE.
References nidas::util::Thread::_cancel_enabled.
Is this a detached thread.
References nidas::util::Thread::_detached.
Return true when this thread has been interrupted.
Implements nidas::util::Runnable.
References nidas::util::Thread::_interrupted, and nidas::util::Thread::_mutex.
Referenced by nidas::core::SampleSorter::flush(), nidas::dynld::raf::SyncServer::read(), ServerThread::run(), Sender::run(), ModemLineSetter::run(), ModemLineMonitor::run(), nidas::core::DerivedDataReader::run(), nidas::core::FsMountWorkerThread::run(), nidas::core::SampleBuffer::run(), nidas::core::SampleOutputRequestThread::run(), nidas::core::SampleSorter::run(), nidas::core::SensorHandler::run(), nidas::core::SensorOpener::run(), nidas::core::StatusListener::run(), nidas::core::DSMEngineStat::run(), nidas::util::McSocketListener::run(), and nidas::dynld::raf::SyncServer::stop().
Has this thread been joined?
References nidas::util::Thread::getId().
Referenced by nidas::core::FsMount::cancel(), nidas::core::SensorHandler::join(), nidas::core::SampleBuffer::~SampleBuffer(), nidas::core::SampleSorter::~SampleSorter(), and nidas::util::Thread::~Thread().
Is this thread running?
References nidas::util::Thread::_mutex, and nidas::util::Thread::_running.
Referenced by nidas::util::Thread::blockSignal(), nidas::core::FsMount::cancel(), nidas::dynld::UDPSampleOutput::XMLSocketListener::checkWorkers(), nidas::dynld::UDPSampleOutput::close(), nidas::core::SamplePipeline::join(), nidas::core::DSMServerApp::killStatusThread(), nidas::core::Looper::removeClient(), nidas::core::ServerSocket::requestConnection(), nidas::core::SensorHandler::run(), nidas::core::Looper::setupClientMaps(), nidas::util::Thread::unblockSignal(), nidas::core::SampleBuffer::~SampleBuffer(), nidas::core::SampleSorter::~SampleSorter(), nidas::util::Thread::~Thread(), and nidas::dynld::UDPSampleOutput::~UDPSampleOutput().
|
virtualinherited |
The calling thread joins this thread, waiting until the thread finishes, which means either that the run() method returned, the thread called pthread_exit() or the thread was cancelled.
The return value is the int return value of the run method, or PTHREAD_CANCELED (-1). If the run method threw an Exception, it will be caught and then re-thrown by join.
Exception |
Reimplemented in nidas::core::SensorHandler.
References nidas::util::Thread::_exception, nidas::util::Thread::_id, nidas::util::Thread::_mutex, nidas::util::Exception::errnoToString(), nidas::util::Thread::getId(), nidas::util::Thread::getName(), nidas::util::Thread::RUN_EXCEPTION, and nidas::util::Thread::RUN_OK.
Referenced by nidas::dynld::UDPSampleOutput::XMLSocketListener::checkWorkers(), nidas::dynld::UDPSampleOutput::close(), nidas::dynld::UDPSampleOutput::XMLSocketListener::fireWorkers(), nidas::core::SamplePipeline::join(), nidas::core::SensorHandler::join(), nidas::core::DSMEngine::joinDataThreads(), nidas::core::DSMServerApp::killStatusThread(), nidas::core::DSMEngine::killXmlRpcThread(), nidas::core::DSMServerApp::killXmlRpcThread(), nidas::core::Looper::removeClient(), nidas::util::ThreadJoiner::run(), nidas::core::SampleBuffer::~SampleBuffer(), nidas::core::SampleSorter::~SampleSorter(), nidas::core::ServerSocket::~ServerSocket(), and nidas::dynld::UDPSampleOutput::~UDPSampleOutput().
|
virtualinherited |
Send a signal to this thread.
Exception |
References nidas::util::Thread::_id, nidas::util::Thread::_mutex, nidas::util::Exception::errnoToString(), and nidas::util::Thread::getName().
Referenced by nidas::core::FsMount::cancel(), nidas::core::DerivedDataReader::interrupt(), nidas::core::SensorHandler::interrupt(), nidas::core::SensorOpener::interrupt(), nidas::core::XmlRpcThread::interrupt(), nidas::util::McSocketListener::interrupt(), nidas::core::DSMServerApp::killStatusThread(), nidas::core::SensorHandler::scheduleAdd(), nidas::core::SensorHandler::scheduleClose(), nidas::core::SensorHandler::scheduleClose(), nidas::core::SensorHandler::scheduleReopen(), and nidas::core::SensorHandler::sensorIsOpen().
|
staticinherited |
Referenced by nidas::util::Thread::currentThread(), and nidas::util::LogContextState::threadName().
|
privateinherited |
|
privatevirtualinherited |
References nidas::util::Thread::_blockedSignals, nidas::util::Thread::_exception, nidas::util::Thread::_mutex, nidas::util::Thread::_unblockedSignals, nidas::util::Exception::clone(), nidas::util::Thread::getFullName(), ILOG, nidas::util::Mutex::lock(), nidas::util::Runnable::run(), nidas::util::Thread::RUN_EXCEPTION, nidas::util::Thread::setThreadSchedulerNolock(), and nidas::util::Mutex::unlock().
Method called to pass a sample to this client.
This method is typically called by a SampleSource for each of its SampleClients when it has a sample ready. Returns true: success false: sample rejected. This is meant to signal a warning-type situation - like a socket not being available temporarily. True errors will be thrown as an IOException.
)
Implemented in nidas::dynld::UDPSampleOutput, nidas::dynld::raf::SyncRecordSource, TestClient, nidas::core::DSMSensor, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::RemoteSerialConnection, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleOutputBase, nidas::core::SampleSorter, nidas::dynld::raf::CVIProcessor, nidas::dynld::raf::SyncRecordReader, nidas::dynld::SampleOutputStream, nidas::dynld::StatisticsCruncher, DumpClient, SampleDispatcher, DataStats, DumpClient, nidas::dynld::AsciiOutput, and nidas::dynld::raf::CVIOutput.
|
privateinherited |
Register this current thread with a static registry of threads by id.
Thread::registerThread (new Thread ("Main"));
References nidas::util::Thread::_id.
Referenced by nidas::util::Thread::start().
|
pure virtualinherited |
Remove a SampleClient from this SampleSource.
)
Implemented in nidas::dynld::SampleInputStream, nidas::core::DSMSensor, nidas::core::SampleSourceSupport, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::dynld::raf::SyncRecordGenerator, nidas::dynld::raf::SyncRecordSource, and nidas::dynld::StatisticsCruncher.
Referenced by nidas::core::RemoteSerialConnection::close(), nidas::core::DSMEngine::closeOutputs(), nidas::core::SampleArchiver::disconnect(), nidas::dynld::SampleProcessor::disconnect(), nidas::core::SampleArchiver::~SampleArchiver(), and nidas::dynld::SampleProcessor::~SampleProcessor().
|
pure virtualinherited |
Remove a SampleClient for a given SampleTag from this SampleSource.
The pointer to the SampleClient must remain valid, until after it is removed.
)
Implemented in nidas::dynld::SampleInputStream, nidas::core::SamplePipeline, nidas::core::SampleSourceSupport, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::dynld::raf::SyncRecordSource, nidas::dynld::StatisticsCruncher, nidas::core::DSMSensor, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SampleSorter, and nidas::dynld::raf::SyncRecordGenerator.
)
Implemented in nidas::dynld::SampleInputStream, nidas::core::NearestResampler, nidas::core::NearestResamplerAtRate, nidas::core::SampleAverager, nidas::core::SampleBuffer, nidas::core::SampleIOProcessor, nidas::core::SamplePipeline, nidas::core::SampleSorter, nidas::core::SampleSourceSupport, nidas::dynld::raf::SyncRecordSource, nidas::dynld::StatisticsCruncher, and nidas::core::DSMSensor.
Referenced by nidas::core::SamplePipeline::removeSampleTag().
The method which will run in its own thread.
This method must be supplied by the Runnable or Thread subclass.
Exception |
Implemented in WriterThread, ServerThread, DataWriter, PSI, TestSource, Sender, ModemLineSetter, ModemLineMonitor, nidas::core::DerivedDataReader, nidas::core::DSMEngineIntf, nidas::core::DSMServerIntf, nidas::core::FsMountWorkerThread, nidas::core::Looper, nidas::core::SampleBuffer, nidas::core::SampleOutputRequestThread, nidas::core::SampleSorter, nidas::core::SensorHandler, nidas::core::SensorOpener, nidas::core::Socket::ConnectionThread, nidas::core::ServerSocket::ConnectionThread, nidas::core::StatusListener, nidas::core::DSMEngineStat, nidas::core::DSMServerStat, nidas::dynld::raf::SyncServer, nidas::dynld::RawSampleService::Worker, nidas::dynld::UDPSampleOutput::VariableListWorker, nidas::dynld::UDPSampleOutput::ConnectionMonitor, nidas::dynld::UDPSampleOutput::XMLSocketListener, nidas::dynld::XMLConfigService::Worker, nidas::util::McSocketListener, nidas::util::McSocketMulticaster< SocketTT >, nidas::util::ThreadRunnable, and nidas::util::ThreadJoiner.
Referenced by nidas::util::Thread::pRun(), nidas::util::ThreadRunnable::run(), and nidas::util::Thread::start().
|
protectedinherited |
Set the cancel type for this thread.
true means cancel requests are deferred until the next cancellation point. false means they occur instantly. This is protected, it should be called only from a thread's own run method. See the pthreads(7) man page for a list of the cancellation points.
Note: non-deferred canceling is difficult to get right. It has not been tested with this class, and is not recommended.
References nidas::util::Thread::_cancel_deferred.
|
protectedinherited |
Set the cancel state for this thread - false means cancel requests are ignored.
See pthread_setcancelstate. This is protected, it should be called only from a thread's own run method.
References nidas::util::Thread::_cancel_enabled.
val | If true, and heapSize exceeds heapMax, then wait for heapSize to be less then heapMax, which will block any SampleSources that are inserting samples into this sorter. If false, then discard any samples that are received while heapSize exceeds heapMax. |
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
Set the maximum amount of heap memory to use for sorting samples.
val | Maximum size of heap in bytes. |
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
Implemented in nidas::core::SampleSorter, and nidas::core::SampleBuffer.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
Implemented in nidas::core::SampleSorter, and nidas::core::SampleBuffer.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
|
inherited |
Exception |
References nidas::util::Thread::NU_THREAD_OTHER, and nidas::util::Thread::setThreadScheduler().
Is this thread running in real-time, meaning is it handling recently sampled data? If so then we can screen for bad sample time-tags by checking against the system clock, which is trusted.
Note that real-time here doesn't mean running at real-time priority.
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
|
inherited |
Exception |
References nidas::util::Thread::NU_THREAD_FIFO, and nidas::util::Thread::setThreadScheduler().
Referenced by nidas::core::DSMEngine::openSensors(), nidas::core::SamplePipeline::procinit(), and nidas::core::SamplePipeline::rawinit().
|
inherited |
Exception |
References nidas::util::Thread::NU_THREAD_RR, and nidas::util::Thread::setThreadScheduler().
|
inherited |
Exception |
References nidas::util::Thread::_mutex, and nidas::util::Thread::setThreadSchedulerNolock().
Referenced by nidas::dynld::RawSampleService::connect(), nidas::util::Thread::setNonRealTimePriority(), nidas::util::Thread::setRealTimeFIFOPriority(), and nidas::util::Thread::setRealTimeRoundRobinPriority().
|
privateinherited |
If the thread is running, set the scheduling policy according to the current policy and priority attributes in this Thread.
Warn but continue if realtime priority cannot be set, otherwise raise Exception.
Exception |
References nidas::util::Thread::_id, nidas::util::Thread::_policy, nidas::util::Thread::_priority, ELOG, nidas::util::Exception::errnoToString(), nidas::util::Thread::getName(), nidas::util::Thread::NU_THREAD_FIFO, nidas::util::Thread::NU_THREAD_RR, and WLOG.
Referenced by nidas::util::Thread::pRun(), nidas::util::Thread::setThreadScheduler(), and nidas::util::Thread::setThreadSchedulerNolock().
|
privateinherited |
Set the scheduler policy and priority for this thread, then call setThreadSchedulerNolock() to effect the settings if the thread is running.
Exception |
References nidas::util::Thread::_policy, nidas::util::Thread::_priority, and nidas::util::Thread::setThreadSchedulerNolock().
|
staticprivateinherited |
References nidas::util::Thread::currentThread(), nidas::util::Thread::currentThreadId(), and DLOG.
Referenced by nidas::util::Thread::thr_add_sig().
Signal handler function for this thread.
The default handler just sets _interrupt to true, so that amInterrupted() or isInterrupted() will return true. Derived classes can override this method for custom signal handling. However, derived classes are limited in what they can do in their signal handler. Specifically, from the pthread_cond_signal man page:
"It is not safe to use the pthread_cond_signal() function in a signal handler that is invoked asynchronously."
Therefore do not call Cond::signal() from a signal handler.
Reimplemented in nidas::core::SensorHandler.
References nidas::util::Thread::_interrupted.
Number of samples that have not be distributed.
Implemented in nidas::core::SampleBuffer, and nidas::core::SampleSorter.
Referenced by nidas::core::SamplePipeline::getSorterNumProcSamples(), and nidas::core::SamplePipeline::getSorterNumRawSamples().
|
virtualinherited |
Start the thread running, meaning execute the run method in a separate thread.
Exception |
References nidas::util::Thread::_detached, nidas::util::Thread::_id, nidas::util::Thread::_interrupted, nidas::util::Thread::_mutex, nidas::util::Thread::_running, nidas::util::Exception::errnoToString(), nidas::util::Thread::getName(), nidas::util::Thread::makeFullName(), nidas::util::Thread::registerThread(), nidas::util::Runnable::run(), nidas::util::Thread::thr_run(), and nidas::util::Thread::thr_run_detached().
Referenced by nidas::dynld::RawSampleService::connect(), nidas::dynld::XMLConfigAllService::connected(), nidas::dynld::XMLConfigService::connected(), nidas::dynld::raf::SyncServer::getTimeWindow(), main(), nidas::core::FsMount::mount(), nidas::core::DSMEngine::openSensors(), nidas::core::SamplePipeline::procinit(), nidas::core::SamplePipeline::rawinit(), nidas::core::Socket::requestConnection(), nidas::core::ServerSocket::requestConnection(), nidas::core::DSMEngine::run(), nidas::core::SensorHandler::run(), nidas::dynld::UDPSampleOutput::XMLSocketListener::run(), nidas::dynld::raf::SyncServer::setTimeWindow(), nidas::core::Looper::setupClientMaps(), nidas::core::DSMServerApp::startStatusThread(), nidas::core::DSMEngine::startXmlRpcThread(), and nidas::core::DSMServerApp::startXmlRpcThread().
|
staticinherited |
a test method.
|
inlineprotectedinherited |
Check if we have been cancelled.
Calls pthread_testcancel. This is protected since it only checks the current thread - i.e. it must be called within the run method. Since it just calls pthread_testcancel, it is a cancellation point.
Referenced by nidas::util::Runnable::amInterrupted(), and TestSource::run().
|
staticprivateinherited |
References nidas::util::Thread::sigAction().
Referenced by nidas::util::Thread::blockSignal(), and nidas::util::Thread::unblockSignal().
|
staticprivateinherited |
References ILOG.
Referenced by nidas::util::Thread::thr_run().
|
staticprivateinherited |
References nidas::util::Thread::_mutex, and nidas::util::Mutex::lock().
Referenced by nidas::util::Thread::thr_run_detached().
|
staticprivateinherited |
References nidas::util::Thread::thr_cleanup().
Referenced by nidas::util::Thread::start().
|
staticprivateinherited |
References nidas::util::Thread::thr_cleanup_delete().
Referenced by nidas::util::Thread::start().
|
inherited |
Install a signal handler and unblock the signal.
The signal handler will log a message about the receipt of the signal at severity LOG_INFO using the nidas::util::Logger. Then, if the signal handler is being invoked from a registered Thread, the virtual method signalHandler() for that Thread will be called.
The signal handler is installed with the sigaction() system call, and will be the action for the given signal in all threads, including the main() thread. If other threads do not wish to take action on a given signal, they should call blockSignal(sig). Or they can define their own signalHandler() method.
After installing the signal handler, the signal is added to those that are unblocked for the thread, or if the Thread is not yet running, the signal will be unblocked in the thread once it runs.
As with blockSignal(), this method is typically called on this Thread before it has started. If this Thread has started, then the signal will only be unblocked if the method is called from this Thread, i.e. from its own run() method.
To install a signal handler, and then block the signal so that it is held as pending until it is later unblocked, typically with pselect(), or sigwaitinfo(), do:
References nidas::util::Thread::_blockedSignals, nidas::util::Thread::_unblockedSignals, nidas::util::Thread::currentThread(), nidas::util::Thread::isRunning(), and nidas::util::Thread::thr_add_sig().
Referenced by nidas::core::DerivedDataReader::DerivedDataReader(), nidas::core::FsMountWorkerThread::FsMountWorkerThread(), nidas::core::StatusListener::StatusListener(), nidas::core::StatusThread::StatusThread(), nidas::dynld::XMLConfigService::Worker::Worker(), nidas::core::XmlRpcThread::XmlRpcThread(), and nidas::dynld::UDPSampleOutput::XMLSocketListener::XMLSocketListener().
|
privateinherited |
References nidas::util::Thread::_id.
|
inlineprivateinherited |
References nidas::util::Thread::_id, and nidas::util::Thread::_mutex.
|
privateinherited |
|
privateinherited |
|
privateinherited |
|
privateinherited |
|
privateinherited |
Exception thrown by run method.
Referenced by nidas::util::Thread::join(), nidas::util::Thread::pRun(), and nidas::util::Thread::~Thread().
|
privateinherited |
Referenced by nidas::util::Thread::getFullName(), and nidas::util::Thread::makeFullName().
|
privateinherited |
Referenced by nidas::util::Thread::cancel(), nidas::util::Thread::getId(), nidas::util::Thread::join(), nidas::util::Thread::kill(), nidas::util::Thread::makeFullName(), nidas::util::Thread::registerThread(), nidas::util::Thread::setThreadSchedulerNolock(), nidas::util::Thread::start(), nidas::util::Thread::unregisterThread(), and nidas::util::Thread::unsetId().
|
privateinherited |
|
mutableprivateinherited |
Mutex for accessing _id.
Referenced by nidas::util::Thread::cancel(), nidas::util::Thread::getId(), nidas::util::Thread::interrupt(), nidas::util::Thread::isInterrupted(), nidas::util::Thread::isRunning(), nidas::util::Thread::join(), nidas::util::Thread::kill(), nidas::util::Thread::pRun(), nidas::util::Thread::setThreadScheduler(), nidas::util::Thread::start(), nidas::util::Thread::thr_cleanup_delete(), and nidas::util::Thread::unsetId().
|
privateinherited |
Referenced by nidas::util::Thread::getName(), and nidas::util::Thread::makeFullName().
|
privateinherited |
|
privateinherited |
|
privateinherited |
Referenced by nidas::util::Thread::isRunning(), and nidas::util::Thread::start().
|
privateinherited |
|
staticprivateinherited |
Referenced by nidas::util::Thread::currentName().