tzip: fix pthread_cond_wait/pthread_cond_signal wrong usage bug between tzip_thread... 98/170398/2
authorINSUN PYO <insun.pyo@samsung.com>
Tue, 20 Feb 2018 01:02:04 +0000 (10:02 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 20 Feb 2018 02:54:25 +0000 (02:54 +0000)
=============== tzip_mount_thread is blocked here ================================
Thread 5 (Thread 0xb33ed1f0 (LWP 6078)):
0  0xb69726f4 in __pthread_cond_wait (cond=cond@entry=0x7f67e0d0 <thread_cond>, mutex=mutex@entry=0x7f67e0b8 <thread_cond_mutex>) at pthread_cond_wait.c:186
1  0x7f62f2ba in tzip_mount_thread (arg=<optimized out>) at /usr/src/debug/deviced-5.0.0/src/tzip/tzip.c:508
2  0xb696bf04 in start_thread (arg=0xb33ed1f0) at pthread_create.c:335
3  0xb68fa338 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:86 from /lib/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
==================================================================================

Signed-off-by: INSUN PYO <insun.pyo@samsung.com>
Change-Id: Ia4fb0c6de2c22084abef4ba84ee8bd1c77b10933

src/tzip/tzip.c

index ec2c226..03af53d 100644 (file)
@@ -56,6 +56,8 @@ static struct fuse *fuse_handle;
 static struct fuse_chan *channel;
 static GAsyncQueue *async_queue;
 static gint stop_or_error = TZIP_RUNNING_STATE;
+
+static int thread_ready;
 static pthread_cond_t thread_cond = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t thread_cond_mutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -446,6 +448,7 @@ static void *tzip_thread(void *arg)
 
        /* notify to tzip_mount_thread */
        pthread_mutex_lock(&thread_cond_mutex);
+       thread_ready = 1;
        pthread_cond_signal(&thread_cond);
        pthread_mutex_unlock(&thread_cond_mutex);
 
@@ -471,6 +474,7 @@ out:
 
        /* notify to tzip_mount_thread */
        pthread_mutex_lock(&thread_cond_mutex);
+       thread_ready = 1;
        pthread_cond_signal(&thread_cond);
        pthread_mutex_unlock(&thread_cond_mutex);
 
@@ -505,7 +509,9 @@ static void *tzip_mount_thread(void *arg)
 
        /* wait for tzip_thread to be ready*/
        pthread_mutex_lock(&thread_cond_mutex);
-       pthread_cond_wait(&thread_cond, &thread_cond_mutex);
+       if (!thread_ready)
+               pthread_cond_wait(&thread_cond, &thread_cond_mutex);
+       assert(thread_ready); /* Never happend */
        pthread_mutex_unlock(&thread_cond_mutex);
 
        while (1) {