audio: qahw_api: Remove pthread_cancel api
Remove pthread_cancel api, as it is not defined
android standard library. Adding pthread_kill api
to handle input command thread.
Change-Id: Ia9d7f3939f1f7a5851f6aa22fe0894acb814a902
diff --git a/qahw_api/test/qahw_effect_test.c b/qahw_api/test/qahw_effect_test.c
index bc249f3..9ea362f 100644
--- a/qahw_api/test/qahw_effect_test.c
+++ b/qahw_api/test/qahw_effect_test.c
@@ -34,6 +34,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <signal.h>
#include "qahw_api.h"
#include "qahw_defs.h"
@@ -111,6 +112,12 @@
#define NUM_EQ_BANDS 5
const uint16_t qahw_equalizer_band_freqs[NUM_EQ_BANDS] = {60, 230, 910, 3600, 14000}; /* frequencies in HZ */
+/* Handler to handle input command_thread_func signal */
+void stop_effect_command_thread_handler(int signal __unused)
+{
+ pthread_exit(NULL);
+}
+
/* THREAD BODY OF BASSBOOST */
void *bassboost_thread_func(void* data) {
thread_data_t *thr_ctxt = (thread_data_t *)data;
@@ -489,6 +496,12 @@
qahw_effect_param_t *param = (qahw_effect_param_t *)buf32;
qahw_effect_param_t *param_2 = (qahw_effect_param_t *)buf32_2;
+ /* Register the SIGUSR1 to close this thread properly
+ as it is waiting for input in while loop */
+ if (signal(SIGUSR1, stop_effect_command_thread_handler) == SIG_ERR) {
+ fprintf(stderr, "Failed to register SIGUSR1:%d\n",errno);
+ }
+
while(!thr_ctxt->exit) {
if (fgets(cmd_str, sizeof(cmd_str), stdin) == NULL) {
fprintf(stderr, "read error\n");
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index fceff8b..436572f 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -854,10 +854,12 @@
// destory effect command thread
params->cmd_data.exit = true;
usleep(100000); // give a chance for thread to exit gracefully
- rc = pthread_cancel(params->cmd_data.cmd_thread);
+
+ //Send signal for input command_thread_func to stop
+ rc = pthread_kill(params->cmd_data.cmd_thread, SIGUSR1);
if (rc != 0) {
- fprintf(log_file, "Fail to cancel thread!\n");
- fprintf(stderr, "Fail to cancel thread!\n");
+ fprintf(log_file, "Fail to kill effect command thread!\n");
+ fprintf(stderr, "Fail to kill effect command thread!\n");
}
rc = pthread_join(params->cmd_data.cmd_thread, NULL);
if (rc < 0) {