start design for the allrecord_lock
authorVolker Lendecke <vl@samba.org>
Wed, 6 Feb 2013 21:52:43 +0000 (22:52 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 27 Jun 2016 19:44:40 +0000 (21:44 +0200)
lib/tdb/common/mutex.c

index c212842746827d6a6c7d6b6f577ece61175fb889..af5e05549805f5e29f8e57831a76cfaa323fa724 100644 (file)
 
 #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