audio: audio debug thread exit is too slow [1/1]

PD#SWPL-198068

Problem:
using sleep func results;

Solution:
using pthread_cond_timedwait func;

Verify:
zapper

Change-Id: Ibad7610ecc100f4792b7064cceee2528392db6dd
Signed-off-by: haiyang.ren <haiyang.ren@amlogic.com>
diff --git a/audio_hal/audio_hw.c b/audio_hal/audio_hw.c
index 13e83b7..dca1f5d 100644
--- a/audio_hal/audio_hw.c
+++ b/audio_hal/audio_hw.c
@@ -8334,6 +8334,9 @@
     release_alsa_device();
 #ifdef NO_SERVER
     adev->audio_debug_thread_exit = true;
+    pthread_mutex_lock(&adev->audio_debug_mutex);
+    pthread_cond_signal(&adev->audio_debug_cond);
+    pthread_mutex_unlock(&adev->audio_debug_mutex);
     if (adev->audio_debug_thread) {
         pthread_join(adev->audio_debug_thread, NULL);
     }
@@ -8601,6 +8604,9 @@
 {
     struct aml_audio_device *adev = (struct aml_audio_device *)data;
     int fd = 0;
+    uint64_t ref_time = 0;
+    uint64_t tgt_time = 0;
+    struct timespec ts;
     char read_msg[256] = {0};
 
     AM_LOGI("entry. adev: %p", adev);
@@ -8630,7 +8636,12 @@
                 }
                 adev->hw_device.set_parameters(&adev->hw_device, read_msg);
             } else {
-                aml_audio_sleep(2000000);
+                ref_time = aml_audio_get_systime_ns();
+                tgt_time = ref_time + 200*1000*1000LL;
+                ts = aml_audio_ns_to_time(tgt_time);
+                pthread_mutex_lock(&adev->audio_debug_mutex);
+                pthread_cond_timedwait(&adev->audio_debug_cond, &adev->audio_debug_mutex, &ts);
+                pthread_mutex_unlock(&adev->audio_debug_mutex);
             }
         }
         close(fd);
diff --git a/audio_hal/audio_hw.h b/audio_hal/audio_hw.h
index 8d1b372..34a9881 100644
--- a/audio_hal/audio_hw.h
+++ b/audio_hal/audio_hw.h
@@ -637,6 +637,8 @@
 
 #ifdef NO_SERVER
     pthread_t audio_debug_thread; //add for NO_SERVER
+    pthread_mutex_t audio_debug_mutex;
+    pthread_cond_t  audio_debug_cond;
     bool audio_debug_thread_exit;
 #endif
     bool audio_low_latency;  //add for NTS LLP