semeventmulti-linux.cpp revision 8fdb63a0d23d1618724f651b8c3d11be48b44d35
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/* $Id$ */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/** @file
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * innotek Portable Runtime - Multiple Release Event Semaphore, Linux (2.6.x+).
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Copyright (C) 2006-2007 innotek GmbH
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync *
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * available from http://www.virtualbox.org. This file is free software;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * General Public License (GPL) as published by the Free Software
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync *
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * The contents of this file may alternatively be used under the terms
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * of the Common Development and Distribution License Version 1.0
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * VirtualBox OSE distribution, in which case the provisions of the
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * CDDL are applicable instead of those of the GPL.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync *
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * You may elect to license modified versions of this file under the
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * terms and conditions of either the GPL or the CDDL or both.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/*******************************************************************************
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync* Header Files *
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync*******************************************************************************/
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <iprt/semaphore.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <iprt/assert.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <iprt/alloc.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <iprt/asm.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <iprt/err.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include "internal/magics.h"
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <errno.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <limits.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <pthread.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <unistd.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <sys/time.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#include <sys/syscall.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#if 0 /* With 2.6.17 futex.h has become C++ unfriendly. */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync# include <linux/futex.h>
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#else
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync# define FUTEX_WAIT 0
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync# define FUTEX_WAKE 1
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#endif
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/*******************************************************************************
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync* Structures and Typedefs *
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync*******************************************************************************/
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/**
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Linux multiple wakup event semaphore.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstruct RTSEMEVENTMULTIINTERNAL
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /** Magic value. */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync intptr_t volatile iMagic;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /** The futex state variable.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * -1 means signaled.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * 0 means not signaled, no waiters.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * >0 means not signaled, and the value gives the number of waiters.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync int32_t volatile iState;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync};
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/**
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Wrapper for the futex syscall.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstatic long sys_futex(int32_t volatile *uaddr, int op, int val, struct timespec *utime, int32_t *uaddr2, int val3)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync errno = 0;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync long rc = syscall(__NR_futex, uaddr, op, val, utime, uaddr2, val3);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (rc < 0)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync Assert(rc == -1);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync rc = -errno;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return rc;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncRTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Allocate semaphore handle.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = (struct RTSEMEVENTMULTIINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTMULTIINTERNAL));
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync if (pThis)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync pThis->iMagic = RTSEMEVENTMULTI_MAGIC;
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync pThis->iState = 0;
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync *pEventMultiSem = pThis;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VINF_SUCCESS;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VERR_NO_MEMORY;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncRTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Validate input.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync VERR_INVALID_HANDLE);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Invalidate the semaphore and wake up anyone waiting on it.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
8fdb63a0d23d1618724f651b8c3d11be48b44d35vboxsync ASMAtomicWriteSize(&pThis->iMagic, RTSEMEVENTMULTI_MAGIC + 1);
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync if (ASMAtomicXchgS32(&pThis->iState, -1) == 1)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync sys_futex(&pThis->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync usleep(1000);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Free the semaphore memory and be gone.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync RTMemFree(pThis);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VINF_SUCCESS;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncRTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Validate input.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync VERR_INVALID_HANDLE);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Signal it.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync int32_t iOld = ASMAtomicXchgS32(&pThis->iState, -1);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (iOld > 0)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /* wake up sleeping threads. */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync long cWoken = sys_futex(&pThis->iState, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync AssertMsg(cWoken >= 0, ("%ld\n", cWoken)); NOREF(cWoken);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync Assert(iOld == 0 || iOld == -1 || iOld == 1);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VINF_SUCCESS;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncRTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Validate input.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync VERR_INVALID_HANDLE);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#ifdef RT_STRICT
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync int32_t i = pThis->iState;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync Assert(i == 0 || i == -1 || i == 1);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync#endif
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Reset it.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync ASMAtomicCmpXchgS32(&pThis->iState, 0, -1);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VINF_SUCCESS;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstatic int rtSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies, bool fAutoResume)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Validate input.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync AssertReturn(VALID_PTR(pThis) && pThis->iMagic == RTSEMEVENTMULTI_MAGIC,
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync VERR_INVALID_HANDLE);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Quickly check whether it's signaled.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
8fdb63a0d23d1618724f651b8c3d11be48b44d35vboxsync int32_t iCur = ASMAtomicUoReadS32(&pThis->iState);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync Assert(iCur == 0 || iCur == -1 || iCur == 1);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (iCur == -1)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VINF_SUCCESS;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (!cMillies)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VERR_TIMEOUT;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Convert timeout value.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync struct timespec ts;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync struct timespec *pTimeout = NULL;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (cMillies != RT_INDEFINITE_WAIT)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync ts.tv_sec = cMillies / 1000;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync ts.tv_nsec = (cMillies % 1000) * 1000000;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync pTimeout = &ts;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * The wait loop.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync for (unsigned i = 0;; i++)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Start waiting. We only account for there being or having been
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * threads waiting on the semaphore to keep things simple.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
8fdb63a0d23d1618724f651b8c3d11be48b44d35vboxsync iCur = ASMAtomicUoReadS32(&pThis->iState);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync Assert(iCur == 0 || iCur == -1 || iCur == 1);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if ( iCur == 1
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync || ASMAtomicCmpXchgS32(&pThis->iState, 1, 0))
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 1, pTimeout, NULL, 0);
89dfdbb56cf9dddad3c7685b41bda1e4e4c1d6f9vboxsync if (RT_UNLIKELY(pThis->iMagic != RTSEMEVENTMULTI_MAGIC))
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VERR_SEM_DESTROYED;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (rc == 0)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VINF_SUCCESS;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /*
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * Act on the wakup code.
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (rc == -ETIMEDOUT)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync Assert(pTimeout);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VERR_TIMEOUT;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (rc == -EWOULDBLOCK)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /* retry, the value changed. */;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync else if (rc == -EINTR)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync if (!fAutoResume)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VERR_INTERRUPTED;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync else
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync {
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /* this shouldn't happen! */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync AssertMsgFailed(("rc=%ld errno=%d\n", rc, errno));
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return RTErrConvertFromErrno(rc);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync else if (iCur == -1)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return VINF_SUCCESS;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync }
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncRTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync int rc = rtSemEventMultiWait(EventMultiSem, cMillies, true);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync Assert(rc != VERR_INTERRUPTED);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return rc;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncRTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync{
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return rtSemEventMultiWait(EventMultiSem, cMillies, false);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync}
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync