Added non-static set priority function to scheduler
MODIFY
include/sched.h
include/sched.h
@@ -65,6 +65,16 @@ void sched_lend_prio(thread_t *td, prio_t prio);
*/
void sched_unlend_prio(thread_t *td, prio_t prio);
+/*! \brief Set thread's \a td_base_prio and \a td_prio to \a prio.
+ *
+ * Base priority \a td_base_prio is changed unconditionally.
+ * Active priority \a td_prio is changed on condition that we are not lowering
+ * priority of a thread that borrows priority via \a sched_lend_prio.
+ *
+ * \note Must be called with \a td_spin acquired!
+ */
+void sched_set_prio(thread_t *td, prio_t prio);
+
/*! \brief Takes care of run-time accounting for current thread.
*
* \note Must be called from interrupt context.

MODIFY
sys/sched.c
sys/sched.c
@@ -50,11 +50,11 @@ void sched_wakeup(thread_t *td) {
oldtd->td_flags |= TDF_NEEDSWITCH;
}
-/*! \brief Adjust thread's priority.
+/*! \brief Set thread's active priority \a td_prio to \a prio.
*
- * \note Must be called with td_spin acquired!
+ * \note Must be called with \a td_spin acquired!
*/
-static void sched_set_priority(thread_t *td, prio_t prio) {
+static void sched_set_active_prio(thread_t *td, prio_t prio) {
assert(spin_owned(td->td_spin));
if (td->td_prio == prio)
@@ -70,12 +70,24 @@ static void sched_set_priority(thread_t *td, prio_t prio) {
}
}
+void sched_set_prio(thread_t *td, prio_t prio) {
+ assert(spin_owned(td->td_spin));
+
+ td->td_base_prio = prio;
+
+ /* If thread is borrowing priority, don't lower its active priority. */
+ if (td->td_flags & TDF_BORROWING && td->td_prio > prio)
+ return;
+
+ sched_set_active_prio(td, prio);
+}
+
void sched_lend_prio(thread_t *td, prio_t prio) {
assert(spin_owned(td->td_spin));
assert(td->td_prio < prio);
td->td_flags |= TDF_BORROWING;
- sched_set_priority(td, prio);
+ sched_set_active_prio(td, prio);
}
void sched_unlend_prio(thread_t *td, prio_t prio) {
@@ -83,7 +95,7 @@ void sched_unlend_prio(thread_t *td, prio_t prio) {
if (prio <= td->td_base_prio) {
td->td_flags &= ~TDF_BORROWING;
- sched_set_priority(td, td->td_base_prio);
+ sched_set_active_prio(td, td->td_base_prio);
} else
sched_lend_prio(td, prio);
}

Added non-static set priority function to scheduler (#420)