]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move locking macros into individual headers
authorOndřej Surý <ondrej@isc.org>
Fri, 28 Feb 2025 20:49:48 +0000 (21:49 +0100)
committerOndřej Surý <ondrej@isc.org>
Sat, 1 Mar 2025 06:33:51 +0000 (07:33 +0100)
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.

lib/isc/include/isc/mutex.h
lib/isc/include/isc/rwlock.h
lib/isc/include/isc/spinlock.h
lib/isc/include/isc/util.h

index a975b0d0650f21b0ac5536c68dac2d580854a6ad..19612dd99b3edb27ca4356b355858fafcd54f121 100644 (file)
 #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
index b636fbc37cb19e4d53c6bce33daf9475e03aad29..67be70e2e09fb6222acac454d76e9912748f74c7 100644 (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>
index 3333836af5318e47b4786b74f91d372c9cb52954..f8c1e487c1e18c7bcb4ee52e4949ccaa041db32a 100644 (file)
 #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
index a392714e180cc4671c22d6c308fb3a2f6d6d8b23..805e518afce17be50ff2c4012bb7a0475bc34f24 100644 (file)
  */
 #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. */
 #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
  */