Skip to content

Commit a7ace5e

Browse files
committed
Add ready queue helpers for mutex/semaphore
Add scheduler queue helpers _sched_block_enqueue() and _sched_block_dequeue() in task.c, enabling ready-queue manipulation from outside the scheduler core, which was previously unsupported. Apply these helpers to mutex/semaphore operations to ensure that each blocking or wakeup transition updates the corresponding ready queue, keeping scheduler state and mutex/semaphore semantics consistent. Name both helpers with the _sched_block prefix to clearly reflect their role in TASK_BLOCKED state transitions.
1 parent 613c9d3 commit a7ace5e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/sys/task.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ 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+
305+
/* Enqueue path for the task with TASK_BLOCKED state. This API is the mainly
306+
* enqueuing path for semaphore and mutex operations. */
307+
void _sched_block_enqueue(tcb_t *blocked_task);
308+
301309
/* Application Entry Point */
302310

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

kernel/task.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,23 @@ 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+
462+
void _sched_block_enqueue(tcb_t *blocked_task)
463+
{
464+
if (unlikely(!blocked_task || blocked_task->state != TASK_BLOCKED))
465+
return;
466+
467+
sched_enqueue_task(blocked_task);
468+
}
469+
453470
/* Efficient Round-Robin Task Selection with O(n) Complexity
454471
*
455472
* Selects the next ready task using circular traversal of the master task list.

0 commit comments

Comments
 (0)