Changeset 25722 in vbox
- Timestamp:
- Jan 11, 2010 2:22:03 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56464
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/semaphore.h
r25721 r25722 484 484 * 485 485 * @returns iprt status code. 486 * @param pMutexSem Where to store the mutex semaphore handle. 486 * @param phFastMtx Where to store the handle to the newly created 487 * fast mutex semaphore. 487 488 * 488 489 * @remarks Fast mutex semaphores are not recursive. 489 490 */ 490 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem);491 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx); 491 492 492 493 /** … … 494 495 * 495 496 * @returns iprt status code. 496 * @param hMutexSem The mutex semaphore to destroy. 497 */ 498 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hMutexSem); 497 * @param hFastMtx Handle to the fast mutex semaphore. NIL is 498 * quietly ignored (VINF_SUCCESS). 499 */ 500 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx); 499 501 500 502 /** … … 506 508 * 507 509 * @returns iprt status code. 508 * @param h MutexSem The mutex semaphore to request ownership over.509 */ 510 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX h MutexSem);510 * @param hFastMtx Handle to the fast mutex semaphore. 511 */ 512 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx); 511 513 512 514 /** … … 514 516 * 515 517 * @returns iprt status code. 516 * @param hMutexSem The mutex to release the ownership of. 517 * It goes without saying the the calling thread must own it. 518 */ 519 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hMutexSem); 518 * @param hFastMtx Handle to the fast mutex semaphore. It goes 519 * without saying the the calling thread must own 520 * it. 521 */ 522 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx); 520 523 521 524 /** @} */ -
trunk/src/VBox/Runtime/generic/semfastmutex-generic.cpp
r21533 r25722 42 42 43 43 44 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem)44 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx) 45 45 { 46 46 PRTCRITSECT pCritSect = (PRTCRITSECT)RTMemAlloc(sizeof(RTCRITSECT)); 47 47 if (!pCritSect) 48 48 return VERR_NO_MEMORY; 49 int rc = RTCritSectInit(pCritSect); 49 50 int rc = RTCritSectInitEx(pCritSect, RTCRITSECT_FLAGS_NO_NESTING, 51 NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL); 50 52 if (RT_SUCCESS(rc)) 51 { 52 /** @todo pCritSect->fFlags |= RTCRITSECT_FLAGS_NO_NESTING; */ 53 *pMutexSem = (RTSEMFASTMUTEX)pCritSect; 54 } 53 *phFastMtx = (RTSEMFASTMUTEX)pCritSect; 55 54 else 56 55 RTMemFree(pCritSect); … … 60 59 61 60 62 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)61 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx) 63 62 { 64 if ( MutexSem== NIL_RTSEMFASTMUTEX)63 if (hFastMtx == NIL_RTSEMFASTMUTEX) 65 64 return VERR_INVALID_PARAMETER; 66 PRTCRITSECT pCritSect = (PRTCRITSECT) MutexSem;65 PRTCRITSECT pCritSect = (PRTCRITSECT)hFastMtx; 67 66 int rc = RTCritSectDelete(pCritSect); 68 67 if (RT_SUCCESS(rc)) … … 73 72 74 73 75 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)74 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx) 76 75 { 77 return RTCritSectEnter((PRTCRITSECT) MutexSem);76 return RTCritSectEnter((PRTCRITSECT)hFastMtx); 78 77 } 79 78 RT_EXPORT_SYMBOL(RTSemFastMutexRequest); 80 79 81 80 82 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)81 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx) 83 82 { 84 return RTCritSectLeave((PRTCRITSECT) MutexSem);83 return RTCritSectLeave((PRTCRITSECT)hFastMtx); 85 84 } 86 85 RT_EXPORT_SYMBOL(RTSemFastMutexRelease); -
trunk/src/VBox/Runtime/r0drv/darwin/semaphore-r0drv-darwin.cpp
r25721 r25722 530 530 531 531 #if 0 /* need proper timeout lock function! */ 532 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX p MutexSem)532 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX phFastMtx) 533 533 { 534 534 RT_ASSERT_PREEMPTIBLE(); … … 542 542 if (pThis->pMtx) 543 543 { 544 *p MutexSem= pThis;544 *phFastMtx = pThis; 545 545 return VINF_SUCCESS; 546 546 } … … 653 653 654 654 655 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem)655 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx) 656 656 { 657 657 AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *)); 658 AssertPtrReturn(p MutexSem, VERR_INVALID_POINTER);658 AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER); 659 659 RT_ASSERT_PREEMPTIBLE(); 660 660 661 PRTSEMFASTMUTEXINTERNAL p FastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));662 if (p FastInt)663 { 664 p FastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;661 PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis)); 662 if (pThis) 663 { 664 pThis->u32Magic = RTSEMFASTMUTEX_MAGIC; 665 665 Assert(g_pDarwinLockGroup); 666 p FastInt->pMtx = lck_mtx_alloc_init(g_pDarwinLockGroup, LCK_ATTR_NULL);667 if (p FastInt->pMtx)666 pThis->pMtx = lck_mtx_alloc_init(g_pDarwinLockGroup, LCK_ATTR_NULL); 667 if (pThis->pMtx) 668 668 { 669 *p MutexSem = pFastInt;669 *phFastMtx = pThis; 670 670 return VINF_SUCCESS; 671 671 } 672 672 673 RTMemFree(p FastInt);673 RTMemFree(pThis); 674 674 } 675 675 return VERR_NO_MEMORY; … … 677 677 678 678 679 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hMutexSem) 680 { 681 if (hMutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */ 682 return VERR_INVALID_PARAMETER; 683 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)hMutexSem; 684 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 685 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 686 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 687 VERR_INVALID_PARAMETER); 679 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx) 680 { 681 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 682 if (pThis == NIL_RTSEMFASTMUTEX) 683 return VINF_SUCCESS; 684 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 685 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 688 686 RT_ASSERT_INTS_ON(); 689 687 690 ASMAtomic IncU32(&pFastInt->u32Magic); /* make the handle invalid. */688 ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD); 691 689 Assert(g_pDarwinLockGroup); 692 lck_mtx_free(pFastInt->pMtx, g_pDarwinLockGroup); 693 pFastInt->pMtx = NULL; 694 RTMemFree(pFastInt); 695 696 return VINF_SUCCESS; 697 } 698 699 700 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hMutexSem) 701 { 702 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)hMutexSem; 703 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 704 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 705 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 706 VERR_INVALID_PARAMETER); 690 lck_mtx_free(pThis->pMtx, g_pDarwinLockGroup); 691 pThis->pMtx = NULL; 692 RTMemFree(pThis); 693 694 return VINF_SUCCESS; 695 } 696 697 698 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx) 699 { 700 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 701 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 702 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 707 703 RT_ASSERT_PREEMPTIBLE(); 708 lck_mtx_lock(pFastInt->pMtx); 709 return VINF_SUCCESS; 710 } 711 712 713 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hMutexSem) 714 { 715 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)hMutexSem; 716 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 717 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 718 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 719 VERR_INVALID_PARAMETER); 704 705 lck_mtx_lock(pThis->pMtx); 706 return VINF_SUCCESS; 707 } 708 709 710 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx) 711 { 712 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 713 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 714 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 720 715 RT_ASSERT_PREEMPTIBLE(); 721 lck_mtx_unlock(pFastInt->pMtx); 722 return VINF_SUCCESS; 723 } 724 716 717 lck_mtx_unlock(pThis->pMtx); 718 return VINF_SUCCESS; 719 } 720 -
trunk/src/VBox/Runtime/r0drv/freebsd/semfastmutex-r0drv-freebsd.c
r22579 r25722 58 58 59 59 60 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem)60 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx) 61 61 { 62 62 AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *)); 63 AssertPtrReturn(p MutexSem, VERR_INVALID_POINTER);63 AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER); 64 64 65 PRTSEMFASTMUTEXINTERNAL p FastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pFastInt));66 if (p FastInt)65 PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis)); 66 if (pThis) 67 67 { 68 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC; 69 sx_init(&pFastInt->SxLock, "IPRT Fast Mutex Semaphore"); 70 *pMutexSem = pFastInt; 68 pThis->u32Magic = RTSEMFASTMUTEX_MAGIC; 69 sx_init(&pThis->SxLock, "IPRT Fast Mutex Semaphore"); 70 71 *phFastMtx = pThis; 71 72 return VINF_SUCCESS; 72 73 } … … 75 76 76 77 77 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)78 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx) 78 79 { 79 if (MutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */ 80 return VERR_INVALID_PARAMETER; 81 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 82 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 83 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 84 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 85 VERR_INVALID_PARAMETER); 80 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 81 if (pThis == NIL_RTSEMFASTMUTEX) 82 return VINF_SUCCESS; 83 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 84 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 86 85 87 ASMAtomic XchgU32(&pFastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);88 sx_destroy(&p FastInt->SxLock);89 RTMemFree(p FastInt);86 ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD); 87 sx_destroy(&pThis->SxLock); 88 RTMemFree(pThis); 90 89 91 90 return VINF_SUCCESS; … … 93 92 94 93 95 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)94 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx) 96 95 { 97 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 98 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 99 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 100 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 101 VERR_INVALID_PARAMETER); 96 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 97 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 98 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 102 99 103 sx_xlock(&p FastInt->SxLock);100 sx_xlock(&pThis->SxLock); 104 101 return VINF_SUCCESS; 105 102 } 106 103 107 104 108 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)105 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx) 109 106 { 110 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 111 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 112 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 113 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 114 VERR_INVALID_PARAMETER); 107 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 108 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 109 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 115 110 116 sx_xunlock(&p FastInt->SxLock);111 sx_xunlock(&pThis->SxLock); 117 112 return VINF_SUCCESS; 118 113 } -
trunk/src/VBox/Runtime/r0drv/linux/semfastmutex-r0drv-linux.c
r21337 r25722 66 66 67 67 68 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem)68 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx) 69 69 { 70 70 /* 71 71 * Allocate. 72 72 */ 73 PRTSEMFASTMUTEXINTERNAL p FastInt;74 p FastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));75 if (!p FastInt)73 PRTSEMFASTMUTEXINTERNAL pThis; 74 pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis)); 75 if (!pThis) 76 76 return VERR_NO_MEMORY; 77 77 … … 79 79 * Initialize. 80 80 */ 81 p FastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;82 sema_init(&p FastInt->Semaphore, 1);81 pThis->u32Magic = RTSEMFASTMUTEX_MAGIC; 82 sema_init(&pThis->Semaphore, 1); 83 83 #ifdef IPRT_DEBUG_SEMS 84 p FastInt->Owner = NIL_RTNATIVETHREAD;84 pThis->Owner = NIL_RTNATIVETHREAD; 85 85 #endif 86 *pMutexSem = pFastInt; 86 87 *phFastMtx = pThis; 87 88 return VINF_SUCCESS; 88 89 } … … 90 91 91 92 92 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)93 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx) 93 94 { 94 95 /* 95 96 * Validate. 96 97 */ 97 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 98 if (!pFastInt) 99 return VERR_INVALID_PARAMETER; 100 if (pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 101 { 102 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt)); 103 return VERR_INVALID_PARAMETER; 104 } 98 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 99 if (pThis == NIL_RTSEMFASTMUTEX) 100 return VINF_SUCCESS; 101 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 102 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); 105 103 106 ASMAtomic IncU32(&pFastInt->u32Magic);107 RTMemFree(p FastInt);104 ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD); 105 RTMemFree(pThis); 108 106 return VINF_SUCCESS; 109 107 } … … 111 109 112 110 113 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)111 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx) 114 112 { 115 113 /* 116 114 * Validate. 117 115 */ 118 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 119 if ( !pFastInt 120 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 121 { 122 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt)); 123 return VERR_INVALID_PARAMETER; 124 } 116 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 117 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 118 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); 125 119 126 120 #ifdef IPRT_DEBUG_SEMS 127 snprintf(current->comm, TASK_COMM_LEN, "d%lx", IPRT_DEBUG_SEMS_ADDRESS(p FastInt));121 snprintf(current->comm, TASK_COMM_LEN, "d%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis)); 128 122 #endif 129 down(&p FastInt->Semaphore);123 down(&pThis->Semaphore); 130 124 #ifdef IPRT_DEBUG_SEMS 131 snprintf(current->comm, TASK_COMM_LEN, "o%lx", IPRT_DEBUG_SEMS_ADDRESS(p FastInt));132 AssertRelease(p FastInt->Owner == NIL_RTNATIVETHREAD);133 ASMAtomicUoWriteSize(&p FastInt->Owner, RTThreadNativeSelf());125 snprintf(current->comm, TASK_COMM_LEN, "o%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis)); 126 AssertRelease(pThis->Owner == NIL_RTNATIVETHREAD); 127 ASMAtomicUoWriteSize(&pThis->Owner, RTThreadNativeSelf()); 134 128 #endif 135 129 return VINF_SUCCESS; … … 138 132 139 133 140 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)134 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx) 141 135 { 142 136 /* 143 137 * Validate. 144 138 */ 145 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 146 if ( !pFastInt 147 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 148 { 149 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt)); 150 return VERR_INVALID_PARAMETER; 151 } 139 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 140 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 141 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); 152 142 153 143 #ifdef IPRT_DEBUG_SEMS 154 AssertRelease(p FastInt->Owner == RTThreadNativeSelf());155 ASMAtomicUoWriteSize(&p FastInt->Owner, NIL_RTNATIVETHREAD);144 AssertRelease(pThis->Owner == RTThreadNativeSelf()); 145 ASMAtomicUoWriteSize(&pThis->Owner, NIL_RTNATIVETHREAD); 156 146 #endif 157 up(&p FastInt->Semaphore);147 up(&pThis->Semaphore); 158 148 #ifdef IPRT_DEBUG_SEMS 159 snprintf(current->comm, TASK_COMM_LEN, "u%lx", IPRT_DEBUG_SEMS_ADDRESS(p FastInt));149 snprintf(current->comm, TASK_COMM_LEN, "u%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis)); 160 150 #endif 161 151 return VINF_SUCCESS; -
trunk/src/VBox/Runtime/r0drv/nt/semeventmulti-r0drv-nt.cpp
r25720 r25722 76 76 KeInitializeEvent(&pThis->Event, NotificationEvent, FALSE /* not signalled */); 77 77 78 *phEvent Sem = pThis;78 *phEventMultiSem = pThis; 79 79 return VINF_SUCCESS; 80 80 } -
trunk/src/VBox/Runtime/r0drv/nt/semfastmutex-r0drv-nt.cpp
r12160 r25722 60 60 61 61 62 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem)62 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx) 63 63 { 64 64 /* 65 65 * Allocate. 66 66 */ 67 PRTSEMFASTMUTEXINTERNAL p FastInt;68 Assert(sizeof(*p FastInt) > sizeof(void *));69 p FastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));70 if (!p FastInt)67 PRTSEMFASTMUTEXINTERNAL pThis; 68 Assert(sizeof(*pThis) > sizeof(void *)); 69 pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis)); 70 if (!pThis) 71 71 return VERR_NO_MEMORY; 72 72 … … 74 74 * Initialize. 75 75 */ 76 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC; 77 ExInitializeFastMutex(&pFastInt->Mutex); 78 *pMutexSem = pFastInt; 76 pThis->u32Magic = RTSEMFASTMUTEX_MAGIC; 77 ExInitializeFastMutex(&pThis->Mutex); 78 79 *phFastMtx = pThis; 79 80 return VINF_SUCCESS; 80 81 } 81 82 82 83 83 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)84 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx) 84 85 { 85 86 /* 86 87 * Validate. 87 88 */ 88 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 89 if (!pFastInt) 90 return VERR_INVALID_PARAMETER; 91 if (pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 92 { 93 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt)); 94 return VERR_INVALID_PARAMETER; 95 } 89 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 90 if (pThis == NIL_RTSEMFASTMUTEX) 91 return VINF_SUCCESS; 92 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 93 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 96 94 97 ASMAtomicIncU32(&pFastInt->u32Magic); 98 Assert(pFastInt->Mutex.Count == 1); 99 /* It's not very clear what this Contention field really means. Seems to be a counter for the number of times contention occurred. (see e.g. http://winprogger.com/?p=6) 100 * The following assertion is therefor wrong: 101 * Assert(pFastInt->Mutex.Contention == 0); 102 */ 103 RTMemFree(pFastInt); 95 ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD); 96 Assert(pThis->Mutex.Count == 1); 97 RTMemFree(pThis); 104 98 return VINF_SUCCESS; 105 99 } 106 100 107 101 108 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)102 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx) 109 103 { 110 104 /* 111 105 * Validate. 112 106 */ 113 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 114 if ( !pFastInt 115 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 116 { 117 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt)); 118 return VERR_INVALID_PARAMETER; 119 } 107 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 108 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 109 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 110 120 111 #if 1 121 112 /* 122 113 * ExAcquireFastMutex will set the IRQL to APC regardless of our current 123 * level. Lowering the IRQL may screw things up, so toallow this.114 * level. Lowering the IRQL may screw things up, so do not allow this. 124 115 */ 125 116 # if 0 /** @todo enable this when the logger has been fixed. */ 126 AssertMsg(KeGetCurrentIrql() <= APC_LEVEL, 127 ("%d\n", KeGetCurrentIrql()), 128 VERR_INVALID_STATE); 117 AssertMsg(KeGetCurrentIrql() <= APC_LEVEL, ("%d\n", KeGetCurrentIrql()), VERR_INVALID_STATE); 129 118 # else /* the gentler approach. */ 130 119 KIRQL Irql = KeGetCurrentIrql(); … … 134 123 #endif 135 124 136 ExAcquireFastMutex(&p FastInt->Mutex);125 ExAcquireFastMutex(&pThis->Mutex); 137 126 return VINF_SUCCESS; 138 127 } 139 128 140 129 141 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)130 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx) 142 131 { 143 132 /* 144 133 * Validate. 145 134 */ 146 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 147 if ( !pFastInt 148 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC) 149 { 150 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt)); 151 return VERR_INVALID_PARAMETER; 152 } 135 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 136 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 137 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 153 138 154 ExReleaseFastMutex(&p FastInt->Mutex);139 ExReleaseFastMutex(&pThis->Mutex); 155 140 return VINF_SUCCESS; 156 141 } -
trunk/src/VBox/Runtime/r0drv/os2/semfastmutex-r0drv-os2.cpp
r8245 r25722 58 58 59 59 60 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem)60 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx) 61 61 { 62 62 AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *)); 63 AssertPtrReturn(p MutexSem, VERR_INVALID_POINTER);63 AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER); 64 64 65 PRTSEMFASTMUTEXINTERNAL p FastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));66 if (p FastInt)65 PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis)); 66 if (pThis) 67 67 { 68 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC; 69 KernAllocMutexLock(&pFastInt->Mtx); 70 *pMutexSem = pFastInt; 68 pThis->u32Magic = RTSEMFASTMUTEX_MAGIC; 69 KernAllocMutexLock(&pThis->Mtx); 70 71 *phFastMtx = pThis; 71 72 return VINF_SUCCESS; 72 73 } … … 75 76 76 77 77 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)78 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx) 78 79 { 79 if (MutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */ 80 return VERR_INVALID_PARAMETER; 81 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 82 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 83 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 84 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 85 VERR_INVALID_PARAMETER); 80 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 81 if (pThis == NIL_RTSEMFASTMUTEX) 82 return VINF_SUCCESS; 83 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 84 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 86 85 87 ASMAtomic XchgU32(&pFastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);88 KernFreeMutexLock(&p FastInt->Mtx);89 RTMemFree(p FastInt);86 ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD); 87 KernFreeMutexLock(&pThis->Mtx); 88 RTMemFree(pThis); 90 89 91 90 return VINF_SUCCESS; … … 93 92 94 93 95 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)94 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx) 96 95 { 97 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 98 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 99 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 100 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 101 VERR_INVALID_PARAMETER); 102 KernRequestExclusiveMutex(&pFastInt->Mtx); 96 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 97 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 98 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 99 100 KernRequestExclusiveMutex(&pThis->Mtx); 103 101 return VINF_SUCCESS; 104 102 } 105 103 106 104 107 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)105 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx) 108 106 { 109 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 110 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 111 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 112 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 113 VERR_INVALID_PARAMETER); 114 KernReleaseExclusiveMutex(&pFastInt->Mtx); 107 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 108 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 109 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 110 111 KernReleaseExclusiveMutex(&pThis->Mtx); 115 112 return VINF_SUCCESS; 116 113 } -
trunk/src/VBox/Runtime/r0drv/solaris/semfastmutex-r0drv-solaris.c
r22073 r25722 61 61 62 62 63 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX p MutexSem)63 RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx) 64 64 { 65 65 AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *)); 66 AssertPtrReturn(p MutexSem, VERR_INVALID_POINTER);66 AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER); 67 67 RT_ASSERT_PREEMPTIBLE(); 68 68 69 PRTSEMFASTMUTEXINTERNAL p FastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));70 if (p FastInt)69 PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis)); 70 if (pThis) 71 71 { 72 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC; 73 rw_init (&pFastInt->Mtx, "RWLOCK", RW_DRIVER, NULL); 74 *pMutexSem = pFastInt; 72 pThis->u32Magic = RTSEMFASTMUTEX_MAGIC; 73 rw_init (&pThis->Mtx, "RWLOCK", RW_DRIVER, NULL); 74 75 *phFastMtx = pThis; 75 76 return VINF_SUCCESS; 76 77 } … … 79 80 80 81 81 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)82 RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx) 82 83 { 83 if (MutexSem == NIL_RTSEMFASTMUTEX) 84 return VERR_INVALID_PARAMETER; 85 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 86 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 87 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 88 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 89 VERR_INVALID_PARAMETER); 84 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 85 if (pThis == NIL_RTSEMFASTMUTEX) 86 return VINF_SUCCESS; 87 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 88 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 90 89 RT_ASSERT_INTS_ON(); 91 90 92 ASMAtomicXchgU32(&p FastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);93 rw_destroy(&p FastInt->Mtx);94 RTMemFree(p FastInt);91 ASMAtomicXchgU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD); 92 rw_destroy(&pThis->Mtx); 93 RTMemFree(pThis); 95 94 96 95 return VINF_SUCCESS; … … 98 97 99 98 100 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)99 RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx) 101 100 { 102 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 103 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 104 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 105 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 106 VERR_INVALID_PARAMETER); 101 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 102 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 103 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 107 104 RT_ASSERT_PREEMPTIBLE(); 108 105 109 rw_enter(&p FastInt->Mtx, RW_WRITER);106 rw_enter(&pThis->Mtx, RW_WRITER); 110 107 return VINF_SUCCESS; 111 108 } 112 109 113 110 114 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)111 RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx) 115 112 { 116 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem; 117 AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER); 118 AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC, 119 ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt), 120 VERR_INVALID_PARAMETER); 113 PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx; 114 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 115 AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE); 121 116 RT_ASSERT_INTS_ON(); 122 117 123 rw_exit(&p FastInt->Mtx);118 rw_exit(&pThis->Mtx); 124 119 return VINF_SUCCESS; 125 120 }
Note:
See TracChangeset
for help on using the changeset viewer.