Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sched: add nxsched_remove_self #13418

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions sched/mqueue/mq_rcvinternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
{
FAR struct mqueue_msg_s *newmsg;
FAR struct tcb_s *rtcb;
bool switch_needed;

DEBUGASSERT(rcvmsg != NULL);

Expand Down Expand Up @@ -186,21 +185,18 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,

DEBUGASSERT(!is_idle_task(rtcb));

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_self(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTEMPTY;
nxsched_add_prioritized(rtcb, MQ_WNELIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/mqueue/mq_sndinternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ FAR struct mqueue_msg_s *nxmq_alloc_msg(void)
int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
{
FAR struct tcb_s *rtcb;
bool switch_needed;

#ifdef CONFIG_CANCELLATION_POINTS
/* nxmq_wait_send() is not a cancellation point, but may be called via
Expand Down Expand Up @@ -271,21 +270,18 @@ int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)

DEBUGASSERT(!is_idle_task(rtcb));

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_self(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTFULL;
nxsched_add_prioritized(rtcb, MQ_WNFLIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/mqueue/msgrcv.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static int msgrcv_wait(FAR struct msgq_s *msgq, FAR struct msgbuf_s **rcvmsg,
FAR struct msgbuf_s *newmsg = NULL;
FAR struct msgbuf_s *tmp;
FAR struct tcb_s *rtcb;
bool switch_needed;

#ifdef CONFIG_CANCELLATION_POINTS
/* msgrcv_wait() is not a cancellation point, but it may be called
Expand Down Expand Up @@ -129,21 +128,18 @@ static int msgrcv_wait(FAR struct msgq_s *msgq, FAR struct msgbuf_s **rcvmsg,

DEBUGASSERT(NULL != rtcb->flink);

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_self(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTEMPTY;
nxsched_add_prioritized(rtcb, MQ_WNELIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/mqueue/msgsnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
static int msgsnd_wait(FAR struct msgq_s *msgq, int msgflg)
{
FAR struct tcb_s *rtcb;
bool switch_needed;

#ifdef CONFIG_CANCELLATION_POINTS
/* msgsnd_wait() is not a cancellation point, but may be called via
Expand Down Expand Up @@ -95,21 +94,18 @@ static int msgsnd_wait(FAR struct msgq_s *msgq, int msgflg)

DEBUGASSERT(NULL != rtcb->flink);

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_self(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTFULL;
nxsched_add_prioritized(rtcb, MQ_WNFLIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/paging/pg_miss.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void pg_miss(void)
{
FAR struct tcb_s *ftcb = this_task();
FAR struct tcb_s *wtcb;
bool switch_needed;

/* Sanity checking
*
Expand All @@ -138,21 +137,18 @@ void pg_miss(void)

DEBUGASSERT(!is_idle_task(ftcb));

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(ftcb, true);
nxsched_remove_self(ftcb);

/* Add the task to the specified blocked task list */

ftcb->task_state = TSTATE_WAIT_PAGEFILL;
nxsched_add_prioritized(ftcb, list_waitingforfill());

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), ftcb);
}
up_switch_context(this_task(), ftcb);

/* Boost the page fill worker thread priority.
* - Check the priority of the task at the head of the g_waitingforfill
Expand Down
1 change: 1 addition & 0 deletions sched/sched/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,

bool nxsched_add_readytorun(FAR struct tcb_s *rtrtcb);
bool nxsched_remove_readytorun(FAR struct tcb_s *rtrtcb, bool merge);
void nxsched_remove_self(FAR struct tcb_s *rtrtcb);
bool nxsched_add_prioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list);
void nxsched_merge_prioritized(FAR dq_queue_t *list1, FAR dq_queue_t *list2,
uint8_t task_state);
Expand Down
Loading
Loading