Skip to content

Commit 7cfcab5

Browse files
authored
Merge pull request #1028 from jphickey/fix-1027-bsp-nocancel
Fix #1027, defer cancellation when BSP locked
2 parents 1d183e9 + 8a3e0ec commit 7cfcab5

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/bsp/generic-linux/src/bsp_start.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ void OS_BSP_Lock_Impl(void)
110110
{
111111
BSP_DEBUG("pthread_mutex_lock: %s\n", strerror(status));
112112
}
113+
else
114+
{
115+
/*
116+
* Temporarily Disable/Defer thread cancellation.
117+
* Note that OS_BSP_ConsoleOutput_Impl() calls write() which is a cancellation point.
118+
* So if this calling task is canceled, it risks leaving the BSP locked.
119+
*/
120+
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &OS_BSP_GenericLinuxGlobal.AccessCancelState);
121+
}
113122
}
114123

115124
/*----------------------------------------------------------------
@@ -125,6 +134,11 @@ void OS_BSP_Unlock_Impl(void)
125134
{
126135
BSP_DEBUG("pthread_mutex_unlock: %s\n", strerror(status));
127136
}
137+
else
138+
{
139+
/* Restore previous cancelability state */
140+
pthread_setcancelstate(OS_BSP_GenericLinuxGlobal.AccessCancelState, NULL);
141+
}
128142
}
129143

130144
/* ---------------------------------------------------------

src/bsp/generic-linux/src/generic_linux_bsp_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct
4242
{
4343
bool EnableTermControl; /**< Will be set "true" when invoked from a TTY device, false otherwise */
4444
pthread_mutex_t AccessMutex;
45+
int AccessCancelState;
4546
} OS_BSP_GenericLinuxGlobalData_t;
4647

4748
/*

src/os/shared/src/osapi-task.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,10 @@ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority)
339339
*-----------------------------------------------------------------*/
340340
osal_id_t OS_TaskGetId(void)
341341
{
342-
OS_object_token_t token;
343-
osal_id_t task_id;
342+
osal_id_t task_id;
344343

345344
task_id = OS_TaskGetId_Impl();
346345

347-
/* Confirm the task master table entry matches the expected.
348-
* If not it means we have some stale/leftover value */
349-
if (OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, task_id, &token) != OS_SUCCESS)
350-
{
351-
task_id = OS_OBJECT_ID_UNDEFINED;
352-
}
353-
354346
return (task_id);
355347
} /* end OS_TaskGetId */
356348

src/unit-test-coverage/shared/src/coveragetest-task.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ void Test_OS_TaskGetId(void)
197197
UT_SetDefaultReturnValue(UT_KEY(OS_TaskGetId_Impl), idbuf.val);
198198
objid = OS_TaskGetId();
199199
OSAPI_TEST_OBJID(objid, ==, idbuf.id);
200-
201-
UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR);
202-
objid = OS_TaskGetId();
203-
OSAPI_TEST_OBJID(objid, ==, OS_OBJECT_ID_UNDEFINED);
204200
}
205201

206202
void Test_OS_TaskGetIdByName(void)

0 commit comments

Comments
 (0)