semeventmulti-r0drv-solaris.c revision b9c00cd9c9b5f409e64bd7782815faa2c5ecd85f
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Multiple Release Event Semaphores, Ring-0 Driver, Solaris.
1cb3b5cc4236e4c4c1d2fc0e35060181ffdc0669vboxsync * Copyright (C) 2006-2010 Oracle Corporation
089c21a647af46044cad04a78cfdcfae814d2105vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
089c21a647af46044cad04a78cfdcfae814d2105vboxsync * available from http://www.virtualbox.org. This file is free software;
089c21a647af46044cad04a78cfdcfae814d2105vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * The contents of this file may alternatively be used under the terms
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * of the Common Development and Distribution License Version 1.0
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution, in which case the provisions of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * CDDL are applicable instead of those of the GPL.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * You may elect to license modified versions of this file under the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * terms and conditions of either the GPL or the CDDL or both.
089c21a647af46044cad04a78cfdcfae814d2105vboxsync/*******************************************************************************
089c21a647af46044cad04a78cfdcfae814d2105vboxsync* Header Files *
089c21a647af46044cad04a78cfdcfae814d2105vboxsync*******************************************************************************/
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync/*******************************************************************************
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync* Defined Constants And Macros *
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync*******************************************************************************/
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync/** @name fStateAndGen values
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync/** The state bit number. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync/** The state mask. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync#define RTSEMEVENTMULTISOL_STATE_MASK RT_BIT_32(RTSEMEVENTMULTISOL_STATE_BIT)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync/** The generation mask. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync#define RTSEMEVENTMULTISOL_GEN_MASK ~RTSEMEVENTMULTISOL_STATE_MASK
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync/** The generation shift. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync/** The initial variable value. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync#define RTSEMEVENTMULTISOL_STATE_GEN_INIT UINT32_C(0xfffffffc)
089c21a647af46044cad04a78cfdcfae814d2105vboxsync/*******************************************************************************
089c21a647af46044cad04a78cfdcfae814d2105vboxsync* Structures and Typedefs *
089c21a647af46044cad04a78cfdcfae814d2105vboxsync*******************************************************************************/
63e576f3c901db19ac9a11f2353025b66a6798eevboxsync * Solaris multiple release event semaphore.
089c21a647af46044cad04a78cfdcfae814d2105vboxsync /** Magic value (RTSEMEVENTMULTI_MAGIC). */
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync /** The number of references. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** The object state bit and generation counter.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * The generation counter is incremented every time the object is
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * signalled. */
089c21a647af46044cad04a78cfdcfae814d2105vboxsync /** The Solaris mutex protecting this structure and pairing up the with the cv. */
089c21a647af46044cad04a78cfdcfae814d2105vboxsync /** The Solaris condition variable. */
089c21a647af46044cad04a78cfdcfae814d2105vboxsync} RTSEMEVENTMULTIINTERNAL, *PRTSEMEVENTMULTIINTERNAL;
ab93606043a9881487aa83be04191d2f4ea24071vboxsyncRTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI phEventMultiSem)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync return RTSemEventMultiCreateEx(phEventMultiSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, NULL);
ab93606043a9881487aa83be04191d2f4ea24071vboxsyncRTDECL(int) RTSemEventMultiCreateEx(PRTSEMEVENTMULTI phEventMultiSem, uint32_t fFlags, RTLOCKVALCLASS hClass,
ab93606043a9881487aa83be04191d2f4ea24071vboxsync const char *pszNameFmt, ...)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync AssertReturn(!(fFlags & ~RTSEMEVENTMULTI_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
ab93606043a9881487aa83be04191d2f4ea24071vboxsync AssertPtrReturn(phEventMultiSem, VERR_INVALID_POINTER);
ab93606043a9881487aa83be04191d2f4ea24071vboxsync AssertCompile(sizeof(RTSEMEVENTMULTIINTERNAL) > sizeof(void *));
a68835e2c9d5426d501f1bc78ff30e8ec5bb12cevboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis));
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync pThis->fStateAndGen = RTSEMEVENTMULTISOL_STATE_GEN_INIT;
249acff39649895e369c7d0c07d3d0adc4e10f38vboxsync mutex_init(&pThis->Mtx, "IPRT Multiple Release Event Semaphore", MUTEX_DRIVER, (void *)ipltospl(DISP_LEVEL));
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Retain a reference to the semaphore.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pThis The semaphore.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncDECLINLINE(void) rtR0SemEventMultiSolRetain(PRTSEMEVENTMULTIINTERNAL pThis)
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync * Destructor that is called when cRefs == 0.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pThis The instance to destroy.
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsyncstatic void rtSemEventMultiDtor(PRTSEMEVENTMULTIINTERNAL pThis)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Release a reference, destroy the thing if necessary.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pThis The semaphore.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncDECLINLINE(void) rtR0SemEventMultiSolRelease(PRTSEMEVENTMULTIINTERNAL pThis)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync if (RT_UNLIKELY(ASMAtomicDecU32(&pThis->cRefs) == 0))
ab93606043a9881487aa83be04191d2f4ea24071vboxsyncRTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI hEventMultiSem)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
ab93606043a9881487aa83be04191d2f4ea24071vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("pThis=%p u32Magic=%#x\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync AssertMsgReturn(pThis->cRefs > 0, ("pThis=%p cRefs=%d\n", pThis, pThis->cRefs), VERR_INVALID_HANDLE);
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync /* Invalidate the handle and wake up all threads that might be waiting on the semaphore. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync ASMAtomicWriteU32(&pThis->u32Magic, RTSEMEVENTMULTI_MAGIC_DEAD);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync ASMAtomicAndU32(&pThis->fStateAndGen, RTSEMEVENTMULTISOL_GEN_MASK);
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync /* Drop the reference from RTSemEventMultiCreateEx. */
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsyncRTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI hEventMultiSem)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
a68835e2c9d5426d501f1bc78ff30e8ec5bb12cevboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,
a68835e2c9d5426d501f1bc78ff30e8ec5bb12cevboxsync ("pThis=%p u32Magic=%#x\n", pThis, pThis->u32Magic),
69dc0354ae98899256f5e73898f1dc973345ee65vboxsync * If we're in interrupt context we need to unpin the underlying current
69dc0354ae98899256f5e73898f1dc973345ee65vboxsync * thread as this could lead to a deadlock (see #4259 for the full explanation)
1564530634daa6810ea98bfc6dccb727728df853vboxsync * Note! See remarks about preemption in RTSemEventSignal.
542b82b1871753dc94a2a17b504094112f9df306vboxsync RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync * Do the job.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync uint32_t fNew = ASMAtomicUoReadU32(&pThis->fStateAndGen);
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsyncRTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI hEventMultiSem)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
a68835e2c9d5426d501f1bc78ff30e8ec5bb12cevboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,
a68835e2c9d5426d501f1bc78ff30e8ec5bb12cevboxsync ("pThis=%p u32Magic=%#x\n", pThis, pThis->u32Magic),
1564530634daa6810ea98bfc6dccb727728df853vboxsync * If we're in interrupt context we need to unpin the underlying current
1564530634daa6810ea98bfc6dccb727728df853vboxsync * thread as this could lead to a deadlock (see #4259 for the full explanation)
1564530634daa6810ea98bfc6dccb727728df853vboxsync * Note! See remarks about preemption in RTSemEventSignal.
542b82b1871753dc94a2a17b504094112f9df306vboxsync RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Do the job (could be done without the lock, but play safe).
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync ASMAtomicAndU32(&pThis->fStateAndGen, ~RTSEMEVENTMULTISOL_STATE_MASK);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync#if 0 /* NEW_STUFF - not working yet :-) */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** The absolute timeout given as nano seconds since the start of the
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * monotonic clock. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** The timeout in nano seconds relative to the start of the wait. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** The native timeout value. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** The timeout (abs lbolt) when fHighRes is false. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** Set if we use high resolution timeouts. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** Set if it's an indefinite wait. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** Set if we've already timed out.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Set by rtR0SemSolWaitDoIt or rtR0SemSolWaitHighResTimeout, read by
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * rtR0SemSolWaitHasTimedOut. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync bool volatile fTimedOut;
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** Whether the wait was interrupted. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** Interruptible or uninterruptible wait. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /** The thread to wake up. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Initializes a wait.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * The caller MUST check the wait condition BEFORE calling this function or the
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * timeout logic will be flawed.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @returns VINF_SUCCESS or VERR_TIMEOUT.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pWait The wait structure.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param fFlags The wait flags.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param uTimeout The timeout.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pWaitQueue The wait queue head.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncDECLINLINE(int) rtR0SemSolWaitInit(PRTR0SEMSOLWAIT pWait, uint32_t fFlags, uint64_t uTimeout)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Process the flags and timeout.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync uTimeout = uTimeout < UINT64_MAX / UINT32_C(1000000) * UINT32_C(1000000)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync if ( (fFlags & (RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_ABSOLUTE))
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync || pWait->cNsRelTimeout < UINT32_C(1000000000) / 100 /*Hz*/ * 4)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync uint64_t cTicks = drv_usectohz((clock_t)(uTimeout / 1000));
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync pWait->fInterruptible = !!(fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Cyclic timeout callback that sets the timeout indicator and wakes up the
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * waiting thread.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pvUser The wait structure.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncstatic void rtR0SemSolWaitHighResTimeout(void *pvUser)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Do the actual wait.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pWait The wait structure.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pCnd The condition variable to wait on.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pMtx The mutex related to the condition variable.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * The caller has entered this.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncDECLINLINE(void) rtR0SemSolWaitDoIt(PRTR0SEMSOLWAIT pWait, kcondvar_t *pCnd, kmutex_t *pMtx)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * No timeout - easy.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * High resolution timeout - arm a one-shot cyclic for waking up
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * the thread at the desired time.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync Cyh.cyh_level = CY_LOW_LEVEL; /// @todo try CY_LOCK_LEVEL and CY_HIGH_LEVEL?
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Normal timeout.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync rc = cv_timedwait_sig(pCnd, pMtx, pWait->u.lTimeout);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /* Above zero means normal wake-up. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /* Timeout is signalled by -1. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /* Interruption is signalled by 0. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Checks if a solaris wait was interrupted.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @returns true / false
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pWait The wait structure.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @remarks This shall be called before the first rtR0SemSolWaitDoIt().
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncDECLINLINE(bool) rtR0SemSolWaitWasInterrupted(PRTR0SEMSOLWAIT pWait)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Checks if a solaris wait has timed out.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @returns true / false
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pWait The wait structure.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncDECLINLINE(bool) rtR0SemSolWaitHasTimedOut(PRTR0SEMSOLWAIT pWait)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Deletes a solaris wait.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pWait The wait structure.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncDECLINLINE(void) rtR0SemSolWaitDelete(PRTR0SEMSOLWAIT pWait)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Worker for RTSemEventMultiWaitEx and RTSemEventMultiWaitExDebug.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @returns VBox status code.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pThis The event semaphore.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param fFlags See RTSemEventMultiWaitEx.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param uTimeout See RTSemEventMultiWaitEx.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * @param pSrcPos The source code position of the wait.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncstatic int rtR0SemEventMultiSolWait(PRTSEMEVENTMULTIINTERNAL pThis, uint32_t fFlags, uint64_t uTimeout,
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Validate the input.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync AssertReturn(RTSEMWAIT_FLAGS_ARE_VALID(fFlags), VERR_INVALID_PARAMETER);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync mutex_enter(&pThis->Mtx); /* this could be moved down to the else, but play safe for now. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * Is the event already signalled or do we have to wait?
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync fOrgStateAndGen = ASMAtomicUoReadU32(&pThis->fStateAndGen);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync if (fOrgStateAndGen & RTSEMEVENTMULTISOL_STATE_MASK)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync * We have to wait.
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /* The destruction test. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC))
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /* Check the exit conditions. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC))
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync else if (ASMAtomicUoReadU32(&pThis->fStateAndGen) != fOrgStateAndGen)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync /* Do the wait and then recheck the conditions. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync rtR0SemSolWaitDoIt(&Wait, &pThis->Cnd, &pThis->Mtx);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncRTDECL(int) RTSemEventMultiWaitEx(RTSEMEVENTMULTI hEventMultiSem, uint32_t fFlags, uint64_t uTimeout)
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync return rtR0SemEventMultiSolWait(hEventMultiSem, fFlags, uTimeout, NULL);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync return rtR0SemEventMultiSolWait(hEventMultiSem, fFlags, uTimeout, &SrcPos);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsyncRTDECL(int) RTSemEventMultiWaitExDebug(RTSEMEVENTMULTI hEventMultiSem, uint32_t fFlags, uint64_t uTimeout,
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync return rtR0SemEventMultiSolWait(hEventMultiSem, fFlags, uTimeout, &SrcPos);
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync#include "../../generic/RTSemEventMultiWait-2-ex-generic.cpp"
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync#include "../../generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp"
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync#else /* OLD_STUFF */
63e576f3c901db19ac9a11f2353025b66a6798eevboxsync * Translate milliseconds into ticks and go to sleep using the right method.
63e576f3c901db19ac9a11f2353025b66a6798eevboxsync * @retval >0 on normal or spurious wake-up.
63e576f3c901db19ac9a11f2353025b66a6798eevboxsync * @retval -1 on timeout.
63e576f3c901db19ac9a11f2353025b66a6798eevboxsync * @retval 0 on signal.
4add215f9918fd37934b252922caab7803aaac19vboxsyncstatic int rtSemEventMultiWaitWorker(PRTSEMEVENTMULTIINTERNAL pThis, RTMSINTERVAL cMillies, bool fInterruptible)
4add215f9918fd37934b252922caab7803aaac19vboxsync clock_t cTicks = drv_usectohz((clock_t)(cMillies * 1000L));
4add215f9918fd37934b252922caab7803aaac19vboxsync rc = cv_timedwait_sig(&pThis->Cnd, &pThis->Mtx, cTimeout);
4add215f9918fd37934b252922caab7803aaac19vboxsync rc = cv_timedwait(&pThis->Cnd, &pThis->Mtx, cTimeout);
b79e4344bf4eb8033fd06d560cd864192728bd0bvboxsyncstatic int rtSemEventMultiWait(RTSEMEVENTMULTI hEventMultiSem, RTMSINTERVAL cMillies, bool fInterruptible)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
a68835e2c9d5426d501f1bc78ff30e8ec5bb12cevboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC,
a68835e2c9d5426d501f1bc78ff30e8ec5bb12cevboxsync ("pThis=%p u32Magic=%#x\n", pThis, pThis->u32Magic),
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync if (pThis->fStateAndGen & RTSEMEVENTMULTISOL_STATE_MASK)
63e576f3c901db19ac9a11f2353025b66a6798eevboxsync /* This loop is only for continuing after a spurious wake-up. */
b9c00cd9c9b5f409e64bd7782815faa2c5ecd85fvboxsync uint32_t const uSignalGenBeforeWait = pThis->fStateAndGen;
4add215f9918fd37934b252922caab7803aaac19vboxsync rc = rtSemEventMultiWaitWorker(pThis, cMillies, fInterruptible);
4add215f9918fd37934b252922caab7803aaac19vboxsync if (RT_LIKELY(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC))
63e576f3c901db19ac9a11f2353025b66a6798eevboxsync continue; /* Spurious wake-up, go back to waiting. */
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync /* Retured due to call to cv_signal() or cv_broadcast(). */
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync /* We're being destroyed. */
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync /* Returned due to timeout being reached. */
ba2ad20e44479a5831d039c736a0d4ed2aa7d65bvboxsync /* Returned due to pending signal. */
b79e4344bf4eb8033fd06d560cd864192728bd0bvboxsyncRTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI hEventMultiSem, RTMSINTERVAL cMillies)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync return rtSemEventMultiWait(hEventMultiSem, cMillies, false /* not interruptible */);
b79e4344bf4eb8033fd06d560cd864192728bd0bvboxsyncRTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI hEventMultiSem, RTMSINTERVAL cMillies)
ab93606043a9881487aa83be04191d2f4ea24071vboxsync return rtSemEventMultiWait(hEventMultiSem, cMillies, true /* interruptible */);