kernel: fix issues in idle thread
- Add missing irq_lock() before invoking power management.
- Only yield if the idle thread is a coop thread (in coop-only
configurations).
Change-Id: I030795e782590b3023f1d7883bbd058da2c45f4f
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
diff --git a/kernel/unified/idle.c b/kernel/unified/idle.c
index f3b6fb5..9631dfd 100644
--- a/kernel/unified/idle.c
+++ b/kernel/unified/idle.c
@@ -127,6 +127,12 @@
}
+#if K_IDLE_PRIO < 0
+#define IDLE_YIELD_IF_COOP() k_yield()
+#else
+#define IDLE_YIELD_IF_COOP() do { } while ((0))
+#endif
+
void idle(void *unused1, void *unused2, void *unused3)
{
ARG_UNUSED(unused1);
@@ -142,8 +148,9 @@
#endif
for (;;) {
+ (void)irq_lock();
_sys_power_save_idle(_get_next_timeout_expiry());
- k_yield();
+ IDLE_YIELD_IF_COOP();
}
}