From: Ondřej Surý Date: Fri, 28 Feb 2025 20:49:48 +0000 (+0100) Subject: Move locking macros into individual headers X-Git-Tag: ondrej/lock-free-qpzone-reads-v1~11^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=534069e048bddcad6738a4f7f79a39981a618fbe;p=thirdparty%2Fbind9.git 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. --- diff --git a/lib/isc/include/isc/mutex.h b/lib/isc/include/isc/mutex.h index a975b0d0650..19612dd99b3 100644 --- a/lib/isc/include/isc/mutex.h +++ b/lib/isc/include/isc/mutex.h @@ -22,6 +22,21 @@ #include /* for ISC_R_ codes */ #include +#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 diff --git a/lib/isc/include/isc/rwlock.h b/lib/isc/include/isc/rwlock.h index b636fbc37cb..67be70e2e09 100644 --- a/lib/isc/include/isc/rwlock.h +++ b/lib/isc/include/isc/rwlock.h @@ -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 #include diff --git a/lib/isc/include/isc/spinlock.h b/lib/isc/include/isc/spinlock.h index 3333836af53..f8c1e487c1e 100644 --- a/lib/isc/include/isc/spinlock.h +++ b/lib/isc/include/isc/spinlock.h @@ -21,6 +21,21 @@ #include #include +#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 diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index a392714e180..805e518afce 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -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 /* 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 */