The friendly Operating System for the Internet of Things
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 SCHEDULER_H
81 #define SCHEDULER_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 #ifndef SCHED_PRIO_LEVELS
104 #define SCHED_PRIO_LEVELS 16
105 #endif
106 
111 int sched_run(void);
112 
120 void sched_set_status(thread_t *process, unsigned int status);
121 
134 void sched_switch(uint16_t other_prio);
135 
140 
145 extern volatile unsigned int sched_context_switch_request;
146 
150 extern volatile thread_t *sched_threads[KERNEL_PID_LAST + 1];
151 
155 extern volatile thread_t *sched_active_thread;
156 
160 extern volatile int sched_num_threads;
161 
165 extern volatile kernel_pid_t sched_active_pid;
166 
171 
175 NORETURN void sched_task_exit(void);
176 
177 #ifdef MODULE_SCHEDSTATISTICS
178 
181 typedef struct {
182  unsigned int laststart;
184  unsigned int schedules;
185  unsigned long runtime_ticks;
186 } schedstat;
187 
191 extern schedstat sched_pidlist[KERNEL_PID_LAST + 1];
192 
198 void sched_register_cb(void (*callback)(uint32_t, uint32_t));
199 #endif /* MODULE_SCHEDSTATISTICS */
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif /* SCHEDULER_H */
206 
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.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
clist_node_t sched_runqueues[SCHED_PRIO_LEVELS]
List of runqueues per priority level.
#define KERNEL_PID_LAST
The last valid PID (inclusive).
Definition: kernel_types.h:73
thread_t holds thread's context data.
Definition: thread.h:169
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.
volatile int sched_num_threads
Number of running (non-terminated) threads.
NORETURN void sched_task_exit(void)
Removes thread from scheduler and set status to STATUS_STOPPED.
Add definitions required on the native board.
List node structure.
Definition: list.h:40
uint8_t status
thread's status
Definition: thread.h:171
Helper functions for bit arithmetic.
Common macros and compiler attributes/pragmas configuration.
Circular linked list.
void sched_switch(uint16_t other_prio)
Yield if approriate.
void sched_set_status(thread_t *process, unsigned int status)
Set the status of the specified process.
#define SCHED_PRIO_LEVELS
The number of thread priority levels.
Definition: sched.h:104
#define NORETURN
The NORETURN keyword tells the compiler to assume that the function cannot return.
NORETURN void cpu_switch_context_exit(void)
Call context switching at thread exit.