Public Member Functions | Protected Attributes | List of all members
novadaq::Runnable Class Referenceabstract

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-18/NovaDAQUtilities/cxx/include/Runnable.h"

Inheritance diagram for novadaq::Runnable:
gov::fnal::cd::rms::ClientListenerLoop gov::fnal::cd::rms::ListenerLoop< CONN, MSG, LSTNR > NdmcClient novadaq::BackgroundProcess

Public Member Functions

 Runnable ()
 
virtual ~Runnable ()
 
virtual void run ()=0
 
virtual void stop ()
 
virtual bool isRunning () const
 
virtual bool isDone () const
 
virtual void watchfulSleep (int microseconds, int numberOfIntervals=10)
 

Protected Attributes

bool _running
 
bool _stopRequested
 
bool _hasCompleted
 

Detailed Description

Interface for objects that can be run in separate threads using the Boost Thread library.

Sample usage: RunnableDescendant myRunnable; boost::thread myThread(boost::bind(&novadaq::Runnable::run, &myRunnable));

Author
Kurt Biery
Steve Foulkes
Version
Revision
1.4.34.1
Date
2019/09/27 00:07:20

Definition at line 36 of file Runnable.h.

Constructor & Destructor Documentation

novadaq::Runnable::Runnable ( )
inline

Default constructor.

Definition at line 41 of file Runnable.h.

References _hasCompleted, _running, and _stopRequested.

41  {
42  _running = false;
43  _stopRequested = false;
44  _hasCompleted = false;
45  }
virtual novadaq::Runnable::~Runnable ( )
inlinevirtual

Virtual destructor (to ensure that derived class destructors are called).

Definition at line 51 of file Runnable.h.

References run().

51 {}

Member Function Documentation

virtual bool novadaq::Runnable::isDone ( ) const
inlinevirtual

Tests if the Runnable object has completed its running.

Returns
true if the object is done, false otherwise.

Definition at line 80 of file Runnable.h.

References _hasCompleted.

Referenced by novadaq::BackgroundProcess::timedWaitForDone().

80  {
81  return _hasCompleted;
82  }
virtual bool novadaq::Runnable::isRunning ( ) const
inlinevirtual

Tests if the Runnable object is running.

Returns
true if the object is running, false otherwise.

Definition at line 71 of file Runnable.h.

References _running.

71  {
72  return _running;
73  }
virtual void novadaq::Runnable::run ( )
pure virtual
virtual void novadaq::Runnable::stop ( )
inlinevirtual

Stops the execution of the Runnable object.

Reimplemented in gov::fnal::cd::rms::ClientListenerLoop, and novadaq::BackgroundProcess.

Definition at line 61 of file Runnable.h.

References _hasCompleted, and _stopRequested.

Referenced by NdmcClient::~NdmcClient().

61  {
62  if (_hasCompleted) {return;}
63  _stopRequested = true;
64  }
virtual void novadaq::Runnable::watchfulSleep ( int  microseconds,
int  numberOfIntervals = 10 
)
inlinevirtual

Sleeps for the specified amount of time, but periodically checks if a stop has been requested, and returns if so.

Definition at line 88 of file Runnable.h.

References _stopRequested, and compare_h5_caf::idx.

89  {
90  if (numberOfIntervals < 1) {numberOfIntervals = 1;}
91  int intervalTime = microseconds / numberOfIntervals;
92  if (intervalTime < 1) {intervalTime = 1;}
93  for (int idx = 0; idx < numberOfIntervals; ++idx) {
94  if (_stopRequested) {break;}
95  usleep(intervalTime);
96  }
97  }

Member Data Documentation

bool novadaq::Runnable::_hasCompleted
protected

Tracks whether the Runnable object has completed its running.

Definition at line 115 of file Runnable.h.

Referenced by isDone(), novadaq::BackgroundProcess::run(), Runnable(), novadaq::BackgroundProcess::stop(), stop(), and novadaq::BackgroundProcess::waitForDone().

bool novadaq::Runnable::_running
protected

Tracks whether the Runnable object is running or not (this can be before it has started or after it has finished)

Definition at line 105 of file Runnable.h.

Referenced by isRunning(), novadaq::BackgroundProcess::run(), gov::fnal::cd::rms::ClientListenerLoop::run(), NdmcClient::run(), Runnable(), and gov::fnal::cd::rms::ClientListenerLoop::~ClientListenerLoop().

bool novadaq::Runnable::_stopRequested
protected

The documentation for this class was generated from the following file: