@@ -243,7 +243,18 @@ void* T2ER_EventDispatchThread(void *arg)
243243 return NULL ;
244244 }
245245 T2Debug ("Checking for events in event queue , event count = %d\n" , t2_queue_count (eQueue ));
246- if (t2_queue_count (eQueue ) > 0 )
246+ while (t2_queue_count (eQueue ) == 0 && !stopDispatchThread )
247+ {
248+ T2Debug ("Event Queue size is 0, Waiting events from T2ER_Push\n" );
249+ int ret = pthread_cond_wait (& erCond , & erMutex );
250+ if (ret != 0 ) // pthread cond wait failed return after unlock
251+ {
252+ T2Error ("%s pthread_cond_wait failed with error code: %d\n" , __FUNCTION__ , ret );
253+ }
254+ T2Debug ("Received signal from T2ER_Push\n" );
255+ }
256+
257+ if (t2_queue_count (eQueue ) > 0 )
247258 {
248259 T2Event * event = (T2Event * )t2_queue_pop (eQueue );
249260 if (event == NULL )
@@ -280,18 +291,11 @@ void* T2ER_EventDispatchThread(void *arg)
280291 }
281292 else
282293 {
283- T2Debug ("Event Queue size is 0, Waiting events from T2ER_Push\n" );
284- int ret = pthread_cond_wait (& erCond , & erMutex );
285- if (ret != 0 ) // pthread cond wait failed return after unlock
286- {
287- T2Error ("%s pthread_cond_wait failed with error code: %d\n" , __FUNCTION__ , ret );
288- }
289294 if (pthread_mutex_unlock (& erMutex ) != 0 )
290295 {
291296 T2Error ("%s pthread_mutex_unlock for erMutex failed\n" , __FUNCTION__ );
292297 return NULL ;
293298 }
294- T2Debug ("Received signal from T2ER_Push\n" );
295299 }
296300 }
297301 T2Debug ("%s --out\n" , __FUNCTION__ );
@@ -345,7 +349,10 @@ T2ERROR T2ER_Init()
345349 registerForTelemetryEvents (T2ER_PushDataWithDelim );
346350 }
347351
348- system ("touch /tmp/.t2ReadyToReceiveEvents" );
352+ if (system ("touch /tmp/.t2ReadyToReceiveEvents" ) != 0 )
353+ {
354+ T2Error ("Failed to create /tmp/.t2ReadyToReceiveEvents flag file \n" );
355+ }
349356 setT2EventReceiveState (T2_STATE_COMPONENT_READY );
350357 T2Info ("T2 is now Ready to Recieve Events\n" );
351358
@@ -500,13 +507,13 @@ void T2ER_Uninit()
500507 }
501508 EREnabled = false;
502509
510+ if (pthread_mutex_lock (& sTDMutex ) != 0 ) // mutex lock failed so return from T2ER_Uninit
511+ {
512+ T2Error ("%s pthread_mutex_lock for sTDMutex failed\n" , __FUNCTION__ );
513+ return ;
514+ }
503515 if (!stopDispatchThread )
504516 {
505- if (pthread_mutex_lock (& sTDMutex ) != 0 ) // mutex lock failed so return from T2ER_Uninit
506- {
507- T2Error ("%s pthread_mutex_lock for sTDMutex failed\n" , __FUNCTION__ );
508- return ;
509- }
510517 stopDispatchThread = true;
511518 if (pthread_mutex_unlock (& sTDMutex ) != 0 ) //mutex unlock failed so return from T2ER_Uninit
512519 {
@@ -551,6 +558,14 @@ void T2ER_Uninit()
551558 return ;
552559 }
553560 }
561+ else
562+ {
563+ if (pthread_mutex_unlock (& sTDMutex ) != 0 )
564+ {
565+ T2Error ("%s pthread_mutex_unlock for sTDMutex failed\n" , __FUNCTION__ );
566+ return ;
567+ }
568+ }
554569 T2Debug ("T2ER Event Dispatch Thread successfully terminated\n" );
555570 t2_queue_destroy (eQueue , freeT2Event );
556571 eQueue = NULL ;
0 commit comments