Changeset 25624 in vbox
- Timestamp:
- Jan 3, 2010 3:23:27 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
include/iprt/semaphore.h (modified) (1 diff)
-
src/VBox/Runtime/r3/linux/semmutex-linux.cpp (modified) (1 diff)
-
src/VBox/Runtime/r3/os2/sems-os2.cpp (modified) (1 diff)
-
src/VBox/Runtime/r3/posix/semmutex-posix.cpp (modified) (2 diffs)
-
src/VBox/Runtime/r3/win/semmutex-win.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/semaphore.h
r25620 r25624 281 281 */ 282 282 RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem); 283 284 /** 285 * Checks if the mutex semaphore is owned or not. 286 * 287 * @returns true if owned, false if not. 288 * @param hMutex The mutex semaphore. 289 */ 290 RTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutex); 283 291 284 292 /* Strict build: Remap the two request calls to the debug versions. */ -
trunk/src/VBox/Runtime/r3/linux/semmutex-linux.cpp
r25618 r25624 409 409 } 410 410 411 412 RTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutex) 413 { 414 /* 415 * Validate. 416 */ 417 RTSEMMUTEXINTERNAL *pThis = hMutex; 418 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 419 AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 420 421 return pThis->Owner != (pthread_t)~0; 422 } 423 -
trunk/src/VBox/Runtime/r3/os2/sems-os2.cpp
r25378 r25624 279 279 280 280 281 281 RTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutex); 282 { 283 /* 284 * Unlock mutex semaphore. 285 */ 286 PID pid; 287 TID tid; 288 ULONG cRecursions; 289 int rc = DosQueryMutexSem(SEM2HND(MutexSem), &pid, &tid, &cRecursions); 290 if (!rc) 291 return cRecursions != 0; 292 AssertMsgFailed(("DosQueryMutexSem %p failed, rc=%d\n", MutexSem, rc)); 293 return rc == ERROR_SEM_OWNER_DIED; 294 } 295 296 297 -
trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp
r25618 r25624 331 331 */ 332 332 pThis->Owner = (pthread_t)-1; 333 ASMAtomic XchgU32(&pThis->cNesting, 0);333 ASMAtomicWriteU32(&pThis->cNesting, 0); 334 334 335 335 /* … … 346 346 } 347 347 348 349 RTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutex) 350 { 351 /* 352 * Validate. 353 */ 354 RTSEMMUTEXINTERNAL *pThis = hMutex; 355 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 356 AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE); 357 358 return pThis->Owner != (pthread_t)-1; 359 } 360 -
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.

