Skip to content

Commit 737ef54

Browse files
committed
Add enqueue helper for mutex/semaphore operations
Currently, there is no enqueueing API that can be invoked from other files, especially in mutex and semaphore operations which include task state transition from TASK_BLOCKED to TASK_READY when a held resource is released. This change introduces the _sched_blocked_enqueue() helper, which will be used by mutex/semaphore unblocking paths to insert the task’s existing linkage node into the corresponding per-priority ready queue, keeping scheduler visibility and ready-queue consistency.
1 parent c4d4de6 commit 737ef54

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/sys/task.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ void _sched_block(queue_t *wait_q);
302302
* state set as TASK_BLOCKED. Currently, this API is used in mutex lock case.*/
303303
void _sched_block_dequeue(tcb_t *blocked_task);
304304

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+
305309
/* Application Entry Point */
306310

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

kernel/task.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,14 @@ void _sched_block_dequeue(tcb_t *blocked_task)
459459
sched_dequeue_task(blocked_task);
460460
}
461461

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+
462470
/* Efficient Round-Robin Task Selection with O(n) Complexity
463471
*
464472
* Selects the next ready task using circular traversal of the master task list.

0 commit comments

Comments
 (0)