Skip to content

Commit af6e300

Browse files
committed
Add atomic block helper for mutex lock
Previously, mutex_block_atomic() only updated the task state. Under the new scheduler design, the blocked task must also be removed from the ready queue. The existing helper _sched_block() does not match the mutex path because it operates on queue_t instead of list_t and also processes deferred timer work, which mutex locking does not require. This commit introduces _sched_block_mutex(), a helper that supports the list- based waiter structure and skips deferred timer handling. It will be used by the mutex lock APIs in a later change.
1 parent 10e1e89 commit af6e300

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/sys/task.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ uint64_t mo_uptime(void);
301301
*/
302302
void _sched_block(queue_t *wait_q);
303303

304+
/* Support mutex data structure */
305+
void _sched_block_mutex(list_t *waiters);
306+
304307
/* Application Entry Point */
305308

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

kernel/task.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,3 +1102,22 @@ void _sched_block(queue_t *wait_q)
11021102
self->state = TASK_BLOCKED;
11031103
_yield();
11041104
}
1105+
1106+
void _sched_block_mutex(list_t *waiters)
1107+
{
1108+
if (unlikely(!waiters || !kcb || !kcb->task_current ||
1109+
!kcb->task_current->data))
1110+
panic(ERR_SEM_OPERATION);
1111+
1112+
tcb_t *self = kcb->task_current->data;
1113+
1114+
/* Remove node from ready queue */
1115+
sched_dequeue_task(self);
1116+
1117+
if (list_pushback(waiters, self) != 0)
1118+
panic(ERR_SEM_OPERATION);
1119+
1120+
/* set blocked state - scheduler will skip blocked tasks */
1121+
self->state = TASK_BLOCKED;
1122+
_yield();
1123+
}

0 commit comments

Comments
 (0)