From c0d35f453660d15646532d58a08dd1c1a3b0ca10 Mon Sep 17 00:00:00 2001 From: "jy910.yun" Date: Wed, 24 Apr 2013 00:18:37 +0900 Subject: [PATCH] clear deadlock issue while A thread waits some response from system-server, this thread has canceld by main thread. It makes a deadlock issue Change-Id: I16fd700488dbb9891fed91c6bf2eb14c00111c70 --- tizen/DEVICE/src/file.c | 24 +++++++++++++++++------- tizen/DEVICE/src/sysnoti.c | 3 +++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tizen/DEVICE/src/file.c b/tizen/DEVICE/src/file.c index 4063166..eea51e8 100644 --- a/tizen/DEVICE/src/file.c +++ b/tizen/DEVICE/src/file.c @@ -55,7 +55,8 @@ typedef struct { static pthread_t tid; static BUFFER gbuffer; -static int lock; +static int stop; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static int _check_valid_haptic_format(HapticFile *file) { @@ -112,13 +113,16 @@ static int _cancel_thread(void) return 0; } - MODULE_LOG("lock state : %d", lock); - while (lock) { + MODULE_LOG("cancel thread!!!"); + + stop = 1; + + while (pthread_mutex_trylock(&mutex) == EBUSY) { usleep(100); - MODULE_LOG("already locked..."); + MODULE_LOG("Already locked.."); } - __haptic_predefine_action(gbuffer.handle, STOP, NULL); + pthread_mutex_unlock(&mutex); if ((ret = pthread_cancel(tid)) < 0) { MODULE_ERROR("pthread_cancel is failed : %s, ret(%d)", strerror(errno), ret); @@ -148,6 +152,8 @@ static void __clean_up(void *arg) MODULE_LOG("clean up handler!!! : %d", tid); + stop = 0; + for (i = 0; i < pbuffer->channels; ++i) { free(pbuffer->ppbuffer[i]); pbuffer->ppbuffer[i] = NULL; @@ -175,13 +181,17 @@ static void* __play_cb(void *arg) for (i = 0; i < pbuffer->iteration; i++) { for (j = 0; j < pbuffer->length; ++j) { for (k = 0; k < pbuffer->channels; ++k) { + pthread_mutex_lock(&mutex); + if (stop) { + pthread_mutex_unlock(&mutex); + pthread_exit((void*)0); + } ch = pbuffer->ppbuffer[k][j]; if (ch != prev) { - lock = 1; __haptic_predefine_action(pbuffer->handle, LEVEL, ch); - lock = 0; prev = ch; } + pthread_mutex_unlock(&mutex); usleep(BITPERMS * 1000); } } diff --git a/tizen/DEVICE/src/sysnoti.c b/tizen/DEVICE/src/sysnoti.c index 52e51b4..56aaad8 100644 --- a/tizen/DEVICE/src/sysnoti.c +++ b/tizen/DEVICE/src/sysnoti.c @@ -98,6 +98,7 @@ static int __sysnoti_send(struct sysnoti_type *msg) close(sockfd); return -1; } + MODULE_LOG("connect : %x", sockfd); __send_int(sockfd, msg->pid); __send_int(sockfd, msg->cmd); @@ -107,6 +108,7 @@ static int __sysnoti_send(struct sysnoti_type *msg) for (i = 0; i < msg->argc; i++) __send_str(sockfd, msg->argv[i]); + MODULE_LOG("read"); retry_cnt = 0; while ((r = read(sockfd, &ret, sizeof(int))) < 0) { @@ -126,6 +128,7 @@ static int __sysnoti_send(struct sysnoti_type *msg) ++retry_cnt; } + MODULE_LOG("close (ret : %d) : %x", ret, sockfd); close(sockfd); return ret; } -- 2.7.4