kernel: Update k_wakeup()

This commit does two things to k_wakeup():

1. It locks the scheduler before marking the thread as not suspended.
As the the clearing of the _THREAD_SUSPENDED bit is not atomic, this
helps ensure that neither another thread nor ISR interrupts this
action (resulting in a corrupted thread_state).

2. The call to flag_ipi() has been removed as it is already being
made within ready_thread().

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
(cherry picked from commit 51ae993c12629d082f847885f52249432fc31bb2)
diff --git a/kernel/sched.c b/kernel/sched.c
index bb00923..13a7b14 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1653,13 +1653,18 @@
 		}
 	}
 
+	k_spinlock_key_t  key = k_spin_lock(&sched_spinlock);
+
 	z_mark_thread_as_not_suspended(thread);
-	z_ready_thread(thread);
 
-	flag_ipi();
+	if (!thread_active_elsewhere(thread)) {
+		ready_thread(thread);
+	}
 
-	if (!arch_is_in_isr()) {
-		z_reschedule_unlocked();
+	if (arch_is_in_isr()) {
+		k_spin_unlock(&sched_spinlock, key);
+	} else {
+		z_reschedule(&sched_spinlock, key);
 	}
 }