bcd0a07bc02d184e72465d6ae28f45757e43b31f
[bertos.git] / kern / proc.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 README.devlib for information.
7  * -->
8  *
9  * \brief Process scheduler (public interface).
10  *
11  * \version $Id$
12  *
13  * \author Bernardo Innocenti <bernie@develer.com>
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.12  2006/07/19 12:56:27  bernie
19  *#* Convert to new Doxygen style.
20  *#*
21  *#* Revision 1.11  2006/02/21 16:06:55  bernie
22  *#* Cleanup/update process scheduling.
23  *#*
24  *#* Revision 1.10  2005/11/04 16:20:02  bernie
25  *#* Fix reference to README.devlib in header.
26  *#*
27  *#* Revision 1.9  2005/04/11 19:10:28  bernie
28  *#* Include top-level headers from cfg/ subdir.
29  *#*
30  *#* Revision 1.8  2004/11/16 22:37:14  bernie
31  *#* Replace IPTR with iptr_t.
32  *#*
33  *#* Revision 1.7  2004/10/19 08:54:55  bernie
34  *#* Define forbid_cnt.
35  *#*
36  *#* Revision 1.6  2004/10/03 20:44:18  bernie
37  *#* Remove stale declarations (moved to monitor.h).
38  *#*
39  *#* Revision 1.2  2004/06/03 11:27:09  bernie
40  *#* Add dual-license information.
41  *#*
42  *#* Revision 1.1  2004/05/23 17:27:00  bernie
43  *#* Import kern/ subdirectory.
44  *#*
45  *#*/
46
47 #ifndef KERN_PROC_H
48 #define KERN_PROC_H
49
50 #include <cfg/compiler.h>
51 #include <cfg/cpu.h>
52 #include <config_kern.h>
53
54 /* Fwd decl */
55 struct Process;
56
57 /* Task scheduling services */
58 void proc_init(void);
59 struct Process *proc_new_with_name(const char* name, void (*entry)(void), iptr_t data, size_t stacksize, cpustack_t *stack);
60
61 #if !CONFIG_KERN_MONITOR
62         #define proc_new(entry,data,size,stack) proc_new_with_name(NULL,(entry),(data),(size),(stack))
63 #else
64         #define proc_new(entry,data,size,stack) proc_new_with_name(#entry,(entry),(data),(size),(stack))
65 #endif
66
67 void proc_exit(void);
68 void proc_switch(void);
69 void proc_test(void);
70 struct Process* proc_current(void);
71 iptr_t proc_current_user_data(void);
72 void proc_rename(struct Process* proc, const char* name);
73
74 #if CONFIG_KERN_PREEMPTIVE
75         void proc_forbid(void);
76         void proc_permit(void);
77 #else
78         INLINE void proc_forbid(void) { /* nop */ }
79         INLINE void proc_permit(void) { /* nop */ }
80 #endif
81
82 /**
83  * Execute a block of \a CODE atomically with respect to task scheduling.
84  */
85 #define PROC_ATOMIC(CODE) \
86         do { \
87                 proc_forbid(); \
88                 CODE; \
89                 proc_permit(); \
90         } while(0)
91
92 #endif /* KERN_PROC_H */
93