summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Merey <[email protected]>2025-02-19 23:36:36 -0500
committerAaron Merey <[email protected]>2025-03-26 17:01:24 -0400
commite9cd1d2951f4abb00b6e9edec225dde9c378bec3 (patch)
treecc1c736d1fafebcb4f4b08aa0559dc3023d2bbfb /lib
parent66ae4b7ed9fd8dfd95c1276e752b279fc1aad996 (diff)
Change type of dwarf_lock from rwlock to mutex
Change type of dwarf_lock to mutex in order to take advantage of built-in support for recursive locking. * lib/locks.h: Add macros for locking, unlocking, initializing and destroying mutexes. * libdw/dwarf_begin_elf.c (dwarf_end): Replace rwlock macro with mutex macro. * libdw/dwarf_formref_die.c (dwarf_formref_die): Ditto. * libdw/dwarf_getalt.c (dwarf_getalt): Ditto. * libdw/dwarf_setalt.c (dwarf_setalt): Ditto. * libdw/libdwP.h (struct Dwarf): Ditto. * libdw/libdw_findcu.c (__libdw_findcu): Ditto. Signed-off-by: Aaron Merey <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/locks.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/locks.h b/lib/locks.h
index 90fe3f1b..9c17eca7 100644
--- a/lib/locks.h
+++ b/lib/locks.h
@@ -43,6 +43,17 @@
# define rwlock_rdlock(lock) RWLOCK_CALL (rdlock (&lock))
# define rwlock_wrlock(lock) RWLOCK_CALL (wrlock (&lock))
# define rwlock_unlock(lock) RWLOCK_CALL (unlock (&lock))
+# define mutex_define(class,name) class pthread_mutex_t name
+# define MUTEX_CALL(call) \
+ ({ int _err = pthread_mutex_ ## call; assert_perror (_err); })
+# define mutex_init(lock) \
+ ({ pthread_mutexattr_t _attr; \
+ pthread_mutexattr_init (&_attr); \
+ pthread_mutexattr_settype (&_attr, PTHREAD_MUTEX_RECURSIVE); \
+ MUTEX_CALL (init (&lock, &_attr)); })
+# define mutex_lock(_lock) MUTEX_CALL (lock (&_lock))
+# define mutex_unlock(lock) MUTEX_CALL (unlock (&lock))
+# define mutex_fini(lock) MUTEX_CALL (destroy (&lock))
# define once(once_control, init_routine) \
ONCE_CALL (once (&once_control, init_routine))
#else
@@ -55,6 +66,11 @@
# define rwlock_rdlock(lock) ((void) (lock))
# define rwlock_wrlock(lock) ((void) (lock))
# define rwlock_unlock(lock) ((void) (lock))
+# define mutex_define(class,name) class int name
+# define mutex_init(lock) ((void) (lock))
+# define mutex_lock(lock) ((void) (lock))
+# define mutex_unlock(lock) ((void) (lock))
+# define mutex_fini(lock) ((void) (lock))
# define once_define(class,name)
# define once(once_control, init_routine) init_routine()
#endif /* USE_LOCKS */