From 71354a4b25aa3f54ed214fc80638e34d3befa977 Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Mon, 11 Nov 2024 16:36:49 +0800 Subject: ubifs-utils: Add rwsem implementations 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 Signed-off-by: David Oberhollenzer --- ubifs-utils/common/rwsem.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ubifs-utils/common/rwsem.h (limited to 'ubifs-utils/common') diff --git a/ubifs-utils/common/rwsem.h b/ubifs-utils/common/rwsem.h new file mode 100644 index 0000000..3761724 --- /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 + +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 -- cgit v1.2.3