wrapper: deadlock in recording [1/1]

PD#SWPL-125202

Problem:
deadlock

Solution:
fix the deadlock

Verify:
PB

Change-Id: Id1b12698a3a10a07f46d71d7c17cc45d41e31dc9
Signed-off-by: Zhiqiang Han <zhiqiang.han@amlogic.com>
diff --git a/src/dvr_wrapper.c b/src/dvr_wrapper.c
index 8d49b38..b0389df 100644
--- a/src/dvr_wrapper.c
+++ b/src/dvr_wrapper.c
@@ -606,15 +606,14 @@
 
   prctl(PR_SET_NAME,"DvrWrapper");
 
-  pthread_mutex_lock(&thread_ctx->lock);
-
   while (thread_ctx->running) {
-    {
-      int ret;
+    int ret;
 
-      evt = (thread_ctx->type == W_REC)? ctx_getRecordEvent() : ctx_getPlaybackEvent();
-      if (!evt)
-        ret = wrapper_threadWait(thread_ctx);
+    evt = (thread_ctx->type == W_REC)? ctx_getRecordEvent() : ctx_getPlaybackEvent();
+    if (!evt) {
+      pthread_mutex_lock(&thread_ctx->lock);
+      ret = wrapper_threadWait(thread_ctx);
+      pthread_mutex_unlock(&thread_ctx->lock);
     }
 
     while (evt) {
@@ -636,11 +635,10 @@
         if (ctx_valid(ctx)) {
           /*double check after lock*/
           if (evt->sn == ctx->sn) {
-            pthread_mutex_unlock(&thread_ctx->lock);
             process_handleEvents(evt, ctx);
-            pthread_mutex_lock(&thread_ctx->lock);
           }
         }
+
         wrapper_mutex_unlock(&ctx->wrapper_lock);
       }
 
@@ -651,7 +649,6 @@
     }
   }
 
-  pthread_mutex_unlock(&thread_ctx->lock);
   DVR_WRAPPER_DEBUG("end name(%s) running(%d) type(%d) end...\n", thread_ctx->name, thread_ctx->running, thread_ctx->type);
   return NULL;
 }
@@ -669,7 +666,7 @@
 {
   pthread_mutex_lock(&WRAPPER_THREAD_PLAYBACK->lock);
   if (ctx_addEvent(&playback_evt_list, &playback_evt_list_lock, evt) == 0)
-      wrapper_threadSignalForType(evt->type);
+    wrapper_threadSignalForType(evt->type);
   pthread_mutex_unlock(&WRAPPER_THREAD_PLAYBACK->lock);
   return 0;
 }