Changeset 25722 in vbox for trunk/src/VBox/Runtime/r0drv/linux
- Timestamp:
- Jan 11, 2010 2:22:03 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.