private void acquireGlobalWriteLock ( TxId txId ) throws InterruptedException { // Get the global write lock to ensure only one thread at a time can execute this code. globalLock . writeLock ( ) . lock ( ) ; // Use a try block so that the corresponding finally block guarantees release of the thread lock. try { // Check that this transaction does not already own the lock. if ( ! txId . equals ( globalWriteLockTxId ) ) { // Wait until the write lock becomes free. while ( globalWriteLockTxId != null ) { globalWriteLockFree . await ( ) ; } // Assign the global write lock to this transaction. globalWriteLockTxId = txId ; } } finally { // Ensure that the thread lock is released once assignment of the write lock to the transaction is complete. globalLock . writeLock ( ) . unlock ( ) ; } }
Waits until the global write lock can be acquired by the specified transaction .