kernel: preemptive and cooperative scheduler refactoring.
[bertos.git] / bertos / kern / proc.h
index c78735e89d2e54aa0c8e5c47fe4bfb33de28240d..9b4fe140efc8cb9312aec235012545330a1ae156 100644 (file)
@@ -37,7 +37,7 @@
  *
  * $WIZ$ module_name = "kernel"
  * $WIZ$ module_configuration = "bertos/cfg/cfg_proc.h"
- * $WIZ$ module_depends = "switch_ctx", "mtask"
+ * $WIZ$ module_depends = "switch_ctx"
  * $WIZ$ module_supports = "not atmega103"
  */
 
 #include <struct/list.h> // Node, PriNode
 
 #include <cfg/compiler.h>
-
-#if CONFIG_KERN_PREEMPT
-       #include <cfg/debug.h> // ASSERT()
-#endif
+#include <cfg/debug.h> // ASSERT()
 
 #include <cpu/types.h> // cpu_stack_t
 #include <cpu/frame.h> // CPU_SAVED_REGS_CNT
@@ -142,16 +139,24 @@ struct Process *proc_new_with_name(const char *name, void (*entry)(void), iptr_t
 void proc_exit(void);
 
 /**
- * Co-operative context switch.
- *
- * The process that calls this function will release the CPU before its cpu quantum
- * expires, the scheduler will run to select the next process that will take control
- * of the processor.
- * \note This function is available only if CONFIG_KERN is enabled
- * \sa cpu_relax(), which is the recommended method to release the cpu.
+ * Public scheduling class methods.
  */
 void proc_yield(void);
 
+#if CONFIG_KERN_PREEMPT
+bool proc_needPreempt(void);
+void proc_preempt(void);
+#else
+INLINE bool proc_needPreempt(void)
+{
+       return false;
+}
+
+INLINE void proc_preempt(void)
+{
+}
+#endif
+
 void proc_rename(struct Process *proc, const char *name);
 const char *proc_name(struct Process *proc);
 const char *proc_currentName(void);
@@ -163,7 +168,11 @@ const char *proc_currentName(void);
  * the returned pointer to the correct type.
  * \return Pointer to the user data of the current process.
  */
-iptr_t proc_currentUserData(void);
+INLINE iptr_t proc_currentUserData(void)
+{
+       extern struct Process *current_process;
+       return current_process->user_data;
+}
 
 int proc_testSetup(void);
 int proc_testRun(void);