[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240607042615.2069840-27-chengzhihao1@huawei.com>
Date: Fri, 7 Jun 2024 12:24:51 +0800
From: Zhihao Cheng <chengzhihao1@...wei.com>
To: <richard@....at>, <david.oberhollenzer@...ma-star.at>,
<miquel.raynal@...tlin.com>, <yi.zhang@...wei.com>, <xiangyang3@...wei.com>,
<huangxiaojia2@...wei.com>
CC: <linux-mtd@...ts.infradead.org>, <linux-kernel@...r.kernel.org>
Subject: [RFC PATCH mtd-utils 026/110] ubifs-utils: Add mutexlock implementations
Add mutexlock implementations, because there are some mutexlocks
(eg. c->tnc_mutex, c->log_mutex) used in UBIFS linux kernel libs.
The mutexlock is implementated based on pthread mutex.
This is a preparation for replacing implementation of UBIFS utils with
linux kernel libs.
Signed-off-by: Zhihao Cheng <chengzhihao1@...wei.com>
---
ubifs-utils/Makemodule.am | 1 +
ubifs-utils/common/mutex.h | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 ubifs-utils/common/mutex.h
diff --git a/ubifs-utils/Makemodule.am b/ubifs-utils/Makemodule.am
index 7849114e..9f33f0db 100644
--- a/ubifs-utils/Makemodule.am
+++ b/ubifs-utils/Makemodule.am
@@ -6,6 +6,7 @@ common_SOURCES = \
ubifs-utils/common/bitops.h \
ubifs-utils/common/bitops.c \
ubifs-utils/common/spinlock.h \
+ ubifs-utils/common/mutex.h \
ubifs-utils/common/kmem.h \
ubifs-utils/common/kmem.c \
ubifs-utils/common/defs.h \
diff --git a/ubifs-utils/common/mutex.h b/ubifs-utils/common/mutex.h
new file mode 100644
index 00000000..4bf018b0
--- /dev/null
+++ b/ubifs-utils/common/mutex.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_MUTEX_H_
+#define __LINUX_MUTEX_H_
+
+#include <pthread.h>
+
+struct mutex {
+ pthread_mutex_t lock;
+};
+
+#define mutex_init(x) pthread_mutex_init(&(x)->lock, NULL)
+
+#define mutex_lock(x) pthread_mutex_lock(&(x)->lock)
+#define mutex_lock_nested(x, c) pthread_mutex_lock(&(x)->lock)
+#define mutex_unlock(x) pthread_mutex_unlock(&(x)->lock)
+#define mutex_is_locked(x) (pthread_mutex_trylock(&(x)->lock) == EBUSY)
+
+#endif
--
2.13.6
Powered by blists - more mailing lists