VirtualBox

Changeset 5230 in vbox for trunk/src/VBox/Runtime/r0drv/nt


Ignore:
Timestamp:
Oct 10, 2007 4:20:26 PM (17 years ago)
Author:
vboxsync
Message:

Added r0drv/nt/semeventmulti-r0drv-nt.cpp.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/nt/semeventmulti-r0drv-nt.cpp

    r5222 r5230  
    11/* $Id$ */
    22/** @file
    3  * innotek Portable Runtime -  Single Release Event Semaphores, Ring-0 Driver, NT.
     3 * innotek Portable Runtime -  Multiple Release Event Semaphores, Ring-0 Driver, NT.
    44 */
    55
     
    1515 * be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    17 
    1817
    1918
     
    3736 * NT event semaphore.
    3837 */
    39 typedef struct RTSEMEVENTINTERNAL
     38typedef struct RTSEMEVENTMULTIINTERNAL
    4039{
    41     /** Magic value (RTSEMEVENT_MAGIC). */
     40    /** Magic value (RTSEMEVENTMULTI_MAGIC). */
    4241    uint32_t volatile   u32Magic;
    4342    /** The NT Event object. */
    4443    KEVENT              Event;
    45 } RTSEMEVENTINTERNAL, *PRTSEMEVENTINTERNAL;
     44} RTSEMEVENTMULTIINTERNAL, *PRTSEMEVENTMULTIINTERNAL;
    4645
    4746
    48 RTDECL(int)  RTSemEventCreate(PRTSEMEVENT pEventSem)
     47RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventSem)
    4948{
    50     Assert(sizeof(RTSEMEVENTINTERNAL) > sizeof(void *));
    51     PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pEventInt));
    52     if (pEventInt)
     49    Assert(sizeof(RTSEMEVENTMULTIINTERNAL) > sizeof(void *));
     50    PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis));
     51    if (pThis)
    5352    {
    54         pEventInt->u32Magic = RTSEMEVENT_MAGIC;
    55         KeInitializeEvent(&pEventInt->Event, SynchronizationEvent, FALSE);
    56         *pEventSem = pEventInt;
     53        pThis->u32Magic = RTSEMEVENTMULTI_MAGIC;
     54        KeInitializeEvent(&pThis->Event, NotificationEvent, FALSE /* not signalled */);
     55        *pEventSem = pThis;
    5756        return VINF_SUCCESS;
    5857    }
     
    6160
    6261
    63 RTDECL(int)  RTSemEventDestroy(RTSEMEVENT EventSem)
     62RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
    6463{
    6564    /*
    6665     * Validate input.
    6766     */
    68     PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
    69     if (!pEventInt)
     67    PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
     68    if (!pThis)
    7069        return VERR_INVALID_PARAMETER;
    71     if (pEventInt->u32Magic != RTSEMEVENT_MAGIC)
    72     {
    73         AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt->u32Magic, pEventInt));
    74         return VERR_INVALID_PARAMETER;
    75     }
     70    AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
     71    AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
    7672
    7773    /*
    7874     * Invalidate it and signal the object just in case.
    7975     */
    80     ASMAtomicIncU32(&pEventInt->u32Magic);
    81     KeSetEvent(&pEventInt->Event, 0xfff, FALSE);
    82     RTMemFree(pEventInt);
     76    ASMAtomicIncU32(&pThis->u32Magic);
     77    KeSetEvent(&pThis->Event, 0xfff, FALSE);
     78    RTMemFree(pThis);
    8379    return VINF_SUCCESS;
    8480}
    8581
    8682
    87 RTDECL(int)  RTSemEventSignal(RTSEMEVENT EventSem)
     83RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
    8884{
    8985    /*
    9086     * Validate input.
    9187     */
    92     PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
    93     if (!pEventInt)
     88    PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
     89    if (!pThis)
    9490        return VERR_INVALID_PARAMETER;
    95     if (    !pEventInt
    96         ||  pEventInt->u32Magic != RTSEMEVENT_MAGIC)
    97     {
    98         AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
    99         return VERR_INVALID_PARAMETER;
    100     }
     91    AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
     92    AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
    10193
    10294    /*
    10395     * Signal the event object.
    10496     */
    105     KeSetEvent(&pEventInt->Event, 1, FALSE);
     97    KeSetEvent(&pThis->Event, 1, FALSE);
    10698    return VINF_SUCCESS;
    10799}
    108100
    109101
    110 static int rtSemEventWait(RTSEMEVENT EventSem, unsigned cMillies, bool fInterruptible)
     102RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
    111103{
    112104    /*
    113105     * Validate input.
    114106     */
    115     PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
    116     if (!pEventInt)
     107    PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
     108    if (!pThis)
    117109        return VERR_INVALID_PARAMETER;
    118     if (    !pEventInt
    119         ||  pEventInt->u32Magic != RTSEMEVENT_MAGIC)
    120     {
    121         AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
     110    AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
     111    AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
     112
     113    /*
     114     * Reset the event object.
     115     */
     116    KeResetEvent(&pThis->Event);
     117    return VINF_SUCCESS;
     118}
     119
     120
     121static int rtSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies, bool fInterruptible)
     122{
     123    /*
     124     * Validate input.
     125     */
     126    PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
     127    if (!pThis)
    122128        return VERR_INVALID_PARAMETER;
    123     }
     129    AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
     130    AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
    124131
    125132    /*
     
    128135    NTSTATUS rcNt;
    129136    if (cMillies == RT_INDEFINITE_WAIT)
    130         rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, fInterruptible, NULL);
     137        rcNt = KeWaitForSingleObject(&pThis->Event, Executive, KernelMode, fInterruptible, NULL);
    131138    else
    132139    {
    133140        LARGE_INTEGER Timeout;
    134141        Timeout.QuadPart = -(int64_t)cMillies * 10000;
    135         rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, fInterruptible, &Timeout);
     142        rcNt = KeWaitForSingleObject(&pThis->Event, Executive, KernelMode, fInterruptible, &Timeout);
    136143    }
    137144    switch (rcNt)
    138145    {
    139146        case STATUS_SUCCESS:
    140             if (pEventInt->u32Magic == RTSEMEVENT_MAGIC)
     147            if (pThis->u32Magic == RTSEMEVENTMULTI_MAGIC)
    141148                return VINF_SUCCESS;
    142149            return VERR_SEM_DESTROYED;
     
    148155            return VERR_TIMEOUT;
    149156        default:
    150             AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p: wait returned %lx!\n",
    151                              pEventInt->u32Magic, pEventInt, (long)rcNt));
     157            AssertMsgFailed(("pThis->u32Magic=%RX32 pThis=%p: wait returned %lx!\n",
     158                             pThis->u32Magic, pThis, (long)rcNt));
    152159            return VERR_INTERNAL_ERROR;
    153160    }
     
    155162
    156163
    157 RTDECL(int)  RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
     164RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
    158165{
    159     return rtSemEventWait(EventSem, cMillies, false /* fInterruptible */);
     166    return rtSemEventMultiWait(EventMultiSem, cMillies, false /* fInterruptible */);
    160167}
    161168
    162169
    163 RTDECL(int)  RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
     170RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
    164171{
    165     return rtSemEventWait(EventSem, cMillies, true /* fInterruptible */);
     172    return rtSemEventMultiWait(EventMultiSem, cMillies, true /* fInterruptible */);
    166173}
    167174
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette