[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH 4/8] kernel2: pm_scheduler_try_switch()
+ kernel2: pm_scheduler_try_switch() wechselt zu einem gegebenen Thread,
wenn dieser lauffähig ist.
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
src/kernel2/include/tasks.h | 3 +++
src/kernel2/src/tasks/scheduler.c | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h
index 382a362..fc0bc88 100644
--- a/src/kernel2/include/tasks.h
+++ b/src/kernel2/include/tasks.h
@@ -205,6 +205,9 @@ void pm_scheduler_push(pm_thread_t* thread);
/// Kontrolle vom aktuellen Kernelthread an einen anderen Thread abgeben
void pm_scheduler_yield(void);
+/// Versucht einen Taskwechsel zum übergebenen Thread
+void pm_scheduler_try_switch(pm_thread_t* thread);
+
/**
* Initialisierung
*/
diff --git a/src/kernel2/src/tasks/scheduler.c b/src/kernel2/src/tasks/scheduler.c
index bf282c2..43c8180 100644
--- a/src/kernel2/src/tasks/scheduler.c
+++ b/src/kernel2/src/tasks/scheduler.c
@@ -233,3 +233,23 @@ void pm_scheduler_yield(void)
asm volatile("int $0x30;" : : "a" (SYSCALL_PM_SLEEP));
}
+/**
+ * Macht den übergebenen Thread zum aktuellen Thread dieser CPU, wenn er
+ * momentan lauffähig ist. Wenn nicht, bleibt der bisherige Thread aktiv.
+ */
+void pm_scheduler_try_switch(pm_thread_t* thread)
+{
+ cpu_t* cpu;
+
+ if (thread->status != PM_STATUS_READY) {
+ return;
+ }
+
+ cpu = cpu_get_current();
+ if (cpu->thread != thread) {
+ pm_scheduler_push(cpu->thread);
+ pm_scheduler_get(thread);
+ thread->status = PM_STATUS_RUNNING;
+ cpu->thread = thread;
+ }
+}
--
1.6.0.2