Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Executor< NUM_PRIO > Class Template Reference

Implementation the ExecutorBase with a specific number of priority bands. More...

#include <Executor.hxx>

Inheritance diagram for Executor< NUM_PRIO >:
ExecutorBase OSThread Executable LinkedObject< ExecutorBase > Notifiable QMember Destructable

Public Member Functions

 Executor (const char *name, int priority, size_t stack_size)
 Constructor.
 
 Executor (const NO_THREAD &unused)
 Constructor that does not create a thread for running the executor.
 
void start_thread (const char *name, int priority, size_t stack_size)
 Creates a new thread for running this executor.
 
 ~Executor ()
 Destructor.
 
void add (Executable *msg, unsigned priority=UINT_MAX) OVERRIDE
 Send a message to this Executor's queue.
 
void thread_body ()
 If the executor was created with NO_THREAD, then this function needs to be called to run the executor loop.
 
bool empty () OVERRIDE
 
uint32_t sequence () OVERRIDE
 
- Public Member Functions inherited from ExecutorBase
 ExecutorBase ()
 Constructor.
 
 ~ExecutorBase ()
 Destructor.
 
void sync_run (std::function< void()> fn)
 Synchronously runs a closure on this executor.
 
void select (Selectable *job)
 Adds a file descriptor to be watched to the select loop.
 
bool is_selected (Selectable *job)
 
void unselect (Selectable *job)
 Removes a job from the select loop.
 
bool loop_once ()
 Performs one loop of the execution on the calling thread.
 
long long loop_some () ICACHE_FLASH_ATTR
 Performs a few loops of the executor on the calling thread.
 
ActiveTimersactive_timers ()
 
void shutdown ()
 Terminates the executor thread.
 
os_thread_t thread_handle ()
 
OSThreadthread ()
 
void assert_current ()
 Die if we are not on the current executor.
 
Executablecurrent ()
 Helper function for debugging and tracing.
 
- Public Member Functions inherited from LinkedObject< ExecutorBase >
ExecutorBaselink_next ()
 

Private Member Functions

Executablenext (unsigned *priority) OVERRIDE
 Retrieve an item from the front of the queue.
 
 Executor ()
 Default Constructor.
 
 DISALLOW_COPY_AND_ASSIGN (Executor)
 

Private Attributes

QListProtected< NUM_PRIO > queue_
 Internal queue of executables waiting to be scheduled.
 

Additional Inherited Members

- Static Public Member Functions inherited from ExecutorBase
static ExecutorBaseby_name (const char *name, bool wait)
 Lookup an executor by its name.
 
- Static Public Member Functions inherited from LinkedObject< ExecutorBase >
static ExecutorBaselink_head ()
 
static Atomichead_mu ()
 Locks the list for modification (at any entry!).
 
- Protected Member Functions inherited from ExecutorBase
void * entry () override
 Thread entry point.
 
void run () override
 Entry point.
 
 DISALLOW_COPY_AND_ASSIGN (ExecutorBase)
 
 OSThread (const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg)
 Create a thread.
 
 OSThread ()
 Creates a thread via inheritance.
 
void start (const char *name, int priority, size_t stack_size)
 Starts the thread.
 
virtual ~OSThread ()
 Default destructor.
 
bool is_created ()
 
void inherit ()
 Inherits the current thread.
 
os_thread_t get_handle ()
 
void lock_to_thread ()
 Sets the thread handle to the current calling thread's.
 
void unlock_from_thread ()
 Resets the thread handle to none.
 
- Protected Member Functions inherited from Executable
void test_deletion ()
 
void notify () override
 Crashes the program – everyone who is expecting notify calls must override this function.
 
virtual void alloc_result (QMember *item)
 Return the result of an alloc_async() from a memory Pool.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
void init ()
 Initiailize a QMember, in place of a public placement construction.
 
- Protected Member Functions inherited from LinkedObject< ExecutorBase >
ExecutorBaselink_this ()
 
 LinkedObject ()
 Constructor. Puts *this on the linked list.
 
 ~LinkedObject ()
 Constructor. Removes *this from the linked list.
 
ExecutorBaselink_next ()
 
- Static Protected Member Functions inherited from OSThread
static int getpriority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority (OSThread *thread)
 Return the current thread priority.
 
static int get_priority_min ()
 Get the minimum thread priority.
 
static int get_priority_max ()
 Get the maximum thread priority.
 
