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

Fix #1027, defer cancellation when BSP locked #1028

Merged
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
14 changes: 14 additions & 0 deletions src/bsp/generic-linux/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ void OS_BSP_Lock_Impl(void)
{
BSP_DEBUG("pthread_mutex_lock: %s\n", strerror(status));
}
else
{
/*
* Temporarily Disable/Defer thread cancellation.
* Note that OS_BSP_ConsoleOutput_Impl() calls write() which is a cancellation point.
* So if this calling task is canceled, it risks leaving the BSP locked.
*/
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &OS_BSP_GenericLinuxGlobal.AccessCancelState);
}
}

/*----------------------------------------------------------------
Expand All @@ -125,6 +134,11 @@ void OS_BSP_Unlock_Impl(void)
{
BSP_DEBUG("pthread_mutex_unlock: %s\n", strerror(status));
}
else
{
/* Restore previous cancelability state */
pthread_setcancelstate(OS_BSP_GenericLinuxGlobal.AccessCancelState, NULL);
}
}

/* ---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/bsp/generic-linux/src/generic_linux_bsp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef struct
{
bool EnableTermControl; /**< Will be set "true" when invoked from a TTY device, false otherwise */
pthread_mutex_t AccessMutex;
int AccessCancelState;
} OS_BSP_GenericLinuxGlobalData_t;

/*
Expand Down
10 changes: 1 addition & 9 deletions src/os/shared/src/osapi-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,10 @@ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority)
*-----------------------------------------------------------------*/
osal_id_t OS_TaskGetId(void)
{
OS_object_token_t token;
osal_id_t task_id;
osal_id_t task_id;

task_id = OS_TaskGetId_Impl();

/* Confirm the task master table entry matches the expected.
* If not it means we have some stale/leftover value */
if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, task_id, &token) != OS_SUCCESS)
{
task_id = OS_OBJECT_ID_UNDEFINED;
}

return (task_id);
} /* end OS_TaskGetId */

Expand Down
4 changes: 0 additions & 4 deletions src/unit-test-coverage/shared/src/coveragetest-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ void Test_OS_TaskGetId(void)
UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), idbuf.val);
objid = OS_TaskGetId();
OSAPI_TEST_OBJID(objid, ==, idbuf.id);

UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR);
objid = OS_TaskGetId();
OSAPI_TEST_OBJID(objid, ==, OS_OBJECT_ID_UNDEFINED);
}

void Test_OS_TaskGetIdByName(void)
Expand Down