X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fproc.h;h=2849ca17588a989882dc3695598f273cc9ad2202;hb=e354ab2035ca31d1cac3e736917925a49aa000eb;hp=bacd052be848fdebf85b826ece98fb527a88ca63;hpb=f149112c04843df99b2c9e9fd2ef47d9cacae8a4;p=bertos.git diff --git a/bertos/kern/proc.h b/bertos/kern/proc.h index bacd052b..2849ca17 100644 --- a/bertos/kern/proc.h +++ b/bertos/kern/proc.h @@ -30,14 +30,62 @@ * Copyright 1999, 2000, 2001, 2008 Bernie Innocenti * --> * + * \defgroup kern_proc Process (Threads) management + * \ingroup kern + * \{ + * * \brief BeRTOS Kernel core (Process scheduler). * - * \version $Id$ + * This is the core kernel module. It allows you to create new processes + * (which are called \b threads in other systems) and set the priority of + * each process. + * + * A process needs a work area (called \b stack) to run. To create a process, + * you need to declare a stack area, then create the process. + * You may also pass NULL for the stack area, if you have enabled kernel heap: + * in this case the stack will be automatically allocated. + * + * Example: + * \code + * PROC_DEFINE_STACK(stack1, 200); + * + * void NORETURN proc1_run(void) + * { + * while (1) + * { + * LOG_INFO("I'm alive!\n"); + * timer_delay(1000); + * } + * } + * + * + * int main() + * { + * Process *p1 = proc_new(proc1_run, NULL, stack1, sizeof(stack1)); + * // here the process is already running + * proc_setPri(p1, 2); + * // ... + * } + * \endcode + * + * The Process struct must be regarded as an opaque data type, do not access + * any of its members directly. + * + * The entry point function should be declared as NORETURN, because it will + * remove a warning and enable compiler optimizations. + * + * You can temporarily disable preemption calling proc_forbid(); remember + * to enable it again calling proc_permit(). + * + * \note You should hardly need to manually release the CPU; however you + * can do it using the cpu_relax() function. It is illegal to release + * the CPU with preemption disabled. + * * \author Bernie Innocenti * * $WIZ$ module_name = "kernel" * $WIZ$ module_configuration = "bertos/cfg/cfg_proc.h" - * $WIZ$ module_depends = "switch_ctx", "coop", "preempt" + * $WIZ$ module_depends = "switch_ctx" * $WIZ$ module_supports = "not atmega103" */ @@ -51,11 +99,7 @@ #include // Node, PriNode #include - -#if CONFIG_KERN_PREEMPT - #include // ASSERT() - #include -#endif +#include // ASSERT() #include // cpu_stack_t #include // CPU_SAVED_REGS_CNT @@ -142,45 +186,23 @@ struct Process *proc_new_with_name(const char *name, void (*entry)(void), iptr_t */ void proc_exit(void); -/** +/* * Public scheduling class methods. */ void proc_yield(void); -void proc_preempt(void); -int proc_needPreempt(void); -void proc_wakeup(Process *proc); -/** - * Dummy function that defines unimplemented scheduler class methods. - */ -INLINE void __proc_noop(void) +#if CONFIG_KERN_PREEMPT +bool proc_needPreempt(void); +void proc_preempt(void); +#else +INLINE bool proc_needPreempt(void) { + return false; } -#if CONFIG_KERN_PREEMPT - /** - * Preemptive scheduler public methods. - */ - #define preempt_yield proc_yield - #define preempt_needPreempt proc_needPreempt - #define preempt_preempt proc_preempt - /** - * Preemptive scheduler: private methods. - */ - #define preempt_switch proc_switch - #define preempt_wakeup proc_wakeup -#else - /** - * Co-operative scheduler: public methods. - */ - #define coop_yield proc_yield - #define proc_needPreempt __proc_noop - #define proc_preempt __proc_noop - /** - * Co-operative scheduler: private methods. - */ - #define coop_switch proc_switch - #define coop_wakeup proc_wakeup +INLINE void proc_preempt(void) +{ +} #endif void proc_rename(struct Process *proc, const char *name); @@ -423,5 +445,6 @@ INLINE struct Process *proc_current(void) #error No cpu_stack_t size supported! #endif #endif +/** \} */ //defgroup kern_proc #endif /* KERN_PROC_H */