#ifdef USE_TDB_MUTEX_LOCKING
+struct tdb_mutex_header {
+ uint32_t alignment;
+
+ /*
+ * allrecord_lock handling
+ *
+ * Lock a hash chain lock:
+ * 1. Lock the hash mutex
+ * 2. Lock allrecord_mutex
+ * 3. If "allrecord_lock==1": drop the hash mutex
+ * 4. Wait on "allrecord_waiters"&"allrecord_mutex"
+ * 5. Wake up
+ * 6. Unlock "allrecord_mutex"
+ * 7. Goto 1.
+ * 8. When "allrecord_lock==0", unlock allrecord_mutex
+ * 9. Do work on the hash chain
+ * 10. Unlock hash mutex
+ *
+ * Lock allrecord_lock:
+ * 1. Lock allrecord_recovery_mutex
+ * 2. Lock allrecord_mutex
+ * 3. allrecord_lock must be 0, otherwise the previous
+ * allrecord_recover_mutex holder did not clean up properly.
+ * 4. Set allrecord_lock to 1
+ * 5. Unlock allrecord_mutex
+ * 6. For all hash mutexes: (make sure we're alone)
+ * 7. Lock hash mutex
+ * 8. Unlock hash mutex
+ * 9. Do work under the allrecord_lock
+ * 10. Lock allrecord_mutex
+ * 11. Broadcast allrecord_waiters
+ * 12. Unlock allrecord_recovery_mutex
+ */
+
+ /*
+ * Lock held for recovery when the allrecord_lock holder dies
+ */
+ pthread_mutex_t allrecord_lock_recovery_mutex;
+
+ /*
+ * protect allrecord_lock
+ */
+ pthread_mutex_t allrecord_mutex;
+
+ /*
+ * Is the allrecord_lock held?
+ */
+ bool allrecord_lock;
+
+ /*
+ * Wait for the allrecord_lock
+ */
+ pthread_cond_t allrecord_waiters;
+};
+
/*
* If we run with mutexes, we store the "struct tdb_mutexes" at the
* beginning of the file. We store an additional tdb_header right