kern: Unify stack_base/stack_size copies in Process
[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  *
38  * \author Bernie Innocenti <bernie@codewiz.org>
39  */
40
41 #ifndef KERN_PROC_P_H
42 #define KERN_PROC_P_H
43
44 #include "cfg/cfg_kern.h"
45 #include <cfg/compiler.h>
46
47 #include <cpu/types.h>        /* for cpu_stack_t */
48
49 #include <mware/list.h>
50
51 typedef struct Process
52 {
53         Node         link;        /**< Link Process into scheduler lists */
54         cpustack_t  *stack;       /**< Per-process SP */
55         iptr_t       user_data;   /**< Custom data passed to the process */
56
57 #if CONFIG_KERN_SIGNALS
58         sigmask_t    sig_wait;    /**< Signals the process is waiting for */
59         sigmask_t    sig_recv;    /**< Received signals */
60 #endif
61
62 #if CONFIG_KERN_PREEMPTIVE
63         int          forbid_cnt;  /**< Nesting count for proc_forbid()/proc_permit(). */
64 #endif
65
66 #if CONFIG_KERN_HEAP
67         uint16_t     flags;       /**< Flags */
68 #endif
69
70 #if CONFIG_KERN_HEAP | CONFIG_KERN_MONITOR | (ARCH & ARCH_EMUL)
71         cpustack_t  *stack_base;  /**< Base of process stack */
72         size_t       stack_size;  /**< Size of process stack */
73 #endif
74
75 #if CONFIG_KERN_MONITOR
76         struct ProcMonitor
77         {
78                 Node        link;
79                 const char *name;
80         } monitor;
81 #endif
82
83 } Process;
84
85
86 /**
87  * \name Flags for Process.flags.
88  * \{
89  */
90 #define PF_FREESTACK  BV(0)  /**< Free the stack when process dies */
91 /*\}*/
92
93
94 /** Track running processes. */
95 extern REGISTER Process *CurrentProcess;
96
97 /** Track ready processes. */
98 extern REGISTER List     ProcReadyList;
99
100
101 /** Enqueue a task in the ready list. */
102 #define SCHED_ENQUEUE(proc)  ADDTAIL(&ProcReadyList, &(proc)->link)
103
104 /** Schedule to another process *without* adding the current to the ready list. */
105 void proc_schedule(void);
106
107 #if CONFIG_KERN_MONITOR
108         /** Initialize the monitor */
109         void monitor_init(void);
110
111         /** Register a process into the monitor */
112         void monitor_add(Process *proc, const char *name);
113
114         /** Unregister a process from the monitor */
115         void monitor_remove(Process *proc);
116
117         /** Rename a process */
118         void monitor_rename(Process *proc, const char *name);
119 #endif /* CONFIG_KERN_MONITOR */
120
121 #endif /* KERN_PROC_P_H */
122