diff mbox series

[RFC,mtd-utils,027/110] ubifs-utils: Add rwsem implementations

Message ID 20240607042615.2069840-28-chengzhihao1@huawei.com
State New
Delegated to: David Oberhollenzer
Headers show
Series Add fsck.ubifs support | expand

Commit Message

Zhihao Cheng June 7, 2024, 4:24 a.m. UTC
Add rwsem implementations, because there are some rwsems
(eg. c->commit_sem) used in UBIFS linux kernel libs.
The rwsem 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@huawei.com>
---
 ubifs-utils/Makemodule.am  |  1 +
 ubifs-utils/common/rwsem.h | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 ubifs-utils/common/rwsem.h
diff mbox series

Patch

diff --git a/ubifs-utils/Makemodule.am b/ubifs-utils/Makemodule.am
index 9f33f0db..ece8a6e9 100644
--- a/ubifs-utils/Makemodule.am
+++ b/ubifs-utils/Makemodule.am
@@ -7,6 +7,7 @@  common_SOURCES = \
 	ubifs-utils/common/bitops.c \
 	ubifs-utils/common/spinlock.h \
 	ubifs-utils/common/mutex.h \
+	ubifs-utils/common/rwsem.h \
 	ubifs-utils/common/kmem.h \
 	ubifs-utils/common/kmem.c \
 	ubifs-utils/common/defs.h \
diff --git a/ubifs-utils/common/rwsem.h b/ubifs-utils/common/rwsem.h
new file mode 100644
index 00000000..3761724b
--- /dev/null
+++ b/ubifs-utils/common/rwsem.h
@@ -0,0 +1,19 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_RWSEM_H_
+#define __LINUX_RWSEM_H_
+
+#include <pthread.h>
+
+struct rw_semaphore {
+	pthread_mutex_t lock;
+};
+
+#define init_rwsem(x)			pthread_mutex_init(&(x)->lock, NULL)
+
+#define down_read(x)			pthread_mutex_lock(&(x)->lock)
+#define down_write(x)			pthread_mutex_lock(&(x)->lock)
+#define up_read(x)			pthread_mutex_unlock(&(x)->lock)
+#define up_write(x)			pthread_mutex_unlock(&(x)->lock)
+#define down_write_trylock(x)		(pthread_mutex_trylock(&(x)->lock) == 0)
+
+#endif