| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include "mos/platform/platform.hpp" |
| 6 | |
| 7 | typedef struct _scheduler_ops scheduler_ops_t; |
| 8 | typedef struct _scheduler scheduler_t; |
| 9 | |
| 10 | typedef struct _scheduler_ops |
| 11 | { |
| 12 | void (*init)(scheduler_t *instance); ///< Initialize the scheduler |
| 13 | |
| 14 | /** |
| 15 | * @brief Select the next thread to run, thread state lock should be locked |
| 16 | * |
| 17 | */ |
| 18 | Thread *(*select_next)(scheduler_t *instance); |
| 19 | void (*add_thread)(scheduler_t *instance, Thread *thread); ///< Add a thread to the scheduler |
| 20 | void (*remove_thread)(scheduler_t *instance, Thread *thread); ///< Remove a thread from the scheduler |
| 21 | } scheduler_ops_t; |
| 22 | |
| 23 | typedef struct _scheduler |
| 24 | { |
| 25 | const scheduler_ops_t *ops; |
| 26 | } scheduler_t; |
| 27 | |
| 28 | typedef struct _scheduler_info |
| 29 | { |
| 30 | const char *const name; |
| 31 | scheduler_t *const scheduler; |
| 32 | } scheduler_info_t; |
| 33 | |
| 34 | #define MOS_SCHEDULER(_name, _i) MOS_PUT_IN_SECTION(".mos.schedulers", scheduler_info_t, MOS_CONCAT(_name, __COUNTER__), { .name = #_name, .scheduler = &_i }) |
| 35 | |