X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fproc.h;h=19bb5efaa23a4ec10338382ff61de286b238cc55;hb=088cc866a57a0402f6ba3f232fcf8f59c79626d1;hp=9b4fe140efc8cb9312aec235012545330a1ae156;hpb=f35b6066ecdeffcc8998dd566b5246bdcf43c548;p=bertos.git diff --git a/bertos/kern/proc.h b/bertos/kern/proc.h index 9b4fe140..19bb5efa 100644 --- a/bertos/kern/proc.h +++ b/bertos/kern/proc.h @@ -30,9 +30,57 @@ * 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" @@ -47,6 +95,7 @@ #include "cfg/cfg_proc.h" #include "cfg/cfg_signal.h" #include "cfg/cfg_monitor.h" +#include "sem.h" #include // Node, PriNode @@ -56,6 +105,13 @@ #include // cpu_stack_t #include // CPU_SAVED_REGS_CNT +/* The following silents warnings on nightly tests. We need to regenerate + * all the projects before this can be removed. + */ +#ifndef CONFIG_KERN_PRI_INHERIT +#define CONFIG_KERN_PRI_INHERIT 0 +#endif + /* * WARNING: struct Process is considered private, so its definition can change any time * without notice. DO NOT RELY on any field defined here, use only the interface @@ -67,6 +123,12 @@ typedef struct Process { #if CONFIG_KERN_PRI PriNode link; /**< Link Process into scheduler lists */ +# if CONFIG_KERN_PRI_INHERIT + PriNode inh_link; /**< Link Process into priority inheritance lists */ + List inh_list; /**< Priority inheritance list for this Process */ + Semaphore *inh_blocked_by; /**< Semaphore blocking this Process */ + int orig_pri; /**< Process priority without considering inheritance */ +# endif #else Node link; /**< Link Process into scheduler lists */ #endif @@ -74,8 +136,7 @@ typedef struct Process iptr_t user_data; /**< Custom data passed to the process */ #if CONFIG_KERN_SIGNALS - sigmask_t sig_wait; /**< Signals the process is waiting for */ - sigmask_t sig_recv; /**< Received signals */ + Signal sig; #endif #if CONFIG_KERN_HEAP @@ -138,7 +199,7 @@ 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); @@ -193,10 +254,20 @@ INLINE struct Process *proc_current(void) #if CONFIG_KERN_PRI void proc_setPri(struct Process *proc, int pri); + + INLINE int proc_pri(struct Process *proc) + { + return proc->link.pri; + } #else INLINE void proc_setPri(UNUSED_ARG(struct Process *,proc), UNUSED_ARG(int, pri)) { } + + INLINE int proc_pri(UNUSED_ARG(struct Process *, proc)) + { + return 0; + } #endif #if CONFIG_KERN_PREEMPT @@ -397,5 +468,6 @@ INLINE struct Process *proc_current(void) #error No cpu_stack_t size supported! #endif #endif +/** \} */ //defgroup kern_proc #endif /* KERN_PROC_H */