block: Add a mutex for pipe 87/153687/1
authorpr.jung <pr.jung@samsung.com>
Fri, 29 Sep 2017 06:24:38 +0000 (15:24 +0900)
committerpr.jung <pr.jung@samsung.com>
Fri, 29 Sep 2017 06:24:38 +0000 (15:24 +0900)
- Multithread should not write pipe at the same time

Change-Id: Ic95645160e339716bdba8874d42c5aeb516aa520
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/block/block.c

index d61bc37..e3717d6 100644 (file)
@@ -179,6 +179,7 @@ static int pfds[2];
 static fd_handler_h phandler;
 static bool block_control = false;
 static bool block_boot = false;
+static pthread_mutex_t pipe_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 /* Assume there is only one physical internal storage */
 static int dev_internal = -1;
@@ -931,7 +932,10 @@ static int pipe_trigger(enum block_dev_operation op,
                        get_operation_char(pdata.op, name, sizeof(name)),
                        pdata.bdev, pdata.result);
 
+       // Multi thread should not write at the same time
+       pthread_mutex_lock(&pipe_mutex);
        n = write(pfds[1], &pdata, sizeof(struct pipe_data));
+       pthread_mutex_unlock(&pipe_mutex);
 
        return (n != sizeof(struct pipe_data)) ? -EPERM : 0;
 }