2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Move locking macros into individual headers

Previously, the LOCK()/UNLOCK() and friends macros were defined in the
isc/util.h header.  Those macros were moved to their respective headers
as those would have to be included anyway if that particular lock was in
use.
This commit is contained in:
Ondřej Surý
2025-02-28 21:49:48 +01:00
parent 901637c25c
commit 534069e048
4 changed files with 64 additions and 99 deletions

View File

@@ -22,6 +22,21 @@
#include <isc/result.h> /* for ISC_R_ codes */
#include <isc/util.h>
#define LOCK(lp) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "LOCKING %p %s %d\n", (lp), \
__FILE__, __LINE__)); \
isc_mutex_lock((lp)); \
ISC_UTIL_TRACE(fprintf(stderr, "LOCKED %p %s %d\n", (lp), \
__FILE__, __LINE__)); \
}
#define UNLOCK(lp) \
{ \
isc_mutex_unlock((lp)); \
ISC_UTIL_TRACE(fprintf(stderr, "UNLOCKED %p %s %d\n", (lp), \
__FILE__, __LINE__)); \
}
/*
* We use macros instead of static inline functions so that the exact code
* location can be reported when PTHREADS_RUNTIME_CHECK() fails or when mutrace

View File

@@ -26,6 +26,40 @@ typedef enum {
isc_rwlocktype_write
} isc_rwlocktype_t;
#define RWLOCK(lp, t) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "RWLOCK %p, %d %s %d\n", (lp), \
(t), __FILE__, __LINE__)); \
isc_rwlock_lock((lp), (t)); \
ISC_UTIL_TRACE(fprintf(stderr, "RWLOCKED %p, %d %s %d\n", \
(lp), (t), __FILE__, __LINE__)); \
}
#define RWUNLOCK(lp, t) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "RWUNLOCK %p, %d %s %d\n", \
(lp), (t), __FILE__, __LINE__)); \
isc_rwlock_unlock((lp), (t)); \
}
#define RDLOCK(lp) RWLOCK(lp, isc_rwlocktype_read)
#define RDUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_read)
#define WRLOCK(lp) RWLOCK(lp, isc_rwlocktype_write)
#define WRUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_write)
#define UPGRADELOCK(lock, locktype) \
{ \
if (locktype == isc_rwlocktype_read) { \
if (isc_rwlock_tryupgrade(lock) == ISC_R_SUCCESS) { \
locktype = isc_rwlocktype_write; \
} else { \
RWUNLOCK(lock, locktype); \
locktype = isc_rwlocktype_write; \
RWLOCK(lock, locktype); \
} \
} \
INSIST(locktype == isc_rwlocktype_write); \
}
#if USE_PTHREAD_RWLOCK
#include <errno.h>
#include <pthread.h>

View File

@@ -21,6 +21,21 @@
#include <isc/atomic.h>
#include <isc/util.h>
#define SPINLOCK(sp) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKING %p %s %d\n", (sp), \
__FILE__, __LINE__)); \
isc_spinlock_lock((sp)); \
ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKED %p %s %d\n", (sp), \
__FILE__, __LINE__)); \
}
#define SPINUNLOCK(sp) \
{ \
isc_spinlock_unlock((sp)); \
ISC_UTIL_TRACE(fprintf(stderr, "SPINUNLOCKED %p %s %d\n", \
(sp), __FILE__, __LINE__)); \
}
/*
* We use macros instead of static inline functions so that the exact code
* location can be reported when PTHREADS_RUNTIME_CHECK() fails or when mutrace

View File

@@ -108,11 +108,6 @@
*/
#define EMPTY_TRANSLATION_UNIT extern int isc__empty;
/*%
* We use macros instead of calling the routines directly because
* the capital letters make the locking stand out.
*/
#ifdef ISC_UTIL_TRACEON
#define ISC_UTIL_TRACE(a) a
#include <stdio.h> /* Required for fprintf/stderr when tracing. */
@@ -120,100 +115,6 @@
#define ISC_UTIL_TRACE(a)
#endif /* ifdef ISC_UTIL_TRACEON */
#define SPINLOCK(sp) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKING %p %s %d\n", (sp), \
__FILE__, __LINE__)); \
isc_spinlock_lock((sp)); \
ISC_UTIL_TRACE(fprintf(stderr, "SPINLOCKED %p %s %d\n", (sp), \
__FILE__, __LINE__)); \
}
#define SPINUNLOCK(sp) \
{ \
isc_spinlock_unlock((sp)); \
ISC_UTIL_TRACE(fprintf(stderr, "SPINUNLOCKED %p %s %d\n", \
(sp), __FILE__, __LINE__)); \
}
#define LOCK(lp) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "LOCKING %p %s %d\n", (lp), \
__FILE__, __LINE__)); \
isc_mutex_lock((lp)); \
ISC_UTIL_TRACE(fprintf(stderr, "LOCKED %p %s %d\n", (lp), \
__FILE__, __LINE__)); \
}
#define UNLOCK(lp) \
{ \
isc_mutex_unlock((lp)); \
ISC_UTIL_TRACE(fprintf(stderr, "UNLOCKED %p %s %d\n", (lp), \
__FILE__, __LINE__)); \
}
#define BROADCAST(cvp) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "BROADCAST %p %s %d\n", (cvp), \
__FILE__, __LINE__)); \
isc_condition_broadcast((cvp)); \
}
#define SIGNAL(cvp) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "SIGNAL %p %s %d\n", (cvp), \
__FILE__, __LINE__)); \
isc_condition_signal((cvp)); \
}
#define WAIT(cvp, lp) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "WAIT %p LOCK %p %s %d\n", \
(cvp), (lp), __FILE__, __LINE__)); \
isc_condition_wait((cvp), (lp)); \
ISC_UTIL_TRACE(fprintf(stderr, "WAITED %p LOCKED %p %s %d\n", \
(cvp), (lp), __FILE__, __LINE__)); \
}
/*
* isc_condition_waituntil can return ISC_R_TIMEDOUT, so we
* don't RUNTIME_CHECK the result.
*
* XXX Also, can't really debug this then...
*/
#define WAITUNTIL(cvp, lp, tp) isc_condition_waituntil((cvp), (lp), (tp))
#define RWLOCK(lp, t) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "RWLOCK %p, %d %s %d\n", (lp), \
(t), __FILE__, __LINE__)); \
isc_rwlock_lock((lp), (t)); \
ISC_UTIL_TRACE(fprintf(stderr, "RWLOCKED %p, %d %s %d\n", \
(lp), (t), __FILE__, __LINE__)); \
}
#define RWUNLOCK(lp, t) \
{ \
ISC_UTIL_TRACE(fprintf(stderr, "RWUNLOCK %p, %d %s %d\n", \
(lp), (t), __FILE__, __LINE__)); \
isc_rwlock_unlock((lp), (t)); \
}
#define RDLOCK(lp) RWLOCK(lp, isc_rwlocktype_read)
#define RDUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_read)
#define WRLOCK(lp) RWLOCK(lp, isc_rwlocktype_write)
#define WRUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_write)
#define UPGRADELOCK(lock, locktype) \
{ \
if (locktype == isc_rwlocktype_read) { \
if (isc_rwlock_tryupgrade(lock) == ISC_R_SUCCESS) { \
locktype = isc_rwlocktype_write; \
} else { \
RWUNLOCK(lock, locktype); \
locktype = isc_rwlocktype_write; \
RWLOCK(lock, locktype); \
} \
} \
INSIST(locktype == isc_rwlocktype_write); \
}
/*%
* Performance
*/