VirtualBox

Changeset 5165 in vbox for trunk/src/VBox/Runtime/r0drv


Ignore:
Timestamp:
Oct 5, 2007 1:32:50 PM (17 years ago)
Author:
vboxsync
Message:

RTSemEventWaitNoResume

Location:
trunk/src/VBox/Runtime/r0drv
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/linux/semaphore-r0drv-linux.c

    r4071 r5165  
    143143
    144144
    145 RTDECL(int)  RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
    146 {
    147     /*
    148      * Validate input.
    149      */
     145/**
     146 * Worker for RTSemEvent and RTSemEventNoResume.
     147 *
     148 * @returns VBox status code.
     149 * @param   pEventInt           The event semaphore.
     150 * @param   cMillies            The number of milliseconds to wait.
     151 * @param   fInterruptible      Whether it's an interruptible wait or not.
     152 */
     153static int rtSemEventWait(PRTSEMEVENTINTERNAL pEventInt, unsigned cMillies, bool fInterruptible)
     154{
     155    /*
     156     * Ok wait for it.
     157     */
     158    DEFINE_WAIT(Wait);
     159    int     rc       = VINF_SUCCESS;
     160    long    lTimeout = cMillies == RT_INDEFINITE_WAIT ? MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(cMillies);
     161    for (;;)
     162    {
     163        /* make everything thru schedule() atomic scheduling wise. */
     164        prepare_to_wait(&pEventInt->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
     165
     166        /* check the condition. */
     167        if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1))
     168            break;
     169
     170        /* check for pending signals. */
     171        if (fInterruptible && signal_pending(current))
     172        {
     173            rc = VERR_INTERRUPTED;
     174            break;
     175        }
     176
     177        /* wait */
     178        lTimeout = schedule_timeout(lTimeout);
     179
     180        /* Check if someone destroyed the semaphore while we were waiting. */
     181        if (pEventInt->u32Magic != RTSEMEVENT_MAGIC)
     182        {
     183            rc = VERR_SEM_DESTROYED;
     184            break;
     185        }
     186
     187        /* check for timeout. */
     188        if (!lTimeout)
     189        {
     190            rc = VERR_TIMEOUT;
     191            break;
     192        }
     193    }
     194
     195    finish_wait(&pEventInt->Head, &Wait);
     196    return rc;
     197}
     198
     199
     200RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
     201{
    150202    PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
    151203    if (!pEventInt)
     
    158210    }
    159211
    160     /*
    161      * Try get it.
    162      */
    163212    if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1))
    164213        return VINF_SUCCESS;
    165     else
    166     {
    167         /*
    168          * Ok wait for it.
    169          */
    170         DEFINE_WAIT(Wait);
    171         int     rc       = VINF_SUCCESS;
    172         long    lTimeout = cMillies == RT_INDEFINITE_WAIT ? MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(cMillies);
    173         for (;;)
    174         {
    175             /* make everything thru schedule() atomic scheduling wise. */
    176             prepare_to_wait(&pEventInt->Head, &Wait, TASK_INTERRUPTIBLE);
    177 
    178             /* check the condition. */
    179             if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1))
    180                 break;
    181 
    182             /* check for pending signals. */
    183             if (signal_pending(current))
    184             {
    185                 rc = VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */
    186                 break;
    187             }
    188 
    189             /* wait */
    190             lTimeout = schedule_timeout(lTimeout);
    191 
    192             /* Check if someone destroyed the semaphore while we were waiting. */
    193             if (pEventInt->u32Magic != RTSEMEVENT_MAGIC)
    194             {
    195                 rc = VERR_SEM_DESTROYED;
    196                 break;
    197             }
    198 
    199             /* check for timeout. */
    200             if (!lTimeout)
    201             {
    202                 rc = VERR_TIMEOUT;
    203                 break;
    204             }
    205         }
    206         finish_wait(&pEventInt->Head, &Wait);
    207         return rc;
    208     }
    209 }
     214    return rtSemEventWait(pEventInt, cMillies, false /* fInterruptible */);
     215}
     216
     217
     218RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
     219{
     220    PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
     221    if (!pEventInt)
     222        return VERR_INVALID_PARAMETER;
     223    if (    !pEventInt
     224        ||  pEventInt->u32Magic != RTSEMEVENT_MAGIC)
     225    {
     226        AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
     227        return VERR_INVALID_PARAMETER;
     228    }
     229
     230    if (ASMAtomicCmpXchgU32(&pEventInt->fState, 0, 1))
     231        return VINF_SUCCESS;
     232    return rtSemEventWait(pEventInt, cMillies, true /* fInterruptible */);
     233}
     234
    210235
    211236
  • trunk/src/VBox/Runtime/r0drv/nt/semaphore-r0drv-nt.cpp

    r4071 r5165  
    141141
    142142
    143 RTDECL(int)  RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
     143static int rtSemEventWait(RTSEMEVENT EventSem, unsigned cMillies, bool fInterruptible)
    144144{
    145145    /*
     
    161161    NTSTATUS rcNt;
    162162    if (cMillies == RT_INDEFINITE_WAIT)
    163         rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, TRUE, NULL);
     163        rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, fInterruptible, NULL);
    164164    else
    165165    {
    166166        LARGE_INTEGER Timeout;
    167167        Timeout.QuadPart = -(int64_t)cMillies * 10000;
    168         rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, TRUE, &Timeout);
     168        rcNt = KeWaitForSingleObject(&pEventInt->Event, Executive, KernelMode, fInterruptible, &Timeout);
    169169    }
    170170    switch (rcNt)
     
    175175            return VERR_SEM_DESTROYED;
    176176        case STATUS_ALERTED:
    177             return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */
     177            return VERR_INTERRUPTED;
    178178        case STATUS_USER_APC:
    179             return VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */
     179            return VERR_INTERRUPTED;
    180180        case STATUS_TIMEOUT:
    181181            return VERR_TIMEOUT;
     
    187187}
    188188
     189
     190RTDECL(int)  RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
     191{
     192    return rtSemEventWait(EventSem, cMillies, false /* fInterruptible */);
     193}
     194
     195
     196RTDECL(int)  RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
     197{
     198    return rtSemEventWait(EventSem, cMillies, true /* fInterruptible */);
     199}
    189200
    190201
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