Changeset 13580 in vbox for trunk/src/VBox/Main/include/AutoLock.h
- Timestamp:
- Oct 27, 2008 2:04:18 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/AutoLock.h
r8639 r13580 647 647 648 648 /** 649 * Same as #leave() but checks if the current thread actally owns the lock 650 * and only proceeds in this case. As a result, as opposed to #leave(), 651 * doesn't assert when called with no lock being held. 652 */ 653 void maybeLeave() 654 { 655 if (isWriteLockOnCurrentThread()) 656 leave(); 657 } 658 659 /** 660 * Same as #enter() but checks if the current thread actally owns the lock 661 * and only proceeds if not. As a result, as opposed to #enter(), doesn't 662 * assert when called with the lock already being held. 663 */ 664 void maybeEnter() 665 { 666 if (!isWriteLockOnCurrentThread()) 667 enter(); 668 } 669 670 /** 649 671 * Causes the current thread to restore the write lock level after the 650 672 * #leave() call. This call will indefinitely block if another thread has … … 663 685 } 664 686 } 687 688 /** 689 * Attaches another handle to this auto lock instance. 690 * 691 * The previous object's lock is completely released before the new one is 692 * acquired. The lock level of the new handle will be the same. This 693 * also means that if the lock was not acquired at all before #attach(), it 694 * will not be acquired on the new handle too. 695 * 696 * @param aHandle New handle to attach. 697 */ 698 void attach (LockHandle *aHandle) 699 { 700 /* detect simple self-reattachment */ 701 if (mHandle != aHandle) 702 { 703 uint32_t lockLevel = mLockLevel; 704 705 /* perform the destructor part */ 706 if (mHandle) 707 { 708 if (mGlobalLockLevel) 709 { 710 mGlobalLockLevel -= mLockLevel; 711 mLockLevel = 0; 712 for (; mGlobalLockLevel; -- mGlobalLockLevel) 713 mHandle->lockWrite(); 714 } 715 716 AssertMsg (mLockLevel <= 1, ("Lock level > 1: %d\n", mLockLevel)); 717 for (; mLockLevel; -- mLockLevel) 718 mHandle->unlockWrite(); 719 } 720 721 mHandle = aHandle; 722 mLockLevel = lockLevel; 723 724 if (mHandle) 725 for (; lockLevel; -- lockLevel) 726 mHandle->lockWrite(); 727 } 728 } 729 730 /** @see attach (LockHandle *) */ 731 void attach (LockHandle &aHandle) { attach (&aHandle); } 732 733 /** @see attach (LockHandle *) */ 734 void attach (const Lockable &aLockable) { attach (aLockable.lockHandle()); } 735 736 /** @see attach (LockHandle *) */ 737 void attach (const Lockable *aLockable) 738 { attach (aLockable ? aLockable->lockHandle() : NULL); } 739 740 /** Verbose equivalent to <tt>attach (NULL)</tt>. */ 741 void detach() { attach ((LockHandle *) NULL); } 665 742 666 743 /** Returns @c true if this instance manages a null semaphore handle. */ … … 916 993 } 917 994 } 995 996 /** 997 * Attaches another handle to this auto lock instance. 998 * 999 * The previous object's lock is completely released before the new one is 1000 * acquired. The lock level of the new handle will be the same. This also 1001 * means that if the lock was not acquired at all before #attach(), it will 1002 * not be acquired on the new handle too. 1003 * 1004 * @param aHandle New handle to attach. 1005 */ 1006 void attach (LockHandle *aHandle) 1007 { 1008 /* detect simple self-reattachment */ 1009 if (mHandle != aHandle) 1010 { 1011 uint32_t lockLevel = mLockLevel; 1012 if (mHandle) 1013 for (; mLockLevel; -- mLockLevel) 1014 mHandle->unlockRead(); 1015 mHandle = aHandle; 1016 mLockLevel = lockLevel; 1017 if (mHandle) 1018 for (; lockLevel; -- lockLevel) 1019 mHandle->lockRead(); 1020 } 1021 } 1022 1023 /** @see attach (LockHandle *) */ 1024 void attach (LockHandle &aHandle) { attach (&aHandle); } 1025 1026 /** @see attach (LockHandle *) */ 1027 void attach (const Lockable &aLockable) { attach (aLockable.lockHandle()); } 1028 1029 /** @see attach (LockHandle *) */ 1030 void attach (const Lockable *aLockable) 1031 { attach (aLockable ? aLockable->lockHandle() : NULL); } 1032 1033 /** Verbose equivalent to <tt>attach (NULL)</tt>. */ 1034 void detach() { attach ((LockHandle *) NULL); } 918 1035 919 1036 /** Returns @c true if this instance manages a null semaphore handle. */ … … 1158 1275 mLocks [-- i].leave(); 1159 1276 while (i != 0); 1277 } 1278 1279 /** 1280 * Calls AutoWriteLock::maybeLeave() methods for all managed semaphore 1281 * handles in reverse to the order they were passed to the constructor. 1282 */ 1283 void maybeLeave() 1284 { 1285 AssertReturnVoid (ELEMENTS (mLocks) > 0); 1286 size_t i = ELEMENTS (mLocks); 1287 do 1288 mLocks [-- i].maybeLeave(); 1289 while (i != 0); 1290 } 1291 1292 /** 1293 * Calls AutoWriteLock::maybeEnter() methods for all managed semaphore 1294 * handles in order they were passed to the constructor. 1295 */ 1296 void maybeEnter() 1297 { 1298 size_t i = 0; 1299 while (i < ELEMENTS (mLocks)) 1300 mLocks [i ++].maybeEnter(); 1160 1301 } 1161 1302
Note:
See TracChangeset
for help on using the changeset viewer.