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