sched.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
80 #ifndef SCHED_H
81 #define SCHED_H
82 
83 #include <stddef.h>
84 #include "kernel_defines.h"
85 #include "kernel_types.h"
86 #include "native_sched.h"
87 #include "clist.h"
88 
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92 
96 typedef struct _thread thread_t;
97 
104 typedef enum {
126 #define STATUS_ON_RUNQUEUE STATUS_RUNNING
128 #define STATUS_NOT_FOUND ((thread_status_t)-1)
134 #ifndef SCHED_PRIO_LEVELS
135 #define SCHED_PRIO_LEVELS 16
136 #endif
137 
145 thread_t *sched_run(void);
146 
154 void sched_set_status(thread_t *process, thread_status_t status);
155 
168 void sched_switch(uint16_t other_prio);
169 
174 
179 extern volatile unsigned int sched_context_switch_request;
180 
184 extern volatile thread_t *sched_threads[KERNEL_PID_LAST + 1];
185 
189 extern volatile int sched_num_threads;
190 
195 
199 NORETURN void sched_task_exit(void);
200 
214 void sched_arch_idle(void);
215 
216 #if IS_USED(MODULE_SCHED_CB) || defined(DOXYGEN)
217 
226 typedef void (*sched_callback_t)(kernel_pid_t active, kernel_pid_t next);
233 void sched_register_cb(sched_callback_t callback);
234 #endif /* MODULE_SCHED_CB */
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /* SCHED_H */
241 
Types used by the kernel.
waiting for any flag from flag_mask
Definition: sched.h:112
has terminated
Definition: sched.h:105
void sched_set_status(thread_t *process, thread_status_t status)
Set the status of the specified process.
clist_node_t sched_runqueues[SCHED_PRIO_LEVELS]
List of runqueues per priority level.
waiting to be scheduled to run
Definition: sched.h:117
currently running
Definition: sched.h:116
thread_t * sched_run(void)
Triggers the scheduler to schedule the next thread.
thread_status_t status
thread&#39;s status
Definition: thread.h:156
waiting for a condition variable
Definition: sched.h:115
has terminated & keeps thread&#39;s thread_t
Definition: sched.h:106
number of supported thread states
Definition: sched.h:118
thread_t holds thread&#39;s context data.
Definition: thread.h:154
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
volatile unsigned int sched_context_switch_request
Flag indicating whether a context switch is necessary after handling an interrupt.
volatile thread_t * sched_threads[KERNEL_PID_LAST+1]
Thread table.
waiting for all flags in flag_mask
Definition: sched.h:113
void sched_arch_idle(void)
Set CPU to idle mode (CPU dependent)
volatile int sched_num_threads
Number of running (non-terminated) threads.
waiting for get/put on mbox
Definition: sched.h:114
NORETURN void sched_task_exit(void)
Removes thread from scheduler and set status to STATUS_STOPPED.
Add definitions required on the native board.
#define NORETURN
The NORETURN keyword tells the compiler to assume that the function cannot return.
List node structure.
Definition: list.h:40
waiting for a message
Definition: sched.h:109
Common macros and compiler attributes/pragmas configuration.
waiting for message to be delivered
Definition: sched.h:110
Circular linked list.
void sched_switch(uint16_t other_prio)
Yield if appropriate.
void(* sched_callback_t)(kernel_pid_t active, kernel_pid_t next)
Scheduler run callback.
Definition: sched.h:227
waiting for a message response
Definition: sched.h:111
#define SCHED_PRIO_LEVELS
The number of thread priority levels.
Definition: sched.h:136
waiting for a locked mutex
Definition: sched.h:108
thread_status_t
Definition: sched.h:104
NORETURN void cpu_switch_context_exit(void)
Call context switching at thread exit.
#define KERNEL_PID_LAST
The last valid PID (inclusive).
Definition: kernel_types.h:73
void sched_register_cb(sched_callback_t callback)
Register a callback that will be called on every scheduler run.
sleeping
Definition: sched.h:107