Changeset 25433 in vbox
- Timestamp:
- Dec 16, 2009 2:55:18 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56082
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp
r25378 r25433 69 69 70 70 71 RTDECL(int) 71 RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem) 72 72 { 73 73 Assert(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *)); … … 88 88 89 89 90 RTDECL(int) 90 RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem) 91 91 { 92 92 /* … … 96 96 if (!pMutexInt) 97 97 return VERR_INVALID_PARAMETER; 98 if (pMutexInt->u32Magic != RTSEMMUTEX_MAGIC) 99 { 100 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt->u32Magic, pMutexInt)); 101 return VERR_INVALID_PARAMETER; 102 } 98 AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 103 99 104 100 /* 105 101 * Invalidate it and signal the object just in case. 106 102 */ 107 A SMAtomicIncU32(&pMutexInt->u32Magic);103 AssertReturn(ASMAtomicCmpXchgU32(&pMutexInt->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE); 108 104 RTMemFree(pMutexInt); 109 105 return VINF_SUCCESS; … … 111 107 112 108 113 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies) 109 /** 110 * Internal worker for RTSemMutexRequest and RTSemMutexRequestNoResume 111 * 112 * @returns IPRT status code. 113 * @param MutexSem The mutex handle. 114 * @param cMillies The timeout. 115 * @param fInterruptible Whether it's interruptible 116 * (RTSemMutexRequestNoResume) or not 117 * (RTSemMutexRequest). 118 */ 119 static int rtSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies, BOOLEAN fInterruptible) 114 120 { 115 121 /* … … 119 125 if (!pMutexInt) 120 126 return VERR_INVALID_PARAMETER; 121 if ( !pMutexInt 122 || pMutexInt->u32Magic != RTSEMMUTEX_MAGIC) 123 { 124 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt)); 125 return VERR_INVALID_PARAMETER; 126 } 127 AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 127 128 128 129 /* … … 132 133 AssertMsg(cMillies == RT_INDEFINITE_WAIT, ("timeouts are not supported when using fast mutexes!\n")); 133 134 ExAcquireFastMutex(&pMutexInt->Mutex); 134 #else 135 #else /* !RT_USE_FAST_MUTEX */ 135 136 NTSTATUS rcNt; 136 137 if (cMillies == RT_INDEFINITE_WAIT) 137 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, NULL);138 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, NULL); 138 139 else 139 140 { 140 141 LARGE_INTEGER Timeout; 141 142 Timeout.QuadPart = -(int64_t)cMillies * 10000; 142 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, TRUE, &Timeout);143 rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, &Timeout); 143 144 } 144 145 switch (rcNt) … … 148 149 return VINF_SUCCESS; 149 150 return VERR_SEM_DESTROYED; 151 150 152 case STATUS_ALERTED: 151 return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */152 153 case STATUS_USER_APC: 153 return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */ 154 Assert(fInterruptible); 155 return VERR_INTERRUPTED; 156 154 157 case STATUS_TIMEOUT: 155 158 return VERR_TIMEOUT; 159 156 160 default: 157 161 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p: wait returned %lx!\n", … … 159 163 return VERR_INTERNAL_ERROR; 160 164 } 161 #endif 165 #endif /* !RT_USE_FAST_MUTEX */ 162 166 return VINF_SUCCESS; 163 167 } 164 168 165 169 166 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 170 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies) 171 { 172 return rtSemMutexRequest(MutexSem, cMillies, FALSE /*fInterruptible*/); 173 } 174 175 176 RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 167 177 { 168 178 return RTSemMutexRequest(MutexSem, cMillies); 169 179 } 170 180 171 /** @todo implement the NoResume versions */ 172 173 RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem) 181 182 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies) 183 { 184 return rtSemMutexRequest(MutexSem, cMillies, TRUE /*fInterruptible*/); 185 } 186 187 188 RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX MutexSem, unsigned cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL) 189 { 190 return RTSemMutexRequestNoResume(MutexSem, cMillies); 191 } 192 193 194 RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem) 174 195 { 175 196 /* … … 179 200 if (!pMutexInt) 180 201 return VERR_INVALID_PARAMETER; 181 if ( !pMutexInt 182 || pMutexInt->u32Magic != RTSEMMUTEX_MAGIC) 183 { 184 AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt)); 185 return VERR_INVALID_PARAMETER; 186 } 202 AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 187 203 188 204 /* … … 192 208 ExReleaseFastMutex(&pMutexInt->Mutex); 193 209 #else 194 KeReleaseMutex(&pMutexInt->Mutex, FALSE );210 KeReleaseMutex(&pMutexInt->Mutex, FALSE /*Wait*/); 195 211 #endif 196 212 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.