- Timestamp:
- Oct 13, 2010 10:07:18 AM (14 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r33047 r33092 1640 1640 generic/RTAssertShouldPanic-generic.cpp \ 1641 1641 generic/RTLogWriteStdOut-stub-generic.cpp \ 1642 generic/RTSemEventMultiWait-2-ex-generic.cpp \ 1643 generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp \ 1642 1644 generic/RTTimerCreate-generic.cpp \ 1643 1645 generic/mppresent-generic.cpp \ -
trunk/src/VBox/Runtime/r0drv/solaris/semeventmulti-r0drv-solaris.c
r33070 r33092 278 278 } 279 279 280 #if 0 /* NEW_STUFF - not working yet :-)*/280 /* -------- Move to header ---------- */ 281 281 282 282 typedef struct RTR0SEMSOLWAIT … … 307 307 /** The thread to wake up. */ 308 308 kthread_t *pThread; 309 /** Cylic timer ID (used by the timeout callback). */ 310 cyclic_id_t idCy; 309 311 } RTR0SEMSOLWAIT; 312 /** Pointer to a solaris semaphore wait structure. */ 310 313 typedef RTR0SEMSOLWAIT *PRTR0SEMSOLWAIT; 311 314 … … 398 401 pWait->fInterruptible = !!(fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE); 399 402 pWait->pThread = curthread; 403 pWait->idCy = CYCLIC_NONE; 400 404 401 405 return VINF_SUCCESS; … … 415 419 if (VALID_PTR(pThread)) /* paranoia */ 416 420 { 421 /* Note: Trying to take the cpu_lock here doesn't work. */ 422 if (mutex_owner(&cpu_lock) == curthread) 423 { 424 cyclic_remove(pWait->idCy); 425 pWait->idCy = CYCLIC_NONE; 426 } 417 427 ASMAtomicWriteBool(&pWait->fTimedOut, true); 418 428 setrun(pThread); … … 455 465 cyc_time_t Cyt; 456 466 Cyt.cyt_when = pWait->uNsAbsTimeout; 457 Cyt.cyt_interval = 0;467 Cyt.cyt_interval = UINT64_C(1000000000) * 60; 458 468 459 469 mutex_enter(&cpu_lock); 460 cyclic_id_tidCy = cyclic_add(&Cyh, &Cyt);470 pWait->idCy = cyclic_add(&Cyh, &Cyt); 461 471 mutex_exit(&cpu_lock); 462 472 … … 467 477 468 478 mutex_enter(&cpu_lock); 469 cyclic_remove(idCy); 479 if (pWait->idCy != CYCLIC_NONE) 480 { 481 cyclic_remove(pWait->idCy); 482 pWait->idCy = CYCLIC_NONE; 483 } 470 484 mutex_exit(&cpu_lock); 471 485 } … … 532 546 } 533 547 548 /* -------- End ---------- */ 534 549 535 550 … … 570 585 */ 571 586 RTR0SEMSOLWAIT Wait; 572 r tR0SemSolWaitInit(&Wait, fFlags, uTimeout);573 for (;;)587 rc = rtR0SemSolWaitInit(&Wait, fFlags, uTimeout); 588 if (RT_SUCCESS(rc)) 574 589 { 575 /* The destruction test. */ 576 if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC)) 577 rc = VERR_SEM_DESTROYED; 578 else 590 for (;;) 579 591 { 580 /* Check the exit conditions. */592 /* The destruction test. */ 581 593 if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC)) 582 594 rc = VERR_SEM_DESTROYED; 583 else if (ASMAtomicUoReadU32(&pThis->fStateAndGen) != fOrgStateAndGen)584 rc = VINF_SUCCESS;585 else if (rtR0SemSolWaitHasTimedOut(&Wait))586 rc = VERR_TIMEOUT;587 else if (rtR0SemSolWaitWasInterrupted(&Wait))588 rc = VERR_INTERRUPTED;589 595 else 590 596 { 591 /* Do the wait and then recheck the conditions. */ 592 rtR0SemSolWaitDoIt(&Wait, &pThis->Cnd, &pThis->Mtx); 593 continue; 597 /* Check the exit conditions. */ 598 if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC)) 599 rc = VERR_SEM_DESTROYED; 600 else if (ASMAtomicUoReadU32(&pThis->fStateAndGen) != fOrgStateAndGen) 601 rc = VINF_SUCCESS; 602 else if (rtR0SemSolWaitHasTimedOut(&Wait)) 603 rc = VERR_TIMEOUT; 604 else if (rtR0SemSolWaitWasInterrupted(&Wait)) 605 rc = VERR_INTERRUPTED; 606 else 607 { 608 /* Do the wait and then recheck the conditions. */ 609 rtR0SemSolWaitDoIt(&Wait, &pThis->Cnd, &pThis->Mtx); 610 continue; 611 } 594 612 } 613 break; 595 614 } 596 break;615 rtR0SemSolWaitDelete(&Wait); 597 616 } 598 rtR0SemSolWaitDelete(&Wait);599 617 } 600 618 … … 626 644 627 645 628 #include "../../generic/RTSemEventMultiWait-2-ex-generic.cpp"629 #include "../../generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp"630 631 #else /* OLD_STUFF */632 633 /**634 * Translate milliseconds into ticks and go to sleep using the right method.635 *636 * @retval >0 on normal or spurious wake-up.637 * @retval -1 on timeout.638 * @retval 0 on signal.639 */640 static int rtSemEventMultiWaitWorker(PRTSEMEVENTMULTIINTERNAL pThis, RTMSINTERVAL cMillies, bool fInterruptible)641 {642 int rc;643 if (cMillies != RT_INDEFINITE_WAIT)644 {645 clock_t cTicks = drv_usectohz((clock_t)(cMillies * 1000L));646 clock_t cTimeout = ddi_get_lbolt();647 cTimeout += cTicks;648 if (fInterruptible)649 rc = cv_timedwait_sig(&pThis->Cnd, &pThis->Mtx, cTimeout);650 else651 rc = cv_timedwait(&pThis->Cnd, &pThis->Mtx, cTimeout);652 }653 else654 {655 if (fInterruptible)656 rc = cv_wait_sig(&pThis->Cnd, &pThis->Mtx);657 else658 {659 cv_wait(&pThis->Cnd, &pThis->Mtx);660 rc = 1;661 }662 }663 return rc;664 }665 666 667 static int rtSemEventMultiWait(RTSEMEVENTMULTI hEventMultiSem, RTMSINTERVAL cMillies, bool fInterruptible)668 {669 int rc;670 PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;671 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);672 AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,673 ("pThis=%p u32Magic=%#x\n", pThis, pThis->u32Magic),674 VERR_INVALID_HANDLE);675 rtR0SemEventMultiSolRetain(pThis);676 if (cMillies)677 RT_ASSERT_PREEMPTIBLE();678 679 mutex_enter(&pThis->Mtx);680 Assert(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC);681 682 if (pThis->fStateAndGen & RTSEMEVENTMULTISOL_STATE_MASK)683 rc = VINF_SUCCESS;684 else if (!cMillies)685 rc = VERR_TIMEOUT;686 else687 {688 /* This loop is only for continuing after a spurious wake-up. */689 for (;;)690 {691 uint32_t const uSignalGenBeforeWait = pThis->fStateAndGen;692 rc = rtSemEventMultiWaitWorker(pThis, cMillies, fInterruptible);693 if (rc > 0)694 {695 if (RT_LIKELY(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC))696 {697 if (pThis->fStateAndGen == uSignalGenBeforeWait)698 continue; /* Spurious wake-up, go back to waiting. */699 700 /* Retured due to call to cv_signal() or cv_broadcast(). */701 rc = VINF_SUCCESS;702 }703 else704 /* We're being destroyed. */705 rc = VERR_SEM_DESTROYED;706 }707 else if (rc == -1)708 /* Returned due to timeout being reached. */709 rc = VERR_TIMEOUT;710 else711 rc = VERR_INTERRUPTED;712 /* Returned due to pending signal. */713 break;714 }715 }716 717 mutex_exit(&pThis->Mtx);718 rtR0SemEventMultiSolRelease(pThis);719 return rc;720 }721 722 723 RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI hEventMultiSem, RTMSINTERVAL cMillies)724 {725 return rtSemEventMultiWait(hEventMultiSem, cMillies, false /* not interruptible */);726 }727 728 729 RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI hEventMultiSem, RTMSINTERVAL cMillies)730 {731 return rtSemEventMultiWait(hEventMultiSem, cMillies, true /* interruptible */);732 }733 734 #endif
Note:
See TracChangeset
for help on using the changeset viewer.