4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
34 * \brief Internal scheduler structures and definitions for processes.
37 * \author Bernie Innocenti <bernie@codewiz.org>
43 #include "cfg/cfg_kern.h"
44 #include <cfg/compiler.h>
46 #include <cpu/types.h> /* for cpu_stack_t */
48 #include <struct/list.h>
50 #if CONFIG_KERN_PREEMPTIVE
51 #include <ucontext.h> // XXX
54 typedef struct Process
56 Node link; /**< Link Process into scheduler lists */
57 cpustack_t *stack; /**< Per-process SP */
58 iptr_t user_data; /**< Custom data passed to the process */
60 #if CONFIG_KERN_SIGNALS
61 sigmask_t sig_wait; /**< Signals the process is waiting for */
62 sigmask_t sig_recv; /**< Received signals */
65 #if CONFIG_KERN_PREEMPTIVE
66 int forbid_cnt; /**< Nesting count for proc_forbid()/proc_permit(). */
67 bool leaving; /**< XXX: maybe global? */
72 uint16_t flags; /**< Flags */
75 #if CONFIG_KERN_HEAP | CONFIG_KERN_MONITOR | (ARCH & ARCH_EMUL)
76 cpustack_t *stack_base; /**< Base of process stack */
77 size_t stack_size; /**< Size of process stack */
80 #if CONFIG_KERN_MONITOR
92 * \name Flags for Process.flags.
95 #define PF_FREESTACK BV(0) /**< Free the stack when process dies */
99 /** Track running processes. */
100 extern REGISTER Process *CurrentProcess;
103 * Track ready processes.
105 * Access to this list must be protected with a proc_forbid() / proc_premit()
106 * pair, or with SCHED_ATOMIC()
108 extern REGISTER List ProcReadyList;
112 * Enqueue a task in the ready list.
114 * Always use this macro to instert a process in the ready list, as its
115 * might vary to implement a different scheduling algorithms.
117 * \note This macro is *NOT* protected against the scheduler. Access to
118 * this list must be performed with interrupts disabled.
120 #define SCHED_ENQUEUE(proc) ADDTAIL(&ProcReadyList, &(proc)->link)
122 /** Schedule to another process *without* adding the current to the ready list. */
123 void proc_schedule(void);
125 #if CONFIG_KERN_PREEMPT
126 void proc_entry(void (*user_entry)(void));
127 void preempt_init(void);
130 #if CONFIG_KERN_MONITOR
131 /** Initialize the monitor */
132 void monitor_init(void);
134 /** Register a process into the monitor */
135 void monitor_add(Process *proc, const char *name);
137 /** Unregister a process from the monitor */
138 void monitor_remove(Process *proc);
140 /** Rename a process */
141 void monitor_rename(Process *proc, const char *name);
142 #endif /* CONFIG_KERN_MONITOR */
144 #endif /* KERN_PROC_P_H */