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

Pend a yield in vPortCloseRunningThread #1132

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Conversation

aggarg
Copy link
Member

@aggarg aggarg commented Aug 29, 2024

Description

When a task deletes itself, vTaskDelete calls portPRE_TASK_DELETE_HOOK which translates to vPortCloseRunningThread on the Windows port. vPortCloseRunningThread never returns and as a result, taskYIELD_WITHIN_API in vTaskDelete does not get called. As a result, the next task is not scheduled when configUSE_PREEMPTION is set to 0.

This change records that a yield is pending in vPortCloseRunningThread so that the next tick interrupt schedules the next task regardless of the value of configUSE_PREEMPTION.

Test Steps

static void lowPrioTask(void* pvParam)
{
    (void)pvParam;

    for (;;)
    {
        printf("Low prio Task\r\n");
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

static void highPrioTask(void* pvParam)
{
    (void)pvParam;

    vTaskDelete(NULL);
}

void app_main(void)
{
    xTaskCreate(lowPrioTask, "low", 512, NULL, 0, NULL);
    xTaskCreate(highPrioTask, "high", 512, NULL, 1, NULL);

    vTaskStartScheduler();
}

Before the change - No output.
After the change -

Low prio Task
Low prio Task
Low prio Task
Low prio Task
.
.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

#1091

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

When a task deletes itself, it calls portPRE_TASK_DELETE_HOOK which
translates to vPortCloseRunningThread on the Windows port.
vPortCloseRunningThread never returns and as a result,
taskYIELD_WITHIN_API in vTaskDelete does not get called. As a result,
the next task is not scheduled when configUSE_PREEMPTION is set to 0.

This change records that a yield is pending so that the next tick
interrupt switches out the task that was deleted.

Signed-off-by: Gaurav Aggarwal <[email protected]>
@aggarg aggarg requested a review from a team as a code owner August 29, 2024 12:57
Copy link

sonarcloud bot commented Aug 29, 2024

@aggarg aggarg changed the title Pend a yield in portPRE_TASK_DELETE_HOOK Pend a yield in vPortCloseRunningThread Aug 29, 2024
@n9wxu n9wxu merged commit 6dab25a into FreeRTOS:main Aug 29, 2024
16 checks passed
@aggarg aggarg deleted the issue_1091 branch August 29, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants