semeventmulti-r0drv-linux.c revision 30c84c361575629a712f338b514d9db7a8c681f4
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * IPRT - Multiple Release Event Semaphores, Ring-0 Driver, Linux.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * available from http://www.virtualbox.org. This file is free software;
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * you can redistribute it and/or modify it under the terms of the GNU
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * General Public License (GPL) as published by the Free Software
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * The contents of this file may alternatively be used under the terms
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * of the Common Development and Distribution License Version 1.0
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * VirtualBox OSE distribution, in which case the provisions of the
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * CDDL are applicable instead of those of the GPL.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * You may elect to license modified versions of this file under the
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * terms and conditions of either the GPL or the CDDL or both.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * additional information or have any questions.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync/*******************************************************************************
671242f350d172e106580348e24bab66b0d7e6a5vboxsync* Header Files *
671242f350d172e106580348e24bab66b0d7e6a5vboxsync*******************************************************************************/
671242f350d172e106580348e24bab66b0d7e6a5vboxsync/*******************************************************************************
671242f350d172e106580348e24bab66b0d7e6a5vboxsync* Structures and Typedefs *
671242f350d172e106580348e24bab66b0d7e6a5vboxsync*******************************************************************************/
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Linux event semaphore.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /** Magic value (RTSEMEVENTMULTI_MAGIC). */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /** The object status - !0 when signaled and 0 when reset. */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /** The wait queue. */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync} RTSEMEVENTMULTIINTERNAL, *PRTSEMEVENTMULTIINTERNAL;
671242f350d172e106580348e24bab66b0d7e6a5vboxsyncRTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)
671242f350d172e106580348e24bab66b0d7e6a5vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis));
671242f350d172e106580348e24bab66b0d7e6a5vboxsyncRTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Validate input.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
671242f350d172e106580348e24bab66b0d7e6a5vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Invalidate it and signal the object just in case.
671242f350d172e106580348e24bab66b0d7e6a5vboxsyncRTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Validate input.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
671242f350d172e106580348e24bab66b0d7e6a5vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Signal the event object.
671242f350d172e106580348e24bab66b0d7e6a5vboxsyncRTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Validate input.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
671242f350d172e106580348e24bab66b0d7e6a5vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Reset it.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Worker for RTSemEventMulti and RTSemEventMultiNoResume.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * @returns VBox status code.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * @param pThis The event semaphore.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * @param cMillies The number of milliseconds to wait.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * @param fInterruptible Whether it's an interruptible wait or not.
671242f350d172e106580348e24bab66b0d7e6a5vboxsyncstatic int rtSemEventMultiWait(PRTSEMEVENTMULTIINTERNAL pThis, unsigned cMillies, bool fInterruptible)
671242f350d172e106580348e24bab66b0d7e6a5vboxsync * Ok wait for it.
671242f350d172e106580348e24bab66b0d7e6a5vboxsync long lTimeout = cMillies == RT_INDEFINITE_WAIT ? MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(cMillies);
671242f350d172e106580348e24bab66b0d7e6a5vboxsync snprintf(current->comm, TASK_COMM_LEN, "E%lx", IPRT_DEBUG_SEMS_ADDRESS(pThis));
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /* make everything thru schedule() atomic scheduling wise. */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync prepare_to_wait(&pThis->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /* check the condition. */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /* check for pending signals. */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /* Check if someone destroyed the semaphore while we were waiting. */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync /* check for timeout. */
671242f350d172e106580348e24bab66b0d7e6a5vboxsync snprintf(current->comm, TASK_COMM_LEN, "E%lx:%d", IPRT_DEBUG_SEMS_ADDRESS(pThis), rc);
671242f350d172e106580348e24bab66b0d7e6a5vboxsyncRTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
671242f350d172e106580348e24bab66b0d7e6a5vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
671242f350d172e106580348e24bab66b0d7e6a5vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
671242f350d172e106580348e24bab66b0d7e6a5vboxsync return rtSemEventMultiWait(pThis, cMillies, false /* fInterruptible */);
671242f350d172e106580348e24bab66b0d7e6a5vboxsyncRTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
671242f350d172e106580348e24bab66b0d7e6a5vboxsync PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)EventMultiSem;
return VERR_INVALID_PARAMETER;
AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
return VINF_SUCCESS;