From: Kim Gunsoo Date: Thu, 8 Sep 2016 04:58:40 +0000 (+0900) Subject: Fixed the problem that push/pull progress information is broken. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d897e840047c952ffac11d48cf65fed4a535f447;p=sdk%2Ftools%2Fsdb.git Fixed the problem that push/pull progress information is broken. - When outputting the progress information, there was a problem for reentrant of multi-threaded. It was resolved using the critical section. Change-Id: Ie6d62ca2dfd4af44b8d7d4746fdfda13d6146433 Signed-off-by: Kim Gunsoo --- diff --git a/src/file_sync_client.c b/src/file_sync_client.c index 741f96a..d9c5cb9 100644 --- a/src/file_sync_client.c +++ b/src/file_sync_client.c @@ -88,7 +88,9 @@ static void deinit_sync_progress_timer(void) { HANDLE hTimer = NULL; static VOID CALLBACK update_progress(PVOID lpParam, BOOLEAN TimerOrWaitFired) { - print_progress(SDB_PROGRESS_STAGE_TRANSFERRING); + if (hTimer != NULL) { + print_progress(SDB_PROGRESS_STAGE_TRANSFERRING); + } } static void init_sync_progress_timer(void) { @@ -104,6 +106,7 @@ static void deinit_sync_progress_timer(void) { D("failed to DeleteTimerQueueTimer()\n"); return; } + hTimer = NULL; } #endif @@ -169,7 +172,15 @@ void print_progress(int stage) { unsigned percent = 0; unsigned speed = 0; unsigned progress_bytes = 0; + static int is_finished = 0; + + /* initialize timer */ + if (stage == SDB_PROGRESS_STAGE_STARTED) { + init_sync_progress_timer(); + is_finished = 0; + } + /* calc progress information */ sdb_mutex_lock(&prg_info_lock, "read written_bytes. print_progress()"); progress_bytes = g_prg_info.written_bytes; sdb_mutex_unlock(&prg_info_lock, "read written_bytes. print_progress()"); @@ -177,16 +188,25 @@ void print_progress(int stage) { speed = calc_progress_speed(stage, progress_bytes); percent = calc_progress_percent(progress_bytes); - //TODO: consider current window size. - fprintf(stdout,"\r%s %30s\t%3d%%\t%7d%s\t%5dKB/s", g_prg_info.tag, g_prg_info.file_name, + /* print progress information */ + sdb_mutex_lock(&prg_print_lock, "print progress info. print_progress()"); + if (!is_finished) { + //TODO: consider current window size. + fprintf(stdout,"\r%s %30s\t%3d%%\t%7d%s\t%5dKB/s", g_prg_info.tag, g_prg_info.file_name, percent, (progress_bytes/g_prg_info.flag_size), g_prg_info.byte_flag, speed); - fflush(stdout); + fflush(stdout); + } + sdb_mutex_unlock(&prg_print_lock, "print progress info. print_progress()"); - if (stage == SDB_PROGRESS_STAGE_STARTED) { - init_sync_progress_timer(); - } else if (stage == SDB_PROGRESS_STAGE_FINISHED) { + /* deinitialize timer and print '\n' */ + if (stage == SDB_PROGRESS_STAGE_FINISHED) { deinit_sync_progress_timer(); + + sdb_mutex_lock(&prg_print_lock, "print progress info. print_progress()"); fprintf(stdout,"\n"); + fflush(stdout); + is_finished = 1; + sdb_mutex_unlock(&prg_print_lock, "print progress info. print_progress()"); } } diff --git a/src/utils.h b/src/utils.h index 29c61a0..1c72e55 100755 --- a/src/utils.h +++ b/src/utils.h @@ -106,6 +106,7 @@ SDB_MUTEX(wakeup_select_lock) SDB_MUTEX(usb_lock) SDB_MUTEX(D_lock) SDB_MUTEX(prg_info_lock) +SDB_MUTEX(prg_print_lock) int launch_server(); void start_logging(void); diff --git a/src/utils_windows.c b/src/utils_windows.c index 7d180e2..5bb7d06 100755 --- a/src/utils_windows.c +++ b/src/utils_windows.c @@ -972,6 +972,7 @@ static void _sdb_sysdeps_init(void) { SDB_MUTEX(_win32_lock); SDB_MUTEX(sdb_handle_map_lock); SDB_MUTEX(prg_info_lock); + SDB_MUTEX(prg_print_lock); } typedef void (*win_thread_func_t)(void* arg);