Changeset 25648 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Jan 5, 2010 2:32:58 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime/r3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/linux/semeventmulti-linux.cpp
r25640 r25648 52 52 *******************************************************************************/ 53 53 #include <iprt/semaphore.h> 54 #include "internal/iprt.h" 55 54 56 #include <iprt/assert.h> 55 #include <iprt/alloc.h>56 57 #include <iprt/asm.h> 57 58 #include <iprt/err.h> 59 #include <iprt/lockvalidator.h> 60 #include <iprt/mem.h> 58 61 #include <iprt/time.h> 59 62 #include "internal/magics.h" 63 #include "internal/strict.h" 64 60 65 61 66 #include <errno.h> … … 82 87 { 83 88 /** Magic value. */ 84 intptr_t volatile iMagic;89 uint32_t volatile u32Magic; 85 90 /** The futex state variable. 86 91 * -1 means signaled. … … 89 94 */ 90 95 int32_t volatile iState; 96 #ifdef RTSEMEVENTMULTI_STRICT 97 /** Signallers. */ 98 RTLOCKVALRECSHRD Signallers; 99 /** Indicates that lock validation should be performed. */ 100 bool volatile fEverHadSignallers; 101 #endif 91 102 }; 92 103 … … 116 127 if (pThis) 117 128 { 118 pThis->iMagic = RTSEMEVENTMULTI_MAGIC; 119 pThis->iState = 0; 129 pThis->u32Magic = RTSEMEVENTMULTI_MAGIC; 130 pThis->iState = 0; 131 #ifdef RTSEMEVENTMULTI_STRICT 132 RTLockValidatorRecSharedInit(&pThis->Signallers, 133 NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_ANY, 134 "RTSemEventMulti", pThis, true /*fSignaller*/); 135 pThis->fEverHadSignallers = false; 136 #endif 120 137 *pEventMultiSem = pThis; 121 138 return VINF_SUCCESS; … … 131 148 */ 132 149 struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem; 133 AssertReturn(VALID_PTR(pThis) && pThis-> iMagic == RTSEMEVENTMULTI_MAGIC,150 AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, 134 151 VERR_INVALID_HANDLE); 135 152 … … 137 154 * Invalidate the semaphore and wake up anyone waiting on it. 138 155 */ 139 ASMAtomicWriteSize(&pThis-> iMagic, RTSEMEVENTMULTI_MAGIC + 1);156 ASMAtomicWriteSize(&pThis->u32Magic, RTSEMEVENTMULTI_MAGIC + 1); 140 157 if (ASMAtomicXchgS32(&pThis->iState, -1) == 1) 141 158 { … … 147 164 * Free the semaphore memory and be gone. 148 165 */ 166 #ifdef RTSEMEVENTMULTI_STRICT 167 RTLockValidatorRecSharedDelete(&pThis->Signallers); 168 #endif 149 169 RTMemFree(pThis); 150 170 return VINF_SUCCESS; … … 158 178 */ 159 179 struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem; 160 AssertReturn(VALID_PTR(pThis) && pThis-> iMagic == RTSEMEVENTMULTI_MAGIC,180 AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, 161 181 VERR_INVALID_HANDLE); 182 183 #ifdef RTSEMEVENTMULTI_STRICT 184 if (pThis->fEverHadSignallers) 185 { 186 int rc9 = RTLockValidatorRecSharedCheckSignaller(&pThis->Signallers, NIL_RTTHREAD); 187 if (RT_FAILURE(rc9)) 188 return rc9; 189 } 190 #endif 191 192 162 193 /* 163 194 * Signal it. … … 181 212 */ 182 213 struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem; 183 AssertReturn(VALID_PTR(pThis) && pThis-> iMagic == RTSEMEVENTMULTI_MAGIC,214 AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, 184 215 VERR_INVALID_HANDLE); 185 216 #ifdef RT_STRICT … … 198 229 static int rtSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies, bool fAutoResume) 199 230 { 231 PCRTLOCKVALSRCPOS pSrcPos = NULL; 232 200 233 /* 201 234 * Validate input. 202 235 */ 203 236 struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem; 204 AssertReturn(VALID_PTR(pThis) && pThis-> iMagic == RTSEMEVENTMULTI_MAGIC,237 AssertReturn(VALID_PTR(pThis) && pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, 205 238 VERR_INVALID_HANDLE); 206 239 … … 221 254 if (cMillies != RT_INDEFINITE_WAIT) 222 255 { 256 /* If the timeout is zero, then we're done. */ 223 257 if (!cMillies) 224 258 return VERR_TIMEOUT; … … 232 266 * The wait loop. 233 267 */ 268 #ifdef RTSEMEVENTMULTI_STRICT 269 RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt(); 270 #else 271 RTTHREAD hThreadSelf = RTThreadSelf(); 272 #endif 234 273 for (unsigned i = 0;; i++) 235 274 { … … 252 291 ts.tv_nsec = i64Diff % 1000000000; 253 292 } 293 #ifdef RTSEMEVENTMULTI_STRICT 294 if (pThis->fEverHadSignallers) 295 { 296 int rc9 = RTLockValidatorRecSharedCheckBlocking(&pThis->Signallers, hThreadSelf, pSrcPos, false, 297 RTTHREADSTATE_EVENT_MULTI, true); 298 if (RT_FAILURE(rc9)) 299 return rc9; 300 } 301 #endif 302 RTThreadBlocking(hThreadSelf, RTTHREADSTATE_EVENT_MULTI, true); 254 303 long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 1, pTimeout, NULL, 0); 255 if (RT_UNLIKELY(pThis->iMagic != RTSEMEVENTMULTI_MAGIC)) 304 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_EVENT_MULTI); 305 if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC)) 256 306 return VERR_SEM_DESTROYED; 257 307 if (rc == 0) … … 263 313 if (rc == -ETIMEDOUT) 264 314 { 265 /** @something is broken here. shows up every now and again in the ata code. Should try to run the timeout against RTTimeMilliTS to check that it's doing the right thing... */ 315 /** @todo something is broken here. shows up every now and again in the ata 316 * code. Should try to run the timeout against RTTimeMilliTS to 317 * check that it's doing the right thing... */ 266 318 Assert(pTimeout); 267 319 return VERR_TIMEOUT; … … 303 355 RTDECL(void) RTSemEventMultiSetSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread) 304 356 { 305 /** @todo implement RTSemEventMultiSetSignaller on OS/2 */ 357 #ifdef RTSEMEVENTMULTI_STRICT 358 struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem; 359 AssertPtrReturnVoid(pThis); 360 AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC); 361 362 ASMAtomicWriteBool(&pThis->fEverHadSignallers, true); 363 RTLockValidatorRecSharedResetOwner(&pThis->Signallers, hThread, NULL); 364 #endif 306 365 } 307 366 … … 309 368 RTDECL(void) RTSemEventMultiAddSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread) 310 369 { 370 #ifdef RTSEMEVENTMULTI_STRICT 371 struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem; 372 AssertPtrReturnVoid(pThis); 373 AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC); 374 375 ASMAtomicWriteBool(&pThis->fEverHadSignallers, true); 376 RTLockValidatorRecSharedAddOwner(&pThis->Signallers, hThread, NULL); 377 #endif 311 378 } 312 379 … … 314 381 RTDECL(void) RTSemEventMultiRemoveSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread) 315 382 { 383 #ifdef RTSEMEVENTMULTI_STRICT 384 struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem; 385 AssertPtrReturnVoid(pThis); 386 AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC); 387 388 RTLockValidatorRecSharedRemoveOwner(&pThis->Signallers, hThread); 389 #endif 316 390 } 317 391 -
trunk/src/VBox/Runtime/r3/posix/semeventmulti-posix.cpp
r25640 r25648 124 124 RTLockValidatorRecSharedInit(&pThis->Signallers, 125 125 NIL_RTLOCKVALIDATORCLASS, RTLOCKVALIDATOR_SUB_CLASS_ANY, 126 "RTSemEvent ", pThis, true /*fSignaller*/);126 "RTSemEventMulti", pThis, true /*fSignaller*/); 127 127 pThis->fEverHadSignallers = false; 128 128 #endif
Note:
See TracChangeset
for help on using the changeset viewer.