- Static Protected Member Functions inherited from LinkedObject< ExecutorBase >
static ExecutorBaselink_head ()
 
static Atomichead_mu ()
 Locks the list for modification (at any entry!).
 
- Protected Attributes inherited from ExecutorBase
OSSelectWakeup selectHelper_
 Helper object for interruptible select calls.
 
volatile unsigned sequence_: 25
 Sequence number.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 
- Protected Attributes inherited from LinkedObject< ExecutorBase >
ExecutorBaselink_
 Linked list pointer.
 
- Static Protected Attributes inherited from LinkedObject< ExecutorBase >
static ExecutorBasehead_
 Beginning of the list.
 

Detailed Description

template<unsigned NUM_PRIO>
class Executor< NUM_PRIO >

Implementation the ExecutorBase with a specific number of priority bands.

The memory usage and scheduling cost is proportional to the number of priority bands, so it should be kept pretty low.

Definition at line 265 of file Executor.hxx.

Constructor & Destructor Documentation

◆ Executor() [1/2]

template<unsigned NUM_PRIO>
Executor< NUM_PRIO >::Executor ( const char *  name,
int  priority,
size_t  stack_size 
)
inline

Constructor.

Parameters
namename of executor
prioritythread priority
stack_sizethread stack size

Definition at line 274 of file Executor.hxx.

◆ Executor() [2/2]

template<unsigned NUM_PRIO>
Executor< NUM_PRIO >::Executor ( const NO_THREAD unused)
inlineexplicit

Constructor that does not create a thread for running the executor.

The owner should later create a thread to this executor by calling the start_thread() function or donate a thread by calling thread_body() function.

Parameters
unusedunused – just here for polymorphic disalbiguation.

Definition at line 284 of file Executor.hxx.

◆ ~Executor()

template<unsigned NUM_PRIO>
Executor< NUM_PRIO >::~Executor ( )

Destructor.

Destructs the executor.

Waits for the executor to run out of work first.

Definition at line 411 of file Executor.hxx.

Member Function Documentation

◆ add()

template<unsigned NUM_PRIO>
void Executor< NUM_PRIO >::add ( Executable msg,
unsigned  priority = UINT_MAX 
)
inlinevirtual

Send a message to this Executor's queue.

Parameters
msgExecutable instance to insert into the input queue
prioritypriority of message

Implements ExecutorBase.

Definition at line 306 of file Executor.hxx.

◆ empty()

template<unsigned NUM_PRIO>
bool Executor< NUM_PRIO >::empty ( )
inlinevirtual
Returns
true if there are no executables waiting on this thread to be executed. There could still be a current executable.

Implements ExecutorBase.

Definition at line 350 of file Executor.hxx.

◆ next()

template<unsigned NUM_PRIO>
Executable * Executor< NUM_PRIO >::next ( unsigned *  priority)
inlineprivatevirtual

Retrieve an item from the front of the queue.

Parameters
prioritypass back the priority of the queue pulled from
Returns
item retrieved from queue, else NULL if none waiting.

Implements ExecutorBase.

Definition at line 362 of file Executor.hxx.

◆ sequence()

template<unsigned NUM_PRIO>
uint32_t Executor< NUM_PRIO >::sequence ( )
inlinevirtual
Returns
a number that gets incremented by one every time an executable runs.

Implements ExecutorBase.

Definition at line 355 of file Executor.hxx.

◆ start_thread()

template<unsigned NUM_PRIO>
void Executor< NUM_PRIO >::start_thread ( const char *  name,
int  priority,
size_t  stack_size 
)
inline

Creates a new thread for running this executor.

Parameters
namethread name (passed to OS)
prioritythread priority (0 == default prio)
stack_sizenumber of bytes to allocate for the thread stack; used only for FreeRTOS and ignored on linux etc.

Definition at line 293 of file Executor.hxx.

◆ thread_body()

template<unsigned NUM_PRIO>
void Executor< NUM_PRIO >::thread_body ( )
inline

If the executor was created with NO_THREAD, then this function needs to be called to run the executor loop.

It will exit when the execut gets shut down. Useful for having an executor loop run in the main thread.

Definition at line 344 of file Executor.hxx.

Member Data Documentation

◆ queue_

template<unsigned NUM_PRIO>
QListProtected<NUM_PRIO> Executor< NUM_PRIO >::queue_
private

Internal queue of executables waiting to be scheduled.

Definition at line 376 of file Executor.hxx.


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