- Timestamp:
- Jul 21, 2008 10:19:26 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/thread.cpp
r8679 r10792 256 256 { 257 257 rtThreadInsert(pThread, NativeThread); 258 pThread->enmState = RTTHREADSTATE_RUNNING;258 ASMAtomicWriteSize(&pThread->enmState, RTTHREADSTATE_RUNNING); 259 259 rtThreadRelease(pThread); 260 260 } … … 370 370 371 371 /* 372 * Before inserting we must check if there is a thread with this id 373 * in the tree already. We're racing parent and child on insert here 374 * so that the handle is valid in both ends when they return / start. 372 * Do not insert a terminated thread. 375 373 * 376 * If it's not ourself we find, it's a dead alien thread and we will 377 * unlink it from the tree. Alien threads will be released at this point. 378 */ 379 PRTTHREADINT pThreadOther = (PRTTHREADINT)RTAvlPVGet(&g_ThreadTree, (void *)NativeThread); 380 if (pThreadOther != pThread) 381 { 382 /* remove dead alien if any */ 383 if (pThreadOther) 374 * This may happen if the thread finishes before the RTThreadCreate call 375 * gets this far. Since the OS may quickly reuse the native thread ID 376 * it should not be reinserted at this point. 377 */ 378 if (pThread->enmState != RTTHREADSTATE_TERMINATED) 379 { 380 /* 381 * Before inserting we must check if there is a thread with this id 382 * in the tree already. We're racing parent and child on insert here 383 * so that the handle is valid in both ends when they return / start. 384 * 385 * If it's not ourself we find, it's a dead alien thread and we will 386 * unlink it from the tree. Alien threads will be released at this point. 387 */ 388 PRTTHREADINT pThreadOther = (PRTTHREADINT)RTAvlPVGet(&g_ThreadTree, (void *)NativeThread); 389 if (pThreadOther != pThread) 384 390 { 385 Assert(pThreadOther->fIntFlags & RTTHREADINT_FLAGS_ALIEN); 386 ASMAtomicBitClear(&pThread->fIntFlags, RTTHREADINT_FLAG_IN_TREE_BIT); 387 rtThreadRemoveLocked(pThreadOther); 388 if (pThreadOther->fIntFlags & RTTHREADINT_FLAGS_ALIEN) 389 rtThreadRelease(pThreadOther); 391 /* remove dead alien if any */ 392 if (pThreadOther) 393 { 394 AssertMsg(pThreadOther->fIntFlags & RTTHREADINT_FLAGS_ALIEN, ("%p:%s; %p:%s\n", pThread, pThread->szName, pThreadOther, pThreadOther->szName)); 395 ASMAtomicBitClear(&pThread->fIntFlags, RTTHREADINT_FLAG_IN_TREE_BIT); 396 rtThreadRemoveLocked(pThreadOther); 397 if (pThreadOther->fIntFlags & RTTHREADINT_FLAGS_ALIEN) 398 rtThreadRelease(pThreadOther); 399 } 400 401 /* insert the thread */ 402 ASMAtomicWritePtr(&pThread->Core.Key, (void *)NativeThread); 403 bool fRc = RTAvlPVInsert(&g_ThreadTree, &pThread->Core); 404 ASMAtomicOrU32(&pThread->fIntFlags, RTTHREADINT_FLAG_IN_TREE); 405 406 AssertReleaseMsg(fRc, ("Lock problem? %p (%RTnthrd) %s\n", pThread, NativeThread, pThread->szName)); 407 NOREF(fRc); 390 408 } 391 392 /* insert the thread */393 pThread->Core.Key = (void *)NativeThread;394 bool fRc = RTAvlPVInsert(&g_ThreadTree, &pThread->Core);395 ASMAtomicOrU32(&pThread->fIntFlags, RTTHREADINT_FLAG_IN_TREE);396 397 AssertReleaseMsg(fRc, ("Lock problem? %p (%RTnthrd) %s\n", pThread, NativeThread, pThread->szName));398 NOREF(fRc);399 409 } 400 410 … … 544 554 * Free resources. 545 555 */ 546 pThread->Core.Key = (void *)NIL_RTTHREAD;556 ASMAtomicWritePtr(&pThread->Core.Key, (void *)NIL_RTTHREAD); 547 557 pThread->enmType = RTTHREADTYPE_INVALID; 548 558 RTSemEventMultiDestroy(pThread->EventUser); … … 579 589 */ 580 590 pThread->rc = rc; 581 ASMAtomic XchgSize(&pThread->enmState, RTTHREADSTATE_TERMINATED);591 ASMAtomicWriteSize(&pThread->enmState, RTTHREADSTATE_TERMINATED); 582 592 ASMAtomicOrU32(&pThread->fIntFlags, RTTHREADINT_FLAGS_TERMINATED); 583 593 if (pThread->EventTerminated != NIL_RTSEMEVENTMULTI) … … 625 635 * Call thread function and terminate when it returns. 626 636 */ 627 pThread->enmState = RTTHREADSTATE_RUNNING;637 ASMAtomicWriteSize(&pThread->enmState, RTTHREADSTATE_RUNNING); 628 638 rc = pThread->pfnThread(pThread, pThread->pvUser); 629 639 … … 1367 1377 pThread->uBlockLine = uLine; 1368 1378 pThread->uBlockId = uId; 1369 ASMAtomic XchgSize(&pThread->enmState, enmState);1379 ASMAtomicWriteSize(&pThread->enmState, enmState); 1370 1380 1371 1381 /* … … 1452 1462 { 1453 1463 if (pThread && pThread->enmState == enmCurState) 1454 ASMAtomic XchgSize(&pThread->enmState, RTTHREADSTATE_RUNNING);1464 ASMAtomicWriteSize(&pThread->enmState, RTTHREADSTATE_RUNNING); 1455 1465 } 1456 1466
Note:
See TracChangeset
for help on using the changeset viewer.