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 "bitarithm.h"
86 #include "kernel_types.h"
87 #include "native_sched.h"
88 #include "clist.h"
89 
90 #ifdef __cplusplus
91  extern "C" {
92 #endif
93 
97 typedef struct _thread thread_t;
98 
103 typedef enum {
124 #define STATUS_ON_RUNQUEUE STATUS_RUNNING
126 #define STATUS_NOT_FOUND ((thread_status_t)-1)
132 #ifndef SCHED_PRIO_LEVELS
133 #define SCHED_PRIO_LEVELS 16
134 #endif
135 
140 int sched_run(void);
141 
149 void sched_set_status(thread_t *process, thread_status_t status);
150 
163 void sched_switch(uint16_t other_prio);
164 
169 
174 extern volatile unsigned int sched_context_switch_request;
175 
179 extern volatile thread_t *sched_threads[KERNEL_PID_LAST + 1];
180 
184 extern volatile thread_t *sched_active_thread;
185 
189 extern volatile int sched_num_threads;
190 
194 extern volatile kernel_pid_t sched_active_pid;
195 
200 
204 NORETURN void sched_task_exit(void);
205 
206 #ifdef MODULE_SCHED_CB
207 
212 void sched_register_cb(void (*callback)(kernel_pid_t, kernel_pid_t));
213 #endif /* MODULE_SCHED_CB */
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* SCHED_H */
220 
Types used by the kernel.
int sched_run(void)
Triggers the scheduler to schedule the next thread.
volatile kernel_pid_t sched_active_pid
Process ID of active thread.
waiting for any flag from flag_mask
Definition: sched.h:110
has terminated
Definition: sched.h:104
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:115
currently running
Definition: sched.h:114
thread_status_t status
thread&#39;s status
Definition: thread.h:146
waiting for a condition variable
Definition: sched.h:113
number of supported thread states
Definition: sched.h:116
thread_t holds thread&#39;s context data.
Definition: thread.h:144
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.
volatile thread_t * sched_active_thread
Currently active thread.
waiting for all flags in flag_mask
Definition: sched.h:111
volatile int sched_num_threads
Number of running (non-terminated) threads.
waiting for get/put on mbox
Definition: sched.h:112
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
Helper functions for bit arithmetic.
waiting for a message
Definition: sched.h:107
Common macros and compiler attributes/pragmas configuration.
waiting for message to be delivered
Definition: sched.h:108
Circular linked list.
void sched_switch(uint16_t other_prio)
Yield if appropriate.
waiting for a message response
Definition: sched.h:109
#define SCHED_PRIO_LEVELS
The number of thread priority levels.
Definition: sched.h:134
waiting for a locked mutex
Definition: sched.h:106
thread_status_t
Definition: sched.h:103
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
sleeping
Definition: sched.h:105