summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngela Stegmaier <angelabaker@ti.com>2017-05-12 12:28:50 -0500
committerVishal Mahaveer <vishalm@ti.com>2017-06-27 11:01:46 -0500
commit2ac7177a6886dc339c5eaab4eaabea770e954773 (patch)
treeb3079bab4b3ffe728677ab7df587810ad03b7ddf
parent33c69970189fe7386ebdc55365fa802c76874b5f (diff)
downloaddra7xx-d-nougat-mr2.1-release.tar.gz
OMX: Fix Task Cleanup to avoid Deadlockd-nougat-mr2.1-release
The pNewStateMutex is used from the OMXBase_CompThreadEntry thread, and is also obtained from the component de-init (running in another thread) before trying to delete and join the thread. In some error scenarios, this could result in a deadlock if the thread is in the process of handling an error when the component de-init grabs the mutex and waits for the thread to join. In this case, the threads will deadlock, because component de-init is holding a mutex that the other thread needs before it can exit, and the component de-init is waiting for the thread to exit. This patch moves the obtaining of the mutex to after deleting and joining the thread, so that there is no contention for the resource. Change-Id: I7df628162482d6cb60b86635caf7efce6d28489f Signed-off-by: Angela Stegmaier <angelabaker@ti.com> (cherry picked from commit 2b4b1b5ea6d46e39bc15b34b38b3046c96888da4)
-rw-r--r--omx/base/omx_base_comp/src/omx_base_internal.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/omx/base/omx_base_comp/src/omx_base_internal.c b/omx/base/omx_base_comp/src/omx_base_internal.c
index 85c953f..605a54d 100644
--- a/omx/base/omx_base_comp/src/omx_base_internal.c
+++ b/omx/base/omx_base_comp/src/omx_base_internal.c
@@ -147,8 +147,6 @@ OMX_ERRORTYPE OMXBase_PrivateDeInit(OMX_HANDLETYPE hComponent)
OMX_CHECK(pBaseComp != NULL, OMX_ErrorBadParameter);
pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData;
- OSAL_ObtainMutex(pBaseCompPvt->pNewStateMutex, OSAL_SUSPEND);
-
/* set an ENDEVENT before destroying thread */
pBaseCompPvt->fpInvokeProcessFunction(hComponent, ENDEVENT);
tStatus = OSAL_DeleteTask(pBaseCompPvt->pThreadId);
@@ -161,6 +159,13 @@ OMX_ERRORTYPE OMXBase_PrivateDeInit(OMX_HANDLETYPE hComponent)
tStatus = OSAL_DeleteTask(pBaseCompPvt->pThreadId);
}
+ /*
+ * Obtain the mutex after deleting the task. The task may be
+ * currently executing and may need access to the mutex to
+ * properly exit
+ */
+ OSAL_ObtainMutex(pBaseCompPvt->pNewStateMutex, OSAL_SUSPEND);
+
if( tStatus != OSAL_ErrNone ) {
eError = OMX_ErrorTimeout;
OSAL_ErrorTrace("Error while deleting task");