From: Seungbae Shin Date: Mon, 6 Apr 2020 07:44:13 +0000 (+0900) Subject: fixup! Fix hanging on pthread_cond_destroy during cancellation of thread by broadcast... X-Git-Tag: accepted/tizen/6.0/unified/20201030.122545^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_6.0_unified_hotfix;p=platform%2Fcore%2Fapi%2Fsound-pool.git fixup! Fix hanging on pthread_cond_destroy during cancellation of thread by broadcasting before destroy. + fix minor build warnings due to strncpy [Version] 0.0.21 [Issue Type] Bug Change-Id: I5db46a4effabb6c9d4dd5d1538ab9141886549e7 --- diff --git a/packaging/capi-media-sound-pool.spec b/packaging/capi-media-sound-pool.spec index 82fd888..445faff 100644 --- a/packaging/capi-media-sound-pool.spec +++ b/packaging/capi-media-sound-pool.spec @@ -1,5 +1,5 @@ Name: capi-media-sound-pool -Version: 0.0.20 +Version: 0.0.21 Summary: Tizen Sound Pool module Release: 0 Group: Multimedia/Framework diff --git a/src/stream_cb_manager.c b/src/stream_cb_manager.c index 886e70d..3bf22d5 100644 --- a/src/stream_cb_manager.c +++ b/src/stream_cb_manager.c @@ -23,7 +23,6 @@ #include "internal/stream_cb_manager.h" static gpointer __sound_pool_callback_isolator(gpointer user_data); -static void __thread_cancel_cleanup(); static void __queue_destroy_item(gpointer data); static void __queue_destroy_item(gpointer data) @@ -35,22 +34,6 @@ static void __queue_destroy_item(gpointer data) SP_DEBUG_FLEAVE(); } -static void __thread_cancel_cleanup(void *user_data) -{ - SP_DEBUG_FENTER(); - - stream_cb_manager_t *cbmgr = (stream_cb_manager_t *)user_data; - g_async_queue_unref(cbmgr->isolator_callback_queue); - - pthread_cond_broadcast(&cbmgr->isolator_data_cond); - pthread_cond_destroy(&cbmgr->isolator_data_cond); - pthread_mutex_destroy(&cbmgr->isolator_data_mutex); - - SP_SAFE_GFREE(cbmgr); - - SP_DEBUG_FLEAVE(); -} - sound_pool_error_e _stream_cb_manager_process_pending_events(stream_cb_manager_t *cbmgr) { SP_DEBUG_FENTER(); @@ -91,24 +74,19 @@ sound_pool_error_e _stream_cb_manager_signal_completed_events(stream_cb_manager_ static gpointer __sound_pool_callback_isolator(gpointer user_data) { SP_DEBUG_FENTER(); - int err = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - if (err != 0) - SP_INFO("Can't setup cancel type for isolation thread with error [%d].", err); - err = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - if (err != 0) - SP_INFO("Can't setup cancel state for isolation thread with error [%d].", err); SP_RETVM_IF(!user_data, NULL, "User data is NULL. Terminate callback thread"); stream_cb_manager_t *cbmgr = (stream_cb_manager_t *)user_data; - pthread_cleanup_push(__thread_cancel_cleanup, user_data); pthread_mutex_lock(&cbmgr->isolator_data_mutex); - gboolean runing = cbmgr->isolator_loop_run; - pthread_mutex_unlock(&cbmgr->isolator_data_mutex); - while (runing) { - pthread_mutex_lock(&cbmgr->isolator_data_mutex); - while (!cbmgr->isolator_state_changed) + while (cbmgr->isolator_loop_run) { + while (!cbmgr->isolator_state_changed) { pthread_cond_wait(&cbmgr->isolator_data_cond, &cbmgr->isolator_data_mutex); + if (!cbmgr->isolator_loop_run) { + SP_INFO("terminating loop"); + goto exit; + } + } pthread_mutex_unlock(&cbmgr->isolator_data_mutex); /* Iterate streams have been pushed to the queue and call for each @@ -126,15 +104,14 @@ static gpointer __sound_pool_callback_isolator(gpointer user_data) } SP_SAFE_GFREE(event_data); } + /* Signal indicating isolator callback thread completed the events */ _stream_cb_manager_signal_completed_events(cbmgr); - pthread_mutex_lock(&cbmgr->isolator_data_mutex); - runing = cbmgr->isolator_loop_run; - pthread_mutex_unlock(&cbmgr->isolator_data_mutex); } - pthread_cleanup_pop(0); +exit: + pthread_mutex_unlock(&cbmgr->isolator_data_mutex); SP_DEBUG_FLEAVE(); return NULL; } @@ -226,38 +203,25 @@ sound_pool_error_e _stream_cb_manager_destroy(stream_cb_manager_t *cbmgr) /* Wait for completing the isolator callback thread events */ _stream_cb_manager_process_pending_events(cbmgr); - err = pthread_kill(thread, 0); - if (0 == err) { - err = pthread_cancel(thread); - if (0 != err) { - SP_ERROR("Error while cancelling of isolation thread[%d].", err); - ret = SOUND_POOL_ERROR_INVALID_OPERATION; - GOTO_FAIL("", creturn); - } - } else { - SP_ERROR("Invalid isolation thread[%d].", err); - ret = SOUND_POOL_ERROR_INVALID_OPERATION; - GOTO_FAIL("", creturn); - } + + /* stop thread and wait join */ + pthread_mutex_lock(&cbmgr->isolator_data_mutex); + cbmgr->isolator_loop_run = FALSE; + pthread_cond_signal(&cbmgr->isolator_data_cond); + pthread_mutex_unlock(&cbmgr->isolator_data_mutex); err = pthread_join(thread, &return_val); - if (0 != err) + if (0 != err) { SP_ERROR("Error while joining of isolation thread[%d].", err); - if (return_val == PTHREAD_CANCELED) - SP_INFO("Isolation thread canceled."); - else { - ret = SOUND_POOL_ERROR_NONE; - GOTO_FAIL("Routine joining of isolation thread.", creturn); + ret = SOUND_POOL_ERROR_INVALID_OPERATION; } - SP_DEBUG_FLEAVE(); - return ret; - -creturn: g_async_queue_unref(cbmgr->isolator_callback_queue); - pthread_mutex_destroy(&cbmgr->isolator_data_mutex); pthread_cond_destroy(&cbmgr->isolator_data_cond); + pthread_mutex_destroy(&cbmgr->isolator_data_mutex); + SP_SAFE_GFREE(cbmgr); + SP_DEBUG_FLEAVE(); return ret; } diff --git a/test/proxy/src/proxy.c b/test/proxy/src/proxy.c index d681ccf..8e12559 100644 --- a/test/proxy/src/proxy.c +++ b/test/proxy/src/proxy.c @@ -679,8 +679,11 @@ static int __proxy_sound_pool_load_source_from_file(const char *pars) _logger_log_warn("Pool with specified identifier is NULL"); /* If tag wasn't specified by the user, we will use file path as a tag */ - if (tag[0] == '\0') + if (tag[0] == '\0') { strncpy(tag, fname, MAX_PATH_LEN - 1); + tag[MAX_PATH_LEN - 1] = '\0'; + } + _logger_log_info(CMD_LOAD_SOURCE " command was called"); _logger_log_info("Loading source to the pool with %zu identifier from %s file. " diff --git a/test/sound_pool_test.c b/test/sound_pool_test.c index 92a42b7..28ecf47 100644 --- a/test/sound_pool_test.c +++ b/test/sound_pool_test.c @@ -22,6 +22,7 @@ #include #include #include +#include #define KEY_CODE_ESCAPE 27 #define KEY_CODE_BACKSPACE 127 @@ -151,6 +152,8 @@ size_t auto_fill(const char *cmd_start, char fill_hint[MAX_COMMAND_LINE_LEN]) else strncpy(fill_hint, auto_fill, MAX_COMMAND_LINE_LEN - 1); + fill_hint[MAX_COMMAND_LINE_LEN - 1] = '\0'; + return fill_found; }