#include "detect.h"
#include "types.h"
-#include <kern/preempt.h>
+#include <kern/proc.h> /* proc_needPreempt() / proc_preempt() */
#include <cfg/compiler.h> /* for uintXX_t */
#include "cfg/cfg_proc.h" /* CONFIG_KERN_PREEMPT */
* System scheduler: pass CPU control to the next process in
* the ready queue.
*/
-static void proc_schedule(void)
+static void coop_schedule(void)
{
cpu_flags_t flags;
IRQ_RESTORE(flags);
}
-void proc_switch(void)
+void coop_switch(void)
{
/* Remember old process to save its context later */
Process * const old_process = current_process;
- proc_schedule();
+ coop_schedule();
/*
* Optimization: don't switch contexts when the active
/**
* Co-operative context switch
*/
-void proc_yield(void)
+void coop_yield(void)
{
ATOMIC(SCHED_ENQUEUE(current_process));
proc_switch();
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2001, 2004, 2008 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999, 2000, 2001, 2008 Bernie Innocenti <bernie@codewiz.org>
- * -->
- *
- * \brief Choose the multitasking scheduler.
- *
- * \author Francesco Sacchi <batt@develer.com>
- */
-
-
-#include "cfg/cfg_proc.h"
-
-/*
- * Choose which file to compile depending on
- * the multitasking type.
- */
-#if CONFIG_KERN_PREEMPT
- #include "preempt.c"
-#else
- #include "coop.c"
-#endif
-
* the time sharing interval.
*
* When the quantum expires the handler proc_needPreempt() checks if the
- * preemption is enabled and in this case proc_schedule() is called, that
+ * preemption is enabled and in this case preempt_schedule() is called, that
* possibly replaces the current running thread with a different one.
*
* The preemption can be disabled or enabled via proc_forbid() and
/**
* Call the scheduler and eventually replace the current running process.
*/
-static void proc_schedule(void)
+static void preempt_schedule(void)
{
Process *old_process = current_process;
/**
* Check if we need to schedule another task
*/
-int proc_needPreempt(void)
+int preempt_needPreempt(void)
{
if (UNLIKELY(current_process == NULL))
return 0;
/**
* Preempt the current task.
*/
-void proc_preempt(void)
+void preempt_preempt(void)
{
IRQ_ASSERT_DISABLED();
ASSERT(current_process);
/* We are inside a IRQ context, so ATOMIC is not needed here */
if (current_process != idle_proc)
SCHED_ENQUEUE(current_process);
- proc_schedule();
+ preempt_schedule();
}
/**
* \warning This should be considered an internal kernel function, even if it
* is allowed, usage from application code is strongly discouraged.
*/
-void proc_switch(void)
+void preempt_switch(void)
{
ASSERT(proc_preemptAllowed());
IRQ_ASSERT_ENABLED();
- ATOMIC(proc_schedule());
+ ATOMIC(preempt_schedule());
}
/**
* Voluntarily release the CPU.
*/
-void proc_yield(void)
+void preempt_yield(void)
{
/*
* Voluntary preemption while preemption is disabled is considered
ATOMIC(
SCHED_ENQUEUE(current_process);
- proc_schedule();
+ preempt_schedule();
);
}
#include <cfg/compiler.h>
#if CONFIG_KERN_PREEMPT
- void preempt_init(void);
- void proc_preempt(void);
- int proc_needPreempt(void);
-
INLINE void proc_decQuantum(void)
{
extern int _proc_quantum;
monitor_init();
monitor_add(current_process, "main");
#endif
-
-#if CONFIG_KERN_PREEMPT
- preempt_init();
-#endif
+ proc_schedInit();
MOD_INIT(proc);
}
*
* $WIZ$ module_name = "kernel"
* $WIZ$ module_configuration = "bertos/cfg/cfg_proc.h"
- * $WIZ$ module_depends = "switch_ctx", "mtask"
+ * $WIZ$ module_depends = "switch_ctx", "coop", "preempt"
* $WIZ$ module_supports = "not atmega103"
*/
#if CONFIG_KERN_PREEMPT
#include <cfg/debug.h> // ASSERT()
+ #include <kern/preempt.h>
#endif
#include <cpu/types.h> // cpu_stack_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);
+void proc_preempt(void);
+int proc_needPreempt(void);
+
+/**
+ * Dummy function that defines unimplemented scheduler class methods.
+ */
+INLINE void __proc_noop(void)
+{
+}
+
+#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_init proc_schedInit
+#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 proc_schedInit __proc_noop
+#endif
void proc_rename(struct Process *proc, const char *name);
const char *proc_name(struct Process *proc);
}
#endif //CONFIG_KERN_PRI
-/// Schedule another process *without* adding the current one to the ready list.
-void proc_switch(void);
+/* Process trampoline */
void proc_entry(void);
+/* Schedule another process *without* adding the current one to the ready list. */
+void proc_switch(void);
+
+/* Initialize a scheduler class. */
+void proc_schedInit(void);
+
#if CONFIG_KERN_MONITOR
/** Initialize the monitor */
void monitor_init(void);
bertos/mware/sprintf.c \
bertos/kern/kfile.c \
bertos/kern/proc.c \
- bertos/kern/mtask.c \
+ bertos/kern/coop.c \
+ bertos/kern/preempt.c \
bertos/kern/idle.c \
bertos/kern/proc_test.c \
bertos/kern/monitor.c \
bertos/struct/heap.c \
bertos/kern/kfile.c \
bertos/kern/proc.c \
- bertos/kern/mtask.c \
+ bertos/kern/coop.c \
+ bertos/kern/preempt.c \
bertos/kern/idle.c \
bertos/kern/proc_test.c \
bertos/kern/monitor.c \
bertos/mware/sprintf.c \
bertos/struct/heap.c \
bertos/kern/idle.c \
- bertos/kern/mtask.c \
+ bertos/kern/coop.c \
+ bertos/kern/preempt.c \
bertos/kern/irq.c \
bertos/kern/proc.c \
bertos/kern/proc_test.c \
fi
CPU_TARGET=$1
EXCLUDE_DIRS="$COPY_DIR $CPU_DIR $APP_DIR $OS_DIR $WIZARD_DIR $EMUL_DIR $FAT_DIR $NMEA_DIR"
-EXCLUDE_CMD="\.svn -or -name preempt.c -or -name coop.c -prune "
+EXCLUDE_CMD="\.svn -prune "
for i in $EXCLUDE_DIRS; do
EXCLUDE_CMD="$EXCLUDE_CMD -o -path $i -prune ";
done
bertos/kern/proc.c
bertos/kern/signal.c
bertos/kern/sem.c
- bertos/kern/mtask.c
+ bertos/kern/coop.c
+ bertos/kern/preempt.c
bertos/mware/event.c
bertos/mware/formatwr.c
bertos/mware/hex.c