- Timestamp:
- Sep 10, 2008 5:18:38 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 36345
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMInternal.h
r11261 r12324 246 246 /** The VM pointer. */ 247 247 PVMR3 pVM; 248 /** The event semaphore the thread blocks on . */248 /** The event semaphore the thread blocks on when not running. */ 249 249 RTSEMEVENTMULTI BlockEvent; 250 /** The event semaphore the thread sleeps on while running. */ 251 RTSEMEVENTMULTI SleepEvent; 250 252 /** Pointer to the next thread. */ 251 253 R3PTRTYPE(struct PDMTHREAD *) pNext; -
trunk/src/VBox/VMM/PDMThread.cpp
r8155 r12324 62 62 static DECLCALLBACK(int) pdmR3ThreadWakeUp(PPDMTHREAD pThread) 63 63 { 64 RTSemEventMultiSignal(pThread->Internal.s.SleepEvent); 65 64 66 int rc; 65 67 switch (pThread->Internal.s.enmType) … … 142 144 if (RT_SUCCESS(rc)) 143 145 { 144 /* 145 * Create the thread and wait for it to initialize. 146 * The newly created thread will set the PDMTHREAD::Thread member. 147 */ 148 RTTHREAD Thread; 149 rc = RTThreadCreate(&Thread, pdmR3ThreadMain, pThread, cbStack, enmType, RTTHREADFLAGS_WAITABLE, pszName); 146 rc = RTSemEventMultiCreate(&pThread->Internal.s.SleepEvent); 150 147 if (RT_SUCCESS(rc)) 151 148 { 152 rc = RTThreadUserWait(Thread, 60*1000); 153 if ( RT_SUCCESS(rc) 154 && pThread->enmState != PDMTHREADSTATE_SUSPENDED) 155 rc = VERR_INTERNAL_ERROR; 149 /* 150 * Create the thread and wait for it to initialize. 151 * The newly created thread will set the PDMTHREAD::Thread member. 152 */ 153 RTTHREAD Thread; 154 rc = RTThreadCreate(&Thread, pdmR3ThreadMain, pThread, cbStack, enmType, RTTHREADFLAGS_WAITABLE, pszName); 156 155 if (RT_SUCCESS(rc)) 157 156 { 158 /* 159 * Insert it into the thread list. 160 */ 161 pThread->Internal.s.pNext = NULL; 162 if (pVM->pdm.s.pThreadsTail) 163 pVM->pdm.s.pThreadsTail->Internal.s.pNext = pThread; 164 else 165 pVM->pdm.s.pThreads = pThread; 166 pVM->pdm.s.pThreadsTail = pThread; 167 168 rc = RTThreadUserReset(Thread); 169 AssertRC(rc); 170 return rc; 157 rc = RTThreadUserWait(Thread, 60*1000); 158 if ( RT_SUCCESS(rc) 159 && pThread->enmState != PDMTHREADSTATE_SUSPENDED) 160 rc = VERR_INTERNAL_ERROR; 161 if (RT_SUCCESS(rc)) 162 { 163 /* 164 * Insert it into the thread list. 165 */ 166 pThread->Internal.s.pNext = NULL; 167 if (pVM->pdm.s.pThreadsTail) 168 pVM->pdm.s.pThreadsTail->Internal.s.pNext = pThread; 169 else 170 pVM->pdm.s.pThreads = pThread; 171 pVM->pdm.s.pThreadsTail = pThread; 172 173 rc = RTThreadUserReset(Thread); 174 AssertRC(rc); 175 return rc; 176 } 177 178 /* bailout */ 179 RTThreadWait(Thread, 60*1000, NULL); 171 180 } 172 173 /* bailout */ 174 RTThreadWait(Thread, 60*1000, NULL); 181 RTSemEventMultiDestroy(pThread->Internal.s.SleepEvent); 182 pThread->Internal.s.SleepEvent = NIL_RTSEMEVENTMULTI; 175 183 } 176 184 RTSemEventMultiDestroy(pThread->Internal.s.BlockEvent); … … 435 443 pThread->Internal.s.pNext = NULL; 436 444 437 /* free it */ 445 /* free the resources */ 446 RTSemEventMultiDestroy(pThread->Internal.s.BlockEvent); 447 pThread->Internal.s.BlockEvent = NIL_RTSEMEVENTMULTI; 448 449 RTSemEventMultiDestroy(pThread->Internal.s.SleepEvent); 450 pThread->Internal.s.SleepEvent = NIL_RTSEMEVENTMULTI; 451 438 452 MMR3HeapFree(pThread); 439 453 } … … 677 691 pdmR3ThreadBailMeOut(pThread); 678 692 return rc; 693 } 694 695 696 /** 697 * Called by the PDM thread instead of RTThreadSleep. 698 * 699 * The difference is that the sleep will be interrupted on state change. The 700 * thread must be in the running state, otherwise it will return immediately. 701 * 702 * @returns VBox status code. 703 * @retval VINF_SUCCESS on success or state change. 704 * @retval VERR_INTERRUPTED on signal or APC. 705 * 706 * @param pThread The PDM thread. 707 * @param cMillies The number of milliseconds to sleep. 708 */ 709 PDMR3DECL(int) PDMR3ThreadSleep(PPDMTHREAD pThread, unsigned cMillies) 710 { 711 /* 712 * Assert sanity. 713 */ 714 AssertReturn(pThread->enmState > PDMTHREADSTATE_INVALID && pThread->enmState < PDMTHREADSTATE_TERMINATED, VERR_INTERNAL_ERROR); 715 AssertReturn(pThread->Thread == RTThreadSelf(), VERR_INTERNAL_ERROR); 716 717 /* 718 * Reset the event semaphore, check the state and sleep. 719 */ 720 RTSemEventMultiReset(pThread->Internal.s.SleepEvent); 721 if (pThread->enmState != PDMTHREADSTATE_RUNNING) 722 return VINF_SUCCESS; 723 return RTSemEventMultiWaitNoResume(pThread->Internal.s.SleepEvent, cMillies); 679 724 } 680 725
Note:
See TracChangeset
for help on using the changeset viewer.