![]() |
nsbaci 1.0
|
Manages thread scheduling and state transitions. More...
#include <scheduler.h>

Public Member Functions | |
| virtual Thread * | pickNext ()=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 Thread * | current ()=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< Thread > | threads |
| 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. | |
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.
|
pure virtual |
Add a new thread to the scheduler.
| thread | The thread to add. |
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Block the currently running thread.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Block current thread on coend (waiting for spawned threads).
| expectedThreads | Number of threads that should terminate. |
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Block current thread on a semaphore.
| semaphoreAddr | The address of the semaphore. |
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Check if coend-blocked threads should be unblocked.
Called after a thread terminates.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Clear all threads and reset scheduler state.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Get the currently running thread.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Get all threads managed by the scheduler.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Check if there are any threads left to run.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Pick the next thread to run.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Terminate the currently running thread.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Move a thread from blocked to ready state.
| threadId | The ID of the thread to unblock. |
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Move all I/O waiting threads back to ready queue.
Called when input becomes available.
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Unblock threads waiting on a semaphore.
| semaphoreAddr | The address of the semaphore. |
Implemented in nsbaci::services::runtime::NsbaciScheduler.
|
pure virtual |
Yield the current thread (move to back of ready queue).
Implemented in nsbaci::services::runtime::NsbaciScheduler.