semevent-r0drv-nt.cpp revision a734bb626f889ee3334bfc381be194b4ec56aae6
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Single Release Event Semaphores, Ring-0 Driver, NT.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * 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.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*******************************************************************************
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync* Header Files *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync*******************************************************************************/
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*******************************************************************************
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync* Structures and Typedefs *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync*******************************************************************************/
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * NT event semaphore.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /** Magic value (RTSEMEVENT_MAGIC). */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /** The NT Event object. */
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncRTDECL(int) RTSemEventCreate(PRTSEMEVENT phEventSem)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync return RTSemEventCreateEx(phEventSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, NULL);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncRTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem, uint32_t fFlags, RTLOCKVALCLASS hClass, const char *pszNameFmt, ...)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertReturn(!(fFlags & ~RTSEMEVENT_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertCompile(sizeof(RTSEMEVENTINTERNAL) > sizeof(void *));
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pThis));
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync KeInitializeEvent(&pThis->Event, SynchronizationEvent, FALSE);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Invalidate it and signal the object just in case.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)hEventSem;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Signal the event object.
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncstatic int rtSemEventWait(RTSEMEVENT hEventSem, unsigned cMillies, bool fInterruptible)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)hEventSem;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync * Wait for it.
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync * We're assuming interruptible waits should happen at UserMode level.
1198fb18b50cc20479302d19c0aa7ae93f69d359vboxsync KPROCESSOR_MODE WaitMode = fInterruptible ? UserMode : KernelMode;
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync rcNt = KeWaitForSingleObject(&pThis->Event, Executive, WaitMode, fInterruptible, NULL);
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync rcNt = KeWaitForSingleObject(&pThis->Event, Executive, WaitMode, fInterruptible, &Timeout);
36c508c1569b4ff2c4392b32266d2bef62064242vboxsync AssertMsgFailed(("pThis->u32Magic=%RX32 pThis=%p: wait returned %lx!\n",
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncRTDECL(int) RTSemEventWait(RTSEMEVENT hEventSem, unsigned cMillies)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync return rtSemEventWait(hEventSem, cMillies, false /* fInterruptible */);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsyncRTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT hEventSem, unsigned cMillies)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync return rtSemEventWait(hEventSem, cMillies, true /* fInterruptible */);