67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/* $Id$ */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/** @file
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Single Release Event Semaphores, Ring-0 Driver, NT.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2011 Oracle Corporation
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * available from http://www.virtualbox.org. This file is free software;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * 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 *
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 *
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.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*******************************************************************************
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync* Header Files *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync*******************************************************************************/
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync#define RTSEMEVENT_WITHOUT_REMAPPING
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync#include "the-nt-kernel.h"
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync#include <iprt/semaphore.h>
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync#include <iprt/asm.h>
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync#include <iprt/assert.h>
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync#include <iprt/err.h>
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync#include <iprt/lockvalidator.h>
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync#include <iprt/mem.h>
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync#include <iprt/time.h>
8f9193a0c6db641a38d56ceba5747557f1e9927dvboxsync#include <iprt/timer.h>
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync#include "internal/magics.h"
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*******************************************************************************
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync* Structures and Typedefs *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync*******************************************************************************/
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/**
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * NT event semaphore.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsynctypedef struct RTSEMEVENTINTERNAL
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync{
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /** Magic value (RTSEMEVENT_MAGIC). */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync uint32_t volatile u32Magic;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync /** Reference counter. */
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync uint32_t volatile cRefs;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /** The NT Event object. */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync KEVENT Event;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync} RTSEMEVENTINTERNAL, *PRTSEMEVENTINTERNAL;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncRTDECL(int) RTSemEventCreate(PRTSEMEVENT phEventSem)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync{
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync return RTSemEventCreateEx(phEventSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, NULL);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync}
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncRTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem, uint32_t fFlags, RTLOCKVALCLASS hClass, const char *pszNameFmt, ...)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync{
418b9db49fbc652ef9c3f030fdc0f1a322403d95vboxsync AssertReturn(!(fFlags & ~(RTSEMEVENT_FLAGS_NO_LOCK_VAL | RTSEMEVENT_FLAGS_BOOTSTRAP_HACK)), VERR_INVALID_PARAMETER);
418b9db49fbc652ef9c3f030fdc0f1a322403d95vboxsync Assert(!(fFlags & RTSEMEVENT_FLAGS_BOOTSTRAP_HACK) || (fFlags & RTSEMEVENT_FLAGS_NO_LOCK_VAL));
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertCompile(sizeof(RTSEMEVENTINTERNAL) > sizeof(void *));
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pThis));
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (pThis)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync {
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync pThis->u32Magic = RTSEMEVENT_MAGIC;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync pThis->cRefs = 1;
99aa2f6ae259b9b90562d09f3f663f07c2828eeevboxsync KeInitializeEvent(&pThis->Event, SynchronizationEvent, FALSE /* not signalled */);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync *phEventSem = pThis;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync return VINF_SUCCESS;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync }
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync return VERR_NO_MEMORY;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync}
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync/**
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * Retains a reference to the semaphore.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync *
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * @param pThis The semaphore to retain.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync */
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsyncDECLINLINE(void) rtR0SemEventNtRetain(PRTSEMEVENTINTERNAL pThis)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync{
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync Assert(cRefs < 100000); NOREF(cRefs);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync}
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync/**
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * Releases a reference to the semaphore.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync *
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * @param pThis The semaphore to release
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync */
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsyncDECLINLINE(void) rtR0SemEventNtRelease(PRTSEMEVENTINTERNAL pThis)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync{
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (ASMAtomicDecU32(&pThis->cRefs) == 0)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync RTMemFree(pThis);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync}
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncRTDECL(int) RTSemEventDestroy(RTSEMEVENT hEventSem)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync{
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /*
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync PRTSEMEVENTINTERNAL pThis = hEventSem;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync if (pThis == NIL_RTSEMEVENT)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync return VINF_SUCCESS;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /*
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Invalidate it and signal the object just in case.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync ASMAtomicIncU32(&pThis->u32Magic);
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync KeSetEvent(&pThis->Event, 0xfff, FALSE);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rtR0SemEventNtRelease(pThis);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync return VINF_SUCCESS;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync}
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsyncRTDECL(int) RTSemEventSignal(RTSEMEVENT hEventSem)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync{
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /*
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)hEventSem;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rtR0SemEventNtRetain(pThis);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /*
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Signal the event object.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync KeSetEvent(&pThis->Event, 1, FALSE);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rtR0SemEventNtRelease(pThis);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync return VINF_SUCCESS;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync}
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync/**
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * Worker for RTSemEventWaitEx and RTSemEventWaitExDebug.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync *
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * @returns VBox status code.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * @param pThis The event semaphore.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * @param fFlags See RTSemEventWaitEx.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * @param uTimeout See RTSemEventWaitEx.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * @param pSrcPos The source code position of the wait.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync */
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsyncDECLINLINE(int) rtR0SemEventNtWait(PRTSEMEVENTINTERNAL pThis, uint32_t fFlags, uint64_t uTimeout,
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync PCRTLOCKVALSRCPOS pSrcPos)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync{
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /*
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync */
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (!pThis)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync return VERR_INVALID_PARAMETER;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
81a2bceb78e8b2f05efef55789b1689b31b3acacvboxsync AssertReturn(RTSEMWAIT_FLAGS_ARE_VALID(fFlags), VERR_INVALID_PARAMETER);
81a2bceb78e8b2f05efef55789b1689b31b3acacvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rtR0SemEventNtRetain(pThis);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync /*
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * Convert the timeout to a relative one because KeWaitForSingleObject
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * takes system time instead of interrupt time as input for absolute
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * timeout specifications. So, we're best of by giving it relative time.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync *
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync * Lazy bird converts uTimeout to relative nanoseconds and then to Nt time.
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync */
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (!(fFlags & RTSEMWAIT_FLAGS_INDEFINITE))
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync {
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (fFlags & RTSEMWAIT_FLAGS_MILLISECS)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync uTimeout = uTimeout < UINT64_MAX / UINT32_C(1000000) * UINT32_C(1000000)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync ? uTimeout * UINT32_C(1000000)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync : UINT64_MAX;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (uTimeout == UINT64_MAX)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync fFlags |= RTSEMWAIT_FLAGS_INDEFINITE;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync else
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync {
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (fFlags & RTSEMWAIT_FLAGS_ABSOLUTE)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync {
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync uint64_t u64Now = RTTimeSystemNanoTS();
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync uTimeout = u64Now < uTimeout
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync ? uTimeout - u64Now
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync : 0;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync }
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync }
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync }
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync /*
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync * Wait for it.
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync * We're assuming interruptible waits should happen at UserMode level.
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync */
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync NTSTATUS rcNt;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync BOOLEAN fInterruptible = !!(fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE);
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync KPROCESSOR_MODE WaitMode = fInterruptible ? UserMode : KernelMode;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (fFlags & RTSEMWAIT_FLAGS_INDEFINITE)
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync rcNt = KeWaitForSingleObject(&pThis->Event, Executive, WaitMode, fInterruptible, NULL);
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync else
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync {
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync LARGE_INTEGER Timeout;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync Timeout.QuadPart = -(int64_t)(uTimeout / 100);
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync rcNt = KeWaitForSingleObject(&pThis->Event, Executive, WaitMode, fInterruptible, &Timeout);
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync }
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync int rc;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync if (pThis->u32Magic == RTSEMEVENT_MAGIC)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync {
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync switch (rcNt)
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync {
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync case STATUS_SUCCESS:
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rc = VINF_SUCCESS;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync break;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync case STATUS_ALERTED:
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rc = VERR_INTERRUPTED;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync break;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync case STATUS_USER_APC:
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rc = VERR_INTERRUPTED;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync break;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync case STATUS_TIMEOUT:
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rc = VERR_TIMEOUT;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync break;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync default:
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync AssertMsgFailed(("pThis->u32Magic=%RX32 pThis=%p: wait returned %lx!\n",
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync pThis->u32Magic, pThis, (long)rcNt));
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rc = VERR_INTERNAL_ERROR_4;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync break;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync }
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync }
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync else
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rc = VERR_SEM_DESTROYED;
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync rtR0SemEventNtRelease(pThis);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync return rc;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync}
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsyncRTDECL(int) RTSemEventWaitEx(RTSEMEVENT hEventSem, uint32_t fFlags, uint64_t uTimeout)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync{
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync#ifndef RTSEMEVENT_STRICT
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync return rtR0SemEventNtWait(hEventSem, fFlags, uTimeout, NULL);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync#else
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync return rtR0SemEventNtWait(hEventSem, fFlags, uTimeout, &SrcPos);
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync#endif
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync}
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsyncRTDECL(int) RTSemEventWaitExDebug(RTSEMEVENT hEventSem, uint32_t fFlags, uint64_t uTimeout,
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync RTHCUINTPTR uId, RT_SRC_POS_DECL)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync{
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
4c5ed14a824b5df6b1d5aee5f524eea7b0d9459fvboxsync return rtR0SemEventNtWait(hEventSem, fFlags, uTimeout, &SrcPos);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync}
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsyncRTDECL(uint32_t) RTSemEventGetResolution(void)
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync{
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync return RTTimerGetSystemGranularity();
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync}
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync