aboutsummaryrefslogtreecommitdiff
path: root/ubifs-utils
diff options
context:
space:
mode:
authorZhihao Cheng <chengzhihao1@huawei.com>2024-11-11 16:36:48 +0800
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2024-11-11 10:32:45 +0100
commit2ac0a0ef95f731c75c8dd6f17ffd947000e7d61c (patch)
treee4f831c001bba81375c9a5d497539ecff2048f87 /ubifs-utils
parent9ce4a0e99198995bb7bf57076066b35fed23b8d3 (diff)
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 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>
Diffstat (limited to 'ubifs-utils')
-rw-r--r--ubifs-utils/Makemodule.am1
-rw-r--r--ubifs-utils/common/mutex.h18
2 files changed, 19 insertions, 0 deletions
diff --git a/ubifs-utils/Makemodule.am b/ubifs-utils/Makemodule.am
index 7849114..9f33f0d 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 0000000..4bf018b
--- /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