wrapper: incorrect thread starting [1/1]

PD#OTT-50237
PD#SWPL-142935
PD#SWPL-142004

Problem:
thread will exit due to incorrect running state

Solution:
set the running before thread creation

Verify:
Project

Change-Id: I3bc2277f2660b604f0a1354dbc5bc5fd2b7309a0
Signed-off-by: Zhiqiang Han <zhiqiang.han@amlogic.com>
diff --git a/src/dvr_wrapper.c b/src/dvr_wrapper.c
index bf3eee6..818b8d5 100644
--- a/src/dvr_wrapper.c
+++ b/src/dvr_wrapper.c
@@ -490,7 +490,8 @@
 static int wrapper_requestThread(DVR_WrapperThreadCtx_t *ctx, void *(thread_fn)(void *))
 {
   pthread_mutex_lock(&ctx->lock);
-  if (ctx->running == 0) {
+  ctx->running++;
+  if (ctx->running == 1) {
     pthread_condattr_t attr = {0};
     pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
     pthread_cond_init(&ctx->cond, &attr);
@@ -499,7 +500,6 @@
     pthread_create(&ctx->thread, NULL, thread_fn, ctx);
     DVR_WRAPPER_INFO("wrapper thread(%s) started\n", ctx->name);
   }
-  ctx->running++;
   pthread_mutex_unlock(&ctx->lock);
   return 0;
 }
@@ -649,7 +649,7 @@
     }
   }
 
-  DVR_WRAPPER_DEBUG("end name(%s) running(%d) type(%d) end...\n", thread_ctx->name, thread_ctx->running, thread_ctx->type);
+  DVR_WRAPPER_DEBUG("wrapper thread(%s) exit, running(%d) type(%d)\n", thread_ctx->name, thread_ctx->running, thread_ctx->type);
   return NULL;
 }