Changeset 25624 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Jan 3, 2010 3:23:27 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56315
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/semmutex-win.cpp
r25618 r25624 56 56 { 57 57 /** Magic value (RTSEMMUTEX_MAGIC). */ 58 uint32_t u32Magic; 58 uint32_t u32Magic; 59 /** Recursion count. */ 60 uint32_t volatile cRecursions; 61 /** The owner thread. */ 62 RTNATIVETHREAD volatile hNativeOwner; 59 63 /** The mutex handle. */ 60 HANDLE hMtx;64 HANDLE hMtx; 61 65 #ifdef RTSEMMUTEX_STRICT 62 66 /** Lock validator record associated with this mutex. */ 63 RTLOCKVALRECEXCL ValidatorRec;67 RTLOCKVALRECEXCL ValidatorRec; 64 68 #endif 65 69 }; … … 84 88 if (pThis) 85 89 { 86 pThis->u32Magic = RTSEMMUTEX_MAGIC; 87 pThis->hMtx = hMtx; 90 pThis->u32Magic = RTSEMMUTEX_MAGIC; 91 pThis->hMtx = hMtx; 92 pThis->hNativeOwner = NIL_RTNATIVETHREAD; 93 pThis->cRecursions = 0; 88 94 #ifdef RTSEMMUTEX_STRICT 89 95 RTLockValidatorRecExclInit(&pThis->ValidatorRec, NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_NONE, "RTSemMutex", pThis); … … 152 158 153 159 /* 160 * Check for recursive entry. 161 */ 162 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 163 RTNATIVETHREAD hNativeOwner; 164 ASMAtomicReadHandle(&pThis->hNativeOwner, hNativeOwner); 165 if (hNativeOwner == hNativeSelf) 166 { 167 #ifdef RTSEMMUTEX_STRICT 168 int rc9 = RTLockValidatorRecExclRecursion(&pThis->ValidatorRec, pSrcPos); 169 if (RT_FAILURE(rc9)) 170 return rc9; 171 #endif 172 ASMAtomicIncU32(&pThis->cRecursions); 173 return VINF_SUCCESS; 174 } 175 176 /* 154 177 * Lock mutex semaphore. 155 178 */ 156 RTTHREAD hThreadSelf = NIL_RTTHREAD;179 RTTHREAD hThreadSelf = NIL_RTTHREAD; 157 180 if (cMillies > 0) 158 181 { … … 175 198 case WAIT_OBJECT_0: 176 199 #ifdef RTSEMMUTEX_STRICT 177 RTLockValidatorRecExclSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos, false /* we don't know */); 178 #endif 179 /** @todo record who owns this thing and avoid kernel calls during recursion. */ 200 RTLockValidatorRecExclSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true); 201 #endif 202 ASMAtomicWriteHandle(&pThis->hNativeOwner, hNativeSelf); 203 ASMAtomicWriteU32(&pThis->cRecursions, 1); 180 204 return VINF_SUCCESS; 181 205 … … 224 248 AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 225 249 250 /* 251 * Check ownership and recursions. 252 */ 253 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 254 RTNATIVETHREAD hNativeOwner; 255 ASMAtomicReadHandle(&pThis->hNativeOwner, hNativeOwner); 256 if (RT_UNLIKELY(hNativeOwner != hNativeSelf)) 257 { 258 AssertMsgFailed(("Not owner of mutex %p!! hNativeSelf=%RTntrd Owner=%RTntrd cRecursions=%d\n", 259 pThis, hNativeSelf, hNativeOwner, pThis->cRecursions)); 260 return VERR_NOT_OWNER; 261 } 262 if (pThis->cRecursions > 1) 263 { 264 #ifdef RTSEMMUTEX_STRICT 265 int rc9 = RTLockValidatorRecExclUnwind(&pThis->ValidatorRec); 266 if (RT_FAILURE(rc9)) 267 return rc9; 268 #endif 269 ASMAtomicDecU32(&pThis->cRecursions); 270 return VINF_SUCCESS; 271 } 272 273 /* 274 * Unlock mutex semaphore. 275 */ 226 276 #ifdef RTSEMMUTEX_STRICT 227 277 int rc9 = RTLockValidatorRecExclReleaseOwner(&pThis->ValidatorRec, false); … … 229 279 return rc9; 230 280 #endif 231 232 /* 233 * Unlock mutex semaphore. 234 */ 281 ASMAtomicWriteU32(&pThis->cRecursions, 0); 282 ASMAtomicWriteHandle(&pThis->hNativeOwner, NIL_RTNATIVETHREAD); 283 235 284 if (ReleaseMutex(pThis->hMtx)) 236 285 return VINF_SUCCESS; 286 237 287 int rc = RTErrConvertFromWin32(GetLastError()); 238 288 AssertMsgFailed(("%p/%p, rc=%Rrc lasterr=%d\n", pThis, pThis->hMtx, rc, GetLastError())); … … 240 290 } 241 291 292 293 RTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutex) 294 { 295 /* 296 * Validate. 297 */ 298 RTSEMMUTEXINTERNAL *pThis = hMutex; 299 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 300 AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 301 302 RTNATIVETHREAD hNativeOwner; 303 ASMAtomicReadHandle(&pThis->hNativeOwner, hNativeOwner); 304 return hNativeOwner == NIL_RTNATIVETHREAD; 305 } 306
Note:
See TracChangeset
for help on using the changeset viewer.