Skip to content

Commit b66b154

Browse files
committed
Add dequeue helper for mutex lock
Currently, mo_mutex_lock() will call mutex_block_atomic() to mark the running task as TASK_BLOCKED so that it won't be selected by the old scheduler. To support the ready queue consistency that always keeps runnable tasks, the dequeuing path should be included when mutex_block_atomic() is called. This commit adds _sched_blocked_dequeue() helper and will be applied in mutex_block_atomic() in the following commit.
1 parent b608ac8 commit b66b154

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/sys/task.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ uint64_t mo_uptime(void);
298298
*/
299299
void _sched_block(queue_t *wait_q);
300300

301+
/* Dequeue path for task with TASK_BLOCKED state. It must be called before task
302+
* state set as TASK_BLOCKED. Currently, this API is used in mutex lock case.*/
303+
void _sched_block_dequeue(tcb_t *blocked_task);
304+
301305
/* Application Entry Point */
302306

303307
/* The main entry point for the user application.

kernel/task.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ void sched_wakeup_task(tcb_t *task)
450450
sched_enqueue_task(task);
451451
}
452452

453+
/* Dequeue blocked task when mutex lock is triggered */
454+
void _sched_block_dequeue(tcb_t *blocked_task)
455+
{
456+
if (unlikely(!blocked_task || blocked_task->state != TASK_BLOCKED))
457+
return;
458+
459+
sched_dequeue_task(blocked_task);
460+
}
461+
453462
/* Efficient Round-Robin Task Selection with O(n) Complexity
454463
*
455464
* Selects the next ready task using circular traversal of the master task list.

0 commit comments

Comments
 (0)