YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarp::os::Terminee Class Reference

A class that can be polled to see whether the process has been asked to quit gracefully. More...

#include <yarp/os/Terminator.h>

+ Inheritance diagram for yarp::os::Terminee:

Public Member Functions

 Terminee (const char *name)
 Constructor.
 
virtual ~Terminee ()
 Destructor.
 
void run () override
 Main body of the new thread.
 
bool waitQuit () const
 Call this method to wait for a quit message.
 
bool mustQuit () const
 Call this method to see whether a quit message has been received.
 
bool isOk () const
 Check whether the message mechanism is ok.
 
void onStop () override
 Call-back, called while halting the thread (before join).
 
- Public Member Functions inherited from yarp::os::Thread
 Thread ()
 Constructor.
 
virtual ~Thread ()
 Destructor.
 
bool start ()
 Start the new thread running.
 
bool stop ()
 Stop the thread.
 
virtual void beforeStart ()
 Called just before a new thread starts.
 
virtual void afterStart (bool success)
 Called just after a new thread starts (or fails to start), this is executed by the same thread that calls start().
 
virtual bool threadInit ()
 Initialization method.
 
virtual void threadRelease ()
 Release method.
 
bool isStopping ()
 Returns true if the thread is stopping (Thread::stop has been called).
 
bool isRunning ()
 Returns true if the thread is running (Thread::start has been called successfully and the thread has not stopped).
 
long int getKey ()
 Get a unique identifier for the thread.
 
int setPriority (int priority, int policy=-1)
 Set the priority and scheduling policy of the thread, if the OS supports that.
 
int getPriority ()
 Query the current priority of the thread, if the OS supports that.
 
int getPolicy ()
 Query the current scheduling policy of the thread, if the OS supports that.
 
bool join (double seconds=-1)
 The function returns when the thread execution has completed.
 
void setOptions (int stackSize=0)
 Set the stack size for the new thread.
 

Protected Attributes

voidimplementation
 
volatile bool quit
 
volatile bool ok
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Thread
static int getCount ()
 Check how many threads are running.
 
static long int getKeyOfCaller ()
 Get a unique identifier for the calling thread.
 
static void yield ()
 Reschedule the execution of current thread, allowing other threads to run.
 
static void setDefaultStackSize (int stackSize)
 Set the default stack size for all threads created after this point.
 

Detailed Description

A class that can be polled to see whether the process has been asked to quit gracefully.

Definition at line 46 of file Terminator.h.

Constructor & Destructor Documentation

◆ Terminee()

Terminee::Terminee ( const char name)

Constructor.

Parameters
nameis the nickname to register on the name server.

Definition at line 67 of file Terminator.cpp.

◆ ~Terminee()

Terminee::~Terminee ( )
virtual

Destructor.

Definition at line 104 of file Terminator.cpp.

Member Function Documentation

◆ isOk()

bool Terminee::isOk ( ) const

Check whether the message mechanism is ok.

Returns
true if ok, false otherwise.

Definition at line 151 of file Terminator.cpp.

◆ mustQuit()

bool Terminee::mustQuit ( ) const

Call this method to see whether a quit message has been received.

Returns
true is a quit has been received, false otherwise.

Definition at line 145 of file Terminator.cpp.

◆ onStop()

void Terminee::onStop ( )
overridevirtual

Call-back, called while halting the thread (before join).

This callback is executed by the same thread that calls stop(). It should not be called directly. Override this method to do the right thing for your particular Thread::run.

Reimplemented from yarp::os::Thread.

Definition at line 97 of file Terminator.cpp.

◆ run()

void Terminee::run ( )
overridevirtual

Main body of the new thread.

Override this method to do what you want. After Thread::start is called, this method will start running in a separate thread. It is important that this method either keeps checking Thread::isStopping to see if it should stop, or you override the Thread::onStop method to interact with it in some way to shut the new thread down. There is no really reliable, portable way to stop a thread cleanly unless that thread cooperates.

Implements yarp::os::Thread.

Definition at line 119 of file Terminator.cpp.

◆ waitQuit()

bool Terminee::waitQuit ( ) const

Call this method to wait for a quit message.

Returns
true if a quit message has been received

Definition at line 139 of file Terminator.cpp.

Member Data Documentation

◆ implementation

void* yarp::os::Terminee::implementation
protected

Definition at line 49 of file Terminator.h.

◆ ok

volatile bool yarp::os::Terminee::ok
protected

Definition at line 51 of file Terminator.h.

◆ quit

volatile bool yarp::os::Terminee::quit
protected

Definition at line 50 of file Terminator.h.


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