13#ifndef NSBACI_SERVICES_RUNTIME_SCHEDULER_H
14#define NSBACI_SERVICES_RUNTIME_SCHEDULER_H
17#include <unordered_map>
38 Scheduler() =
default;
39 virtual ~Scheduler() =
default;
75 virtual void unblock(nsbaci::types::ThreadID threadId) = 0;
virtual const std::vector< Thread > & getThreads() const =0
Get all threads managed by the scheduler.
virtual Thread * pickNext()=0
Pick the next thread to run.
virtual void blockCurrent()=0
Block the currently running thread.
virtual void blockOnCoend(int32_t expectedThreads)=0
Block current thread on coend (waiting for spawned threads).
std::optional< size_t > runningIndex
Index of currently running thread.
Definition scheduler.h:133
virtual void terminateCurrent()=0
Terminate the currently running thread.
std::vector< size_t > blockedQueue
Indices of blocked threads.
Definition scheduler.h:131
virtual bool hasThreads() const =0
Check if there are any threads left to run.
virtual void blockOnSemaphore(uint32_t semaphoreAddr)=0
Block current thread on a semaphore.
virtual void addThread(Thread thread)=0
Add a new thread to the scheduler.
std::vector< std::pair< size_t, int32_t > > coendQueue
Threads waiting at coend, with their expected thread counts.
Definition scheduler.h:139
virtual void unblockIO()=0
Move all I/O waiting threads back to ready queue.
std::vector< size_t > ioQueue
Indices of I/O waiting threads.
Definition scheduler.h:132
std::vector< Thread > threads
All threads owned by scheduler.
Definition scheduler.h:129
std::unordered_map< uint32_t, std::vector< size_t > > semaphoreQueues
Map from semaphore address to list of waiting thread indices.
Definition scheduler.h:136
virtual size_t unblockSemaphore(uint32_t semaphoreAddr)=0
Unblock threads waiting on a semaphore.
virtual void clear()=0
Clear all threads and reset scheduler state.
virtual void checkCoendUnblock()=0
Check if coend-blocked threads should be unblocked.
virtual void yield()=0
Yield the current thread (move to back of ready queue).
virtual void unblock(nsbaci::types::ThreadID threadId)=0
Move a thread from blocked to ready state.
virtual Thread * current()=0
Get the currently running thread.
std::vector< size_t > readyQueue
Indices of ready threads.
Definition scheduler.h:130
Represents a thread in the runtime service.
Definition thread.h:31
Runtime services namespace for nsbaci.
Thread class declaration for nsbaci runtime service.