Define forbid_cnt.
[bertos.git] / kern / proc_p.h
1 /*!
2  * \file
3  * <!--
4  * Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 1999, 2000, 2001 Bernardo Innocenti <bernie@develer.com>
6  * This file is part of DevLib - See devlib/README for information.
7  * -->
8  *
9  * \brief Internal scheduler structures and definitions for processes.
10  *
11  * \version $Id$
12  *
13  * \author Bernardo Innocenti <bernie@develer.com>
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.9  2004/10/19 08:55:31  bernie
19  *#* Define forbid_cnt.
20  *#*
21  *#* Revision 1.8  2004/10/03 20:39:28  bernie
22  *#* Import changes from sc/firmware.
23  *#*
24  *#* Revision 1.7  2004/08/25 14:12:09  rasky
25  *#* Aggiornato il comment block dei log RCS
26  *#*
27  *#* Revision 1.6  2004/08/24 16:05:15  bernie
28  *#* Add missing headers; Reformat.
29  *#*
30  *#* Revision 1.5  2004/08/14 19:37:57  rasky
31  *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
32  *#*
33  *#* Revision 1.4  2004/07/30 14:24:16  rasky
34  *#* Task switching con salvataggio perfetto stato di interrupt (SR)
35  *#* Kernel monitor per dump informazioni su stack dei processi
36  *#*
37  *#* Revision 1.3  2004/07/14 14:18:09  rasky
38  *#* Merge da SC: Rimosso timer dentro il task, che รจ uno spreco di memoria per troppi task
39  *#*
40  *#* Revision 1.2  2004/06/03 11:27:09  bernie
41  *#* Add dual-license information.
42  *#*
43  *#* Revision 1.1  2004/05/23 17:27:00  bernie
44  *#* Import kern/ subdirectory.
45  *#*
46  *#* Revision 1.3  2004/05/14 12:52:13  rasky
47  *#* Importato supporto kernel per AVR da Stefano
48  *#*
49  *#* Revision 1.2  2004/04/28 16:13:49  rasky
50  *#* proc_schedule() is now semi-private (used only within the kernel)
51  *#*
52  *#* Revision 1.1  2004/04/26 18:02:40  rasky
53  *#* Importato microkernel
54  *#*
55  *#* Revision 1.1  2004/04/04 17:40:26  aleph
56  *#* Add multithreading kernel
57  *#*
58  *#*/
59 #ifndef KERN_PROC_P_H
60 #define KERN_PROC_P_H
61
62 #include "compiler.h"
63 #include "cpu.h"        /* for cpu_stack_t */
64 #include "config.h"
65 #include "config_kern.h"
66 #include <mware/list.h>
67
68 typedef struct Process
69 {
70         Node         link;        /*!< Link Process into scheduler lists */
71         cpustack_t  *stack;       /*!< Per-process SP */
72         IPTR         user_data;   /*!< Custom data passed to the process */
73
74 #if CONFIG_KERN_SIGNALS
75         sigset_t     sig_wait;    /*!< Signals the process is waiting for */
76         sigset_t     sig_recv;    /*!< Received signals */
77 #endif
78
79 #if CONFIG_PROC_PREEMPTIVE
80         int          forbid_cnt;  /*!< Nesting count for proc_forbid()/proc_permit(). */
81
82 #if CONFIG_KERN_HEAP
83         uint16_t     flags;       /*!< Flags */
84         cpustack_t  *stack_base;  /*!< Base of process stack */
85         size_t       stack_size;  /*!< Size of process stack */
86 #endif
87
88 #if CONFIG_KERN_MONITOR
89         struct ProcMonitor
90         {
91                 Node        link;
92                 const char *name;
93                 cpustack_t *stack_base;
94                 size_t      stack_size;
95         } monitor;
96 #endif
97
98 } Process;
99
100
101 /*!
102  * \name Flags for Process.flags.
103  * \{
104  */
105 #define PF_FREESTACK  BV(0)  /*!< Free the stack when process dies */
106 /*\}*/
107
108
109 /*! Track running processes. */
110 extern REGISTER Process *CurrentProcess;
111
112 /*! Track ready processes. */
113 extern REGISTER List     ProcReadyList;
114
115
116 /*! Enqueue a task in the ready list. */
117 #define SCHED_ENQUEUE(proc)  ADDTAIL(&ProcReadyList, &(proc)->link)
118
119 /*! Schedule to another process *without* adding the current to the ready list. */
120 void proc_schedule(void);
121
122 #if CONFIG_KERN_MONITOR
123         /*! Initialize the monitor */
124         void monitor_init(void);
125
126         /*! Register a process into the monitor */
127         void monitor_add(Process *proc, const char *name, cpustack_t *stack, size_t stacksize);
128
129         /*! Unregister a process from the monitor */
130         void monitor_remove(Process *proc);
131
132         /*! Rename a process */
133         void monitor_rename(Process *proc, const char* name);
134 #endif /* CONFIG_KERN_MONITOR */
135
136 #endif /* KERN_PROC_P_H */
137