From 369564da6f73de1c731b5384ff7c1bdf957c39ac Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 29 Sep 2017 15:24:38 +0900 Subject: [PATCH] block: Add a mutex for pipe - Multithread should not write pipe at the same time Change-Id: Ic95645160e339716bdba8874d42c5aeb516aa520 Signed-off-by: pr.jung --- src/block/block.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/block/block.c b/src/block/block.c index d61bc37..e3717d6 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -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; } -- 2.7.4