Changeset 25908 in vbox
- Timestamp:
- Jan 18, 2010 10:07:28 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56726
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/lockvalidator.h
r25748 r25908 718 718 719 719 /** 720 * Checks if the specified thread is one of the owners. 721 * 722 * @returns true if it is, false if not. 723 * 724 * @param pRec The validator record. 725 * @param hThread The thread handle of the owner. NIL_RTTHREAD is 726 * an alias for the current thread. 727 */ 728 RTDECL(bool) RTLockValidatorRecSharedIsOwner(PRTLOCKVALRECSHRD pRec, RTTHREAD hThread); 729 730 /** 720 731 * Check the exit order and release (unset) the shared ownership. 721 732 * -
trunk/include/iprt/semaphore.h
r25759 r25908 850 850 */ 851 851 RTDECL(bool) RTSemRWIsWriteOwner(RTSEMRW hRWSem); 852 853 /** 854 * Checks if the caller is one of the read owners of the sempahore. 855 * 856 * @note !CAUTION! This API doesn't work reliably if lock validation isn't 857 * enabled. Meaning, the answer is not trustworhty unless 858 * RT_LOCK_STRICT or RTSEMRW_STRICT was defined at build time. Also, 859 * make sure you do not use RTSEMRW_FLAGS_NO_LOCK_VAL when creating 860 * the semaphore. And finally, if you used a locking class, don't 861 * disable deadlock detection by setting cMsMinDeadlock to 862 * RT_INDEFINITE_WAIT. 863 * 864 * In short, only use this for assertions. 865 * 866 * @returns true if reader, false if not. 867 * @param hRWSem Handle to the read/write semaphore. 868 * @param fWannaHear What you'd like to hear when lock validation is 869 * not available. (For avoiding asserting all over 870 * the place.) 871 */ 872 RTDECL(bool) RTSemRWIsReadOwner(RTSEMRW hRWSem, bool fWannaHear); 852 873 853 874 /** -
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25844 r25908 4018 4018 if (!pRec->fEnabled) 4019 4019 return; 4020 AssertReturnVoid(hThread != NIL_RTTHREAD); 4020 if (hThread == NIL_RTTHREAD) 4021 { 4022 hThread = RTThreadSelfAutoAdopt(); 4023 AssertReturnVoid(hThread != NIL_RTTHREAD); 4024 } 4021 4025 AssertReturnVoid(hThread->u32Magic == RTTHREADINT_MAGIC); 4022 4026 … … 4043 4047 } 4044 4048 RT_EXPORT_SYMBOL(RTLockValidatorRecSharedRemoveOwner); 4049 4050 4051 RTDECL(bool) RTLockValidatorRecSharedIsOwner(PRTLOCKVALRECSHRD pRec, RTTHREAD hThread) 4052 { 4053 /* Validate and resolve input. */ 4054 AssertReturn(pRec->Core.u32Magic == RTLOCKVALRECSHRD_MAGIC, false); 4055 if (!pRec->fEnabled) 4056 return false; 4057 if (hThread == NIL_RTTHREAD) 4058 { 4059 hThread = RTThreadSelfAutoAdopt(); 4060 AssertReturn(hThread != NIL_RTTHREAD, false); 4061 } 4062 AssertReturn(hThread->u32Magic == RTTHREADINT_MAGIC, false); 4063 4064 /* Do the job. */ 4065 PRTLOCKVALRECUNION pEntry = rtLockValidatorRecSharedFindOwner(pRec, hThread, NULL); 4066 return pEntry != NULL; 4067 } 4068 RT_EXPORT_SYMBOL(RTLockValidatorRecSharedIsOwner); 4045 4069 4046 4070 -
trunk/src/VBox/Runtime/generic/RTFileReadAll-generic.cpp
r21337 r25908 39 39 RTDECL(int) RTFileReadAll(const char *pszFilename, void **ppvFile, size_t *pcbFile) 40 40 { 41 return RTFileReadAllEx(pszFilename, 0, RTFOFF_MAX, 0, ppvFile, pcbFile);41 return RTFileReadAllEx(pszFilename, 0, RTFOFF_MAX, RTFILE_RDALL_O_DENY_WRITE, ppvFile, pcbFile); 42 42 } 43 43 RT_EXPORT_SYMBOL(RTFileReadAll); -
trunk/src/VBox/Runtime/generic/semrw-generic.cpp
r25831 r25908 869 869 RTDECL(bool) RTSemRWIsWriteOwner(RTSEMRW hRWSem) 870 870 { 871 /* 872 * Validate handle. 873 */ 871 874 struct RTSEMRWINTERNAL *pThis = hRWSem; 872 873 /*874 * Validate handle.875 */876 875 AssertPtrReturn(pThis, false); 877 876 AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, false); … … 886 885 } 887 886 RT_EXPORT_SYMBOL(RTSemRWIsWriteOwner); 887 888 889 RTDECL(bool) RTSemRWIsReadOwner(RTSEMRW hRWSem, bool fWannaHear) 890 { 891 /* 892 * Validate handle. 893 */ 894 struct RTSEMRWINTERNAL *pThis = hRWSem; 895 AssertPtrReturn(pThis, false); 896 AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, false); 897 898 /* 899 * Check write ownership. The writer is also a valid reader. 900 */ 901 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 902 RTNATIVETHREAD hWriter; 903 ASMAtomicUoReadHandle(&pThis->hWriter, &hWriter); 904 if (hWriter == hNativeSelf) 905 return true; 906 if (hWriter != NIL_RTNATIVETHREAD) 907 return false; 908 909 #ifdef RTSEMRW_STRICT 910 /* 911 * Ask the lock validator. 912 */ 913 return RTLockValidatorRecSharedIsOwner(&pThis->ValidatorRead, NIL_RTTHREAD); 914 #else 915 /* 916 * If there are no reads we cannot be one of them... But if there are we 917 * cannot know and can only return what the caller want to hear. 918 */ 919 if (pThis->cReads == 0) 920 return false; 921 return fWannaHear; 922 #endif 923 } 924 RT_EXPORT_SYMBOL(RTSemRWIsReadOwner); 888 925 889 926 -
trunk/src/VBox/Runtime/generic/semrw-lockless-generic.cpp
r25831 r25908 876 876 877 877 878 RTDECL(bool) RTSemRWIsReadOwner(RTSEMRW hRWSem, bool fWannaHear) 879 { 880 /* 881 * Validate handle. 882 */ 883 struct RTSEMRWINTERNAL *pThis = hRWSem; 884 AssertPtrReturn(pThis, false); 885 AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, false); 886 887 /* 888 * Inspect the state. 889 */ 890 uint64_t u64State = ASMAtomicReadU64(&pThis->u64State); 891 if ((u64State & RTSEMRW_DIR_MASK) == (RTSEMRW_DIR_WRITE << RTSEMRW_DIR_SHIFT)) 892 { 893 /* 894 * It's in write mode, so we can only be a reader if we're also the 895 * current writer. 896 */ 897 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 898 RTNATIVETHREAD hWriter; 899 ASMAtomicUoReadHandle(&pThis->hWriter, &hWriter); 900 return hWriter == hNativeSelf; 901 } 902 903 /* 904 * Read mode. If there are no current readers, then we cannot be a reader. 905 */ 906 if (!(u64State & RTSEMRW_CNT_RD_MASK)) 907 return false; 908 909 #ifdef RTSEMRW_STRICT 910 /* 911 * Ask the lock validator. 912 */ 913 return RTLockValidatorRecSharedIsOwner(&pThis->ValidatorRead, NIL_RTTHREAD); 914 #else 915 /* 916 * Ok, we don't know, just tell the caller what he want to hear. 917 */ 918 return fWannaHear; 919 #endif 920 } 921 RT_EXPORT_SYMBOL(RTSemRWIsReadOwner); 922 923 878 924 RTDECL(uint32_t) RTSemRWGetWriteRecursion(RTSEMRW hRWSem) 879 925 { -
trunk/src/VBox/Runtime/r3/posix/semrw-posix.cpp
r25831 r25908 638 638 639 639 640 RTDECL(bool) RTSemRWIsReadOwner(RTSEMRW hRWSem, bool fWannaHear) 641 { 642 /* 643 * Validate handle. 644 */ 645 struct RTSEMRWINTERNAL *pThis = hRWSem; 646 AssertPtrReturn(pThis, false); 647 AssertReturn(pThis->u32Magic == RTSEMRW_MAGIC, false); 648 649 /* 650 * Check write ownership. The writer is also a valid reader. 651 */ 652 pthread_t Self = pthread_self(); 653 pthread_t Writer; 654 ATOMIC_GET_PTHREAD_T(&pThis->Writer, &Writer); 655 if (Writer == Self) 656 return true; 657 if (Writer != (pthread_t)-1) 658 return false; 659 660 /* 661 * If there are no readers, we cannot be one of them, can we? 662 */ 663 if (ASMAtomicReadU32(&pThis->cReaders) == 0) 664 return false; 665 666 #ifdef RTSEMRW_STRICT 667 /* 668 * Ask the lock validator. 669 */ 670 return RTLockValidatorRecSharedIsOwner(&pThis->ValidatorRead, NIL_RTTHREAD); 671 #else 672 /* 673 * Just tell the caller what he want to hear. 674 */ 675 return fWannaHear; 676 #endif 677 } 678 RT_EXPORT_SYMBOL(RTSemRWIsReadOwner); 679 680 640 681 RTDECL(uint32_t) RTSemRWGetWriteRecursion(RTSEMRW hRWSem) 641 682 {
Note:
See TracChangeset
for help on using the changeset viewer.