Skip to content

Add ownership check when giving a mutex#1454

Open
cookpate wants to merge 1 commit into
FreeRTOS:mainfrom
cookpate:fix-mutex
Open

Add ownership check when giving a mutex#1454
cookpate wants to merge 1 commit into
FreeRTOS:mainfrom
cookpate:fix-mutex

Conversation

@cookpate

Copy link
Copy Markdown
Member

Add ownership check when giving a mutex

Description

In xQueueGenericSend (from xSemaphoreGive), when the queue's type is a mutex and that mutex is held, check its holder against the current task. Only allow the holding task to give the mutex.

Test Steps

Scenario:
Task A and Task B with equal priorities, preemption enabled.

  1. Create a mutex.
  2. Start the scheduler, switch to Task A.
  3. Take the mutex (xSemaphoreTake) as Task A.
  4. Preempt Task A, switch to Task B.
  5. Give the mutex (xSemaphoreGive) as Task B.

Without this change: Task B's xSemaphoreGive succeeds, the mutex is marked available, no longer taken by Task A.
With this change: Task B's xSeamphoreGive fails, the mutex remains taken, and it is still taken by Task A.

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.

Note: CMock tests will be added in a commit to FreeRTOS/FreeRTOS.

Related Issue

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

Disallow a held mutex from being given by another task,
one that did not first take the mutex.
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant