clear deadlock issue 2.1b_release accepted/tizen_2.1/20130425.032930 submit/tizen_2.1/20130424.233024
authorjy910.yun <jy910.yun@samsung.com>
Tue, 23 Apr 2013 15:18:37 +0000 (00:18 +0900)
committerjy910.yun <jy910.yun@samsung.com>
Tue, 23 Apr 2013 16:55:59 +0000 (01:55 +0900)
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
tizen/DEVICE/src/sysnoti.c

index 4063166..eea51e8 100644 (file)
@@ -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);
                        }
                }
index 52e51b4..56aaad8 100644 (file)
@@ -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;
 }