doc: Fix style in documentation.
[bertos.git] / bertos / kern / proc_p.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
31  *
32  * -->
33  *
34  * \brief Internal scheduler structures and definitions for processes.
35  *
36  * \version $Id$
37  * \author Bernie Innocenti <bernie@codewiz.org>
38  */
39
40 #ifndef KERN_PROC_P_H
41 #define KERN_PROC_P_H
42
43 #include "cfg/cfg_proc.h"
44 #include "cfg/cfg_signal.h"
45 #include "cfg/cfg_monitor.h"
46
47 #include <cfg/compiler.h>
48
49 #include <cpu/types.h>        /* for cpu_stack_t */
50
51 #include <struct/list.h>
52
53 #if CONFIG_KERN_PREEMPT
54         #include <ucontext.h> // XXX
55 #endif
56
57 typedef struct Process
58 {
59 #if CONFIG_KERN_PRI
60         PriNode      link;        /**< Link Process into scheduler lists */
61 #else
62         Node         link;        /**< Link Process into scheduler lists */
63 #endif
64         cpu_stack_t  *stack;       /**< Per-process SP */
65         iptr_t       user_data;   /**< Custom data passed to the process */
66
67 #if CONFIG_KERN_SIGNALS
68         sigmask_t    sig_wait;    /**< Signals the process is waiting for */
69         sigmask_t    sig_recv;    /**< Received signals */
70 #endif
71
72 #if CONFIG_KERN_HEAP
73         uint16_t     flags;       /**< Flags */
74 #endif
75
76 #if CONFIG_KERN_HEAP | CONFIG_KERN_MONITOR | (ARCH & ARCH_EMUL)
77         cpu_stack_t  *stack_base;  /**< Base of process stack */
78         size_t       stack_size;  /**< Size of process stack */
79 #endif
80
81 #if CONFIG_KERN_PREEMPT
82         ucontext_t   context;
83 #endif
84
85 #if CONFIG_KERN_MONITOR
86         struct ProcMonitor
87         {
88                 Node        link;
89                 const char *name;
90         } monitor;
91 #endif
92
93 } Process;
94
95
96 /**
97  * \name Flags for Process.flags.
98  * \{
99  */
100 #define PF_FREESTACK  BV(0)  /**< Free the stack when process dies */
101 /*\}*/
102
103
104 /** Track running processes. */
105 extern REGISTER Process *CurrentProcess;
106
107 /**
108  * Track ready processes.
109  *
110  * Access to this list must be performed with interrupts disabled
111  */
112 extern REGISTER List     ProcReadyList;
113
114 #if CONFIG_KERN_PRI
115         #define SCHED_ENQUEUE_INTERNAL(proc) LIST_ENQUEUE(&ProcReadyList, &(proc)->link)
116 #else
117         #define SCHED_ENQUEUE_INTERNAL(proc) ADDTAIL(&ProcReadyList, &(proc)->link)
118 #endif
119
120 /**
121  * Enqueue a process in the ready list.
122  *
123  * Always use this macro to instert a process in the ready list, as its
124  * might vary to implement a different scheduling algorithms.
125  *
126  * \note Access to the scheduler ready list must be performed with
127  *       interrupts disabled.
128  */
129 #define SCHED_ENQUEUE(proc)  do { \
130                 IRQ_ASSERT_DISABLED(); \
131                 LIST_ASSERT_VALID(&ProcReadyList); \
132                 SCHED_ENQUEUE_INTERNAL(proc); \
133         } while (0)
134
135
136 /// Schedule another process *without* adding the current one to the ready list.
137 void proc_switch(void);
138
139 #if CONFIG_KERN_PREEMPT
140 void proc_entry(void (*user_entry)(void));
141 void preempt_init(void);
142 #endif
143
144 #if CONFIG_KERN_MONITOR
145         /** Initialize the monitor */
146         void monitor_init(void);
147
148         /** Register a process into the monitor */
149         void monitor_add(Process *proc, const char *name);
150
151         /** Unregister a process from the monitor */
152         void monitor_remove(Process *proc);
153
154         /** Rename a process */
155         void monitor_rename(Process *proc, const char *name);
156 #endif /* CONFIG_KERN_MONITOR */
157
158 #endif /* KERN_PROC_P_H */