semeventmulti-r0drv-nt.cpp revision ab93606043a9881487aa83be04191d2f4ea24071
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * IPRT - Multiple Release Event Semaphores, Ring-0 Driver, NT.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * 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
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * General Public License (GPL) as published by the Free Software
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * The contents of this file may alternatively be used under the terms
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * of the Common Development and Distribution License Version 1.0
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * VirtualBox OSE distribution, in which case the provisions of the
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * CDDL are applicable instead of those of the GPL.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * You may elect to license modified versions of this file under the
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * terms and conditions of either the GPL or the CDDL or both.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * additional information or have any questions.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*******************************************************************************
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync* Header Files *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync*******************************************************************************/
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync/*******************************************************************************
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync* Structures and Typedefs *
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync*******************************************************************************/
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * NT event semaphore.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /** Magic value (RTSEMEVENTMULTI_MAGIC). */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync /** The NT Event object. */
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync} RTSEMEVENTMULTIINTERNAL, *PRTSEMEVENTMULTIINTERNAL;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncRTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI phEventMultiSem)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync return RTSemEventMultiCreateEx(phEventMultiSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, NULL);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncRTDECL(int) RTSemEventMultiCreateEx(PRTSEMEVENTMULTI phEventMultiSem, uint32_t fFlags, RTLOCKVALCLASS hClass,
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync const char *pszNameFmt, ...)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync AssertReturn(!(fFlags & ~RTSEMEVENTMULTI_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync AssertCompile(sizeof(RTSEMEVENTMULTIINTERNAL) > sizeof(void *));
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis));
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync KeInitializeEvent(&pThis->Event, NotificationEvent, FALSE /* not signalled */);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncRTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI hEventMultiSem)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Invalidate it and signal the object just in case.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncRTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI hEventMultiSem)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Signal the event object.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncRTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI hEventMultiSem)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Reset the event object.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsyncstatic int rtSemEventMultiWait(RTSEMEVENTMULTI hEventMultiSem, unsigned cMillies, bool fInterruptible)
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Validate input.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * Wait for it.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync * We're assuming interruptible waits should happen at UserMode level.
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync KPROCESSOR_MODE WaitMode = fInterruptible ? UserMode : KernelMode;
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync rcNt = KeWaitForSingleObject(&pThis->Event, Executive, WaitMode, fInterruptible, NULL);
67c26773eca4a576449ffa8f289fa344fc7b8176vboxsync rcNt = KeWaitForSingleObject(&pThis->Event, Executive, WaitMode, fInterruptible, &Timeout);
switch (rcNt)
case STATUS_SUCCESS:
return VINF_SUCCESS;
return VERR_SEM_DESTROYED;
case STATUS_ALERTED:
return VERR_INTERRUPTED;
case STATUS_USER_APC:
return VERR_INTERRUPTED;
case STATUS_TIMEOUT:
return VERR_TIMEOUT;
return VERR_INTERNAL_ERROR;