Add rwsem implementations, because there are some rwsems
(eg. c->commit_sem) used in UBIFS linux kernel libs.
The rwsem is implemented 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>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
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 \
--- /dev/null
+/* 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