Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Bus< MessageType >::Master Class Reference

The Bus Master class. More...

#include <BusMaster.hxx>

Inheritance diagram for Bus< MessageType >::Master:
StateFlowBase Executable Notifiable QMember Destructable

Public Member Functions

 Master (Service *s, PacketSink *sink, Activity *idle, unsigned num_enqueued)
 Constructor.
 
void set_policy (unsigned num_prio, const Fixed16 *strides)
 Sets the scheduling policy.
 
void schedule_activity (Activity *a, unsigned prio)
 Adds an activity to the bus master's scheduler.
 
- Public Member Functions inherited from StateFlowBase
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
Serviceservice ()
 Return a pointer to the service I am bound to.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Member Functions

Action get_buffer ()
 Start of scheduling flow.
 
Action fill_pkt ()
 Executes the scheduling decision, fills in the packet by the selected activity and sends it to the bus sink.
 

Private Attributes

uninitialized< ScheduledQueuequeue_
 Handles the policy of polling.
 
Activityidle_
 If we have no activity to do, this activity gets invoked.
 
PacketSinksink_
 Where to send the generated packets.
 
LimitedPool pool_
 Source of the buffers that we fill and hand out.
 
uint16_t numPacketsInPool_
 Total number of packets that the pool can generate.
 
uint16_t needShutdown_: 1
 True if shutdown was requested.
 

Additional Inherited Members

- Static Public Member Functions inherited from StateFlowBase
template<class T , typename... Args>
static void invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args)
 Calls a helper flow to perform some actions.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- Protected Member Functions inherited from StateFlowBase
 StateFlowBase (Service *service)
 Constructor.
 
 ~StateFlowBase ()
 Destructor.
 
void reset_flow (Callback c)
 Resets the flow to the specified state.
 
bool is_state (Callback c)
 
bool is_terminated ()
 
void start_flow (Callback c)
 Resets the flow to the specified state and starts it.
 
Action again ()
 Call the current state again via call_immediately.
 
Action exit ()
 Terminate current StateFlow activity.
 
Action delete_this ()
 Terminates the flow and deletes *this.
 
Action set_terminated ()
 Sets the flow to terminated state.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
Action wait ()
 Wait for an asynchronous call.
 
Action wait_and_call (Callback c)
 Wait for resource to become available before proceeding to next state.
 
template<class T >
Action allocate_and_call (FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
 Allocates a buffer from a pool and proceed to the next state when allocation is successful.
 
Action allocate_and_call (Callback c, QAsync *queue)
 Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete.
 
template<class T >
Buffer< T > * full_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
T * full_allocation_result (TypedQAsync< T > *queue)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
void cast_allocation_result (T **member)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
Buffer< T > * get_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation.
 
Action yield_and_call (Callback c)
 Place the current flow to the back of the executor, and transition to a new state after we get the CPU again.
 
Action yield ()
 Place the current flow to the back of the executor, and re-try the current state after we get the CPU again.
 
Action sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c)
 Suspends execution of this control flow for a specified time.
 
template<class T , typename... Args>
Action invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args)
 Calls a helper flow to perform some actions.
 
Action read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read and then invokes the next state.
 
Action read_single (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read.
 
Action read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now.
 
Action read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read, or a timeout expires.
 
Action internal_try_read ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading.
 
Action write_repeated (StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Writes some data into a file descriptor, repeating the operation as necessary until all bytes are written.
 
Action internal_try_write ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

template<class MessageType>
class Bus< MessageType >::Master

The Bus Master class.

This keeps the scheduler of activities and owns a variety of auxiliary objects and memory management.

Definition at line 74 of file BusMaster.hxx.

Constructor & Destructor Documentation

◆ Master()

template<class MessageType >
Bus< MessageType >::Master::Master ( Service s,
PacketSink sink,
Activity idle,
unsigned  num_enqueued 
)
inline

Constructor.

Parameters
sthe executor to run the service on.
sinkthis is where the generated packets will be sent out.
idlewhen no activity is scheduled, this activity will be invoked with the packet. This activity must be ready to render a packet at all times.
num_enqueuedthis is how many packets we fill in and enqueue for the sink. It is a tradeoff between the sink being out of work vs the what is the lowest latency between enqueueing a high priority activity and that getting the next packet. Recommended values are 2 or 3.

Definition at line 88 of file BusMaster.hxx.

Member Function Documentation

◆ fill_pkt()

template<class MessageType >
Action Bus< MessageType >::Master::fill_pkt ( )
inlineprivate

Executes the scheduling decision, fills in the packet by the selected activity and sends it to the bus sink.

Definition at line 143 of file BusMaster.hxx.

◆ get_buffer()

template<class MessageType >
Action Bus< MessageType >::Master::get_buffer ( )
inlineprivate

Start of scheduling flow.

Definition at line 136 of file BusMaster.hxx.

◆ schedule_activity()

template<class MessageType >
void Bus< MessageType >::Master::schedule_activity ( Activity a,
unsigned  prio 
)
inline

Adds an activity to the bus master's scheduler.

The activity must be ready to fill in a packet right now.

Parameters
athe activity to schedule. The caller retains ownership.
priothe priority band to schedule in.

Definition at line 129 of file BusMaster.hxx.

◆ set_policy()

template<class MessageType >
void Bus< MessageType >::Master::set_policy ( unsigned  num_prio,
const Fixed16 strides 
)
inline

Sets the scheduling policy.

This must be called exactly once after construction before scheduling any bus activity.

Definition at line 119 of file BusMaster.hxx.

Member Data Documentation

◆ idle_

template<class MessageType >
Activity* Bus< MessageType >::Master::idle_
private

If we have no activity to do, this activity gets invoked.

It must always be able to fill in a packet.

Definition at line 165 of file BusMaster.hxx.

◆ needShutdown_

template<class MessageType >
uint16_t Bus< MessageType >::Master::needShutdown_
private

True if shutdown was requested.

Definition at line 173 of file BusMaster.hxx.

◆ numPacketsInPool_

template<class MessageType >
uint16_t Bus< MessageType >::Master::numPacketsInPool_
private

Total number of packets that the pool can generate.

Definition at line 171 of file BusMaster.hxx.

◆ pool_

template<class MessageType >
LimitedPool Bus< MessageType >::Master::pool_
private

Source of the buffers that we fill and hand out.

Definition at line 169 of file BusMaster.hxx.

◆ queue_

template<class MessageType >
uninitialized<ScheduledQueue> Bus< MessageType >::Master::queue_
private

Handles the policy of polling.

Definition at line 162 of file BusMaster.hxx.

◆ sink_

template<class MessageType >
PacketSink* Bus< MessageType >::Master::sink_
private

Where to send the generated packets.

Definition at line 167 of file BusMaster.hxx.


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