Ocean
Ocean::Scheduler Class Reference

This class represents a round robin scheduler. More...

Inheritance diagram for Ocean::Scheduler:

Public Types

typedef Ocean::Callback< void > Callback
 Definition of a callback function. More...
 

Public Member Functions

void registerFunction (const Callback &callback)
 Registers a scheduler function. More...
 
void unregisterFunction (const Callback &callback)
 Unregisters a scheduler function. More...
 

Protected Member Functions

 Scheduler ()
 Creates a new scheduler. More...
 
virtual ~Scheduler ()
 Destructs a scheduler. More...
 
virtual void threadRun ()
 Derived thread run function. More...
 
- Protected Member Functions inherited from Ocean::Singleton< Scheduler >
 Singleton ()=default
 Default constructor. More...
 
- Protected Member Functions inherited from Ocean::Thread
 Thread (const Thread &thread)=delete
 Disabled copy constructor. More...
 
void createThread ()
 Creates the thread itself. More...
 
void destroyThread ()
 Destroys the thread itself. More...
 
void stopThreadExplicitly (const unsigned int timeout=5000u)
 Tries to stop the thread gracefully. More...
 
Threadoperator= (const Thread &thread)=delete
 The disabled assign operator. More...
 
 Thread (const std::string &name=std::string())
 Creates a new thread object. More...
 
 Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string())
 Creates a new thread object. More...
 
virtual ~Thread ()
 Destructs a thread object. More...
 
bool startThread ()
 Starts the thread. More...
 
void stopThread ()
 Informs the thread to stop. More...
 
bool terminateThread ()
 Terminates the thread. More...
 
bool joinThread (const unsigned int timeout=(unsigned int)(-1))
 Waits until this thread has been stopped. More...
 
bool shouldThreadStop () const
 Returns whether this thread should stop. More...
 
bool isThreadInvokedToStart () const
 Returns whether this thread has been invoked to start immediately. More...
 
bool isThreadActive () const
 Returns whether this thread is active. More...
 

Protected Attributes

Callbacks callbacks
 Scheduler callbacks. More...
 

Private Types

typedef ConcurrentCallbacks< CallbackCallbacks
 Definition of a callback pair holding a callback function and an active flag. More...
 

Friends

class Singleton< Scheduler >
 

Additional Inherited Members

- Static Public Member Functions inherited from Ocean::Singleton< Scheduler >
static Schedulerget ()
 Returns a reference to the unique object. More...
 
- Protected Types inherited from Ocean::Thread
typedef std::pair< pthread_t, bool > TimedJoinPair
 Definition of a pair holding a thread id and a boolean state. More...
 
enum  ThreadPriority {
  PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL ,
  PRIORTY_HIGH , PRIORTY_REALTIME
}
 Definition of different thread priority values. More...
 
- Static Protected Member Functions inherited from Ocean::Thread
static void sleep (unsigned int ms)
 Sleeps the calling thread for a given time. More...
 
static void giveUp ()
 Gives up the remaining thread time. More...
 
static ThreadId currentThreadId ()
 Returns the thread id of the current (calling) thread. More...
 
static ThreadPriority threadPriority ()
 Returns the priority of the current thread. More...
 
static bool setThreadPriority (const ThreadPriority priority)
 Sets the priority of the current thread. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
static int pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime)
 Implements a thread join function with timeout value. More...
 

Detailed Description

This class represents a round robin scheduler.

The scheduler is based on one single thread and executes all registered functions in a round robin manner.
The registered functions are called with high frequency (e.g., each 10-50 ms).
A registered function should return immediately so that a high call frequency for all registered function can be ensured.

See also
ThreadPool, TaskQueue.

Member Typedef Documentation

◆ Callback

Definition of a callback function.

◆ Callbacks

Definition of a callback pair holding a callback function and an active flag.

Constructor & Destructor Documentation

◆ Scheduler()

Ocean::Scheduler::Scheduler ( )
protected

Creates a new scheduler.

◆ ~Scheduler()

virtual Ocean::Scheduler::~Scheduler ( )
protectedvirtual

Destructs a scheduler.

Member Function Documentation

◆ registerFunction()

void Ocean::Scheduler::registerFunction ( const Callback callback)

Registers a scheduler function.

Each registered function must be unregistered by the caller if the scheduler event is not needed anymore.

Parameters
callbackCallback function to register
See also
unregisterFunction().

◆ threadRun()

virtual void Ocean::Scheduler::threadRun ( )
protectedvirtual

Derived thread run function.

Implements Ocean::Thread.

◆ unregisterFunction()

void Ocean::Scheduler::unregisterFunction ( const Callback callback)

Unregisters a scheduler function.

This function may be called from a registered scheduler function.

Parameters
callbackCallback function to unregister
See also
registerFunction().

Friends And Related Function Documentation

◆ Singleton< Scheduler >

friend class Singleton< Scheduler >
friend

Field Documentation

◆ callbacks

Callbacks Ocean::Scheduler::callbacks
protected

Scheduler callbacks.


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