nsbaci 1.0
Loading...
Searching...
No Matches
nsbaci::services::runtime::Scheduler Class Referenceabstract

Manages thread scheduling and state transitions. More...

#include <scheduler.h>

Inheritance diagram for nsbaci::services::runtime::Scheduler:

Public Member Functions

virtual ThreadpickNext ()=0
 Pick the next thread to run.
virtual void addThread (Thread thread)=0
 Add a new thread to the scheduler.
virtual void blockCurrent ()=0
 Block the currently running thread.
virtual void blockOnSemaphore (uint32_t semaphoreAddr)=0
 Block current thread on a semaphore.
virtual size_t unblockSemaphore (uint32_t semaphoreAddr)=0
 Unblock threads waiting on a semaphore.
virtual void unblock (nsbaci::types::ThreadID threadId)=0
 Move a thread from blocked to ready state.
virtual void yield ()=0
 Yield the current thread (move to back of ready queue).
virtual void terminateCurrent ()=0
 Terminate the currently running thread.
virtual bool hasThreads () const =0
 Check if there are any threads left to run.
virtual Threadcurrent ()=0
 Get the currently running thread.
virtual void clear ()=0
 Clear all threads and reset scheduler state.
virtual void unblockIO ()=0
 Move all I/O waiting threads back to ready queue.
virtual const std::vector< Thread > & getThreads () const =0
 Get all threads managed by the scheduler.
virtual void blockOnCoend (int32_t expectedThreads)=0
 Block current thread on coend (waiting for spawned threads).
virtual void checkCoendUnblock ()=0
 Check if coend-blocked threads should be unblocked.

Protected Attributes

std::vector< Threadthreads
 All threads owned by scheduler.
std::vector< size_t > readyQueue
 Indices of ready threads.
std::vector< size_t > blockedQueue
 Indices of blocked threads.
std::vector< size_t > ioQueue
 Indices of I/O waiting threads.
std::optional< size_t > runningIndex
 Index of currently running thread.
std::unordered_map< uint32_t, std::vector< size_t > > semaphoreQueues
 Map from semaphore address to list of waiting thread indices.
std::vector< std::pair< size_t, int32_t > > coendQueue
 Threads waiting at coend, with their expected thread counts.

Detailed Description

Manages thread scheduling and state transitions.

The Scheduler is responsible for determining which thread runs next, managing thread queues for different states, and handling thread state transitions.

Member Function Documentation

◆ addThread()

virtual void nsbaci::services::runtime::Scheduler::addThread ( Thread thread)
pure virtual

Add a new thread to the scheduler.

Parameters
threadThe thread to add.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ blockCurrent()

virtual void nsbaci::services::runtime::Scheduler::blockCurrent ( )
pure virtual

Block the currently running thread.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ blockOnCoend()

virtual void nsbaci::services::runtime::Scheduler::blockOnCoend ( int32_t expectedThreads)
pure virtual

Block current thread on coend (waiting for spawned threads).

Parameters
expectedThreadsNumber of threads that should terminate.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ blockOnSemaphore()

virtual void nsbaci::services::runtime::Scheduler::blockOnSemaphore ( uint32_t semaphoreAddr)
pure virtual

Block current thread on a semaphore.

Parameters
semaphoreAddrThe address of the semaphore.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ checkCoendUnblock()

virtual void nsbaci::services::runtime::Scheduler::checkCoendUnblock ( )
pure virtual

Check if coend-blocked threads should be unblocked.

Called after a thread terminates.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ clear()

virtual void nsbaci::services::runtime::Scheduler::clear ( )
pure virtual

Clear all threads and reset scheduler state.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ current()

virtual Thread * nsbaci::services::runtime::Scheduler::current ( )
pure virtual

Get the currently running thread.

Returns
Pointer to current thread, or nullptr if none.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ getThreads()

virtual const std::vector< Thread > & nsbaci::services::runtime::Scheduler::getThreads ( ) const
pure virtual

Get all threads managed by the scheduler.

Returns
Const reference to the threads vector.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ hasThreads()

virtual bool nsbaci::services::runtime::Scheduler::hasThreads ( ) const
pure virtual

Check if there are any threads left to run.

Returns
True if there are threads in any queue.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ pickNext()

virtual Thread * nsbaci::services::runtime::Scheduler::pickNext ( )
pure virtual

Pick the next thread to run.

Returns
Pointer to the next thread, or nullptr if no threads are ready.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ terminateCurrent()

virtual void nsbaci::services::runtime::Scheduler::terminateCurrent ( )
pure virtual

Terminate the currently running thread.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ unblock()

virtual void nsbaci::services::runtime::Scheduler::unblock ( nsbaci::types::ThreadID threadId)
pure virtual

Move a thread from blocked to ready state.

Parameters
threadIdThe ID of the thread to unblock.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ unblockIO()

virtual void nsbaci::services::runtime::Scheduler::unblockIO ( )
pure virtual

Move all I/O waiting threads back to ready queue.

Called when input becomes available.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ unblockSemaphore()

virtual size_t nsbaci::services::runtime::Scheduler::unblockSemaphore ( uint32_t semaphoreAddr)
pure virtual

Unblock threads waiting on a semaphore.

Parameters
semaphoreAddrThe address of the semaphore.
Returns
Number of threads unblocked.

Implemented in nsbaci::services::runtime::NsbaciScheduler.

◆ yield()

virtual void nsbaci::services::runtime::Scheduler::yield ( )
pure virtual

Yield the current thread (move to back of ready queue).

Implemented in nsbaci::services::runtime::NsbaciScheduler.


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