semevent-r0drv-linux.c revision 2045498c3a1635533d5319d1086f78d90331b0c6
b450d7a1747c5f4fb7c917a8ec1f9ce8440d7ffevboxsync * IPRT - Single Release Event Semaphores, Ring-0 Driver, Linux.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * available from http://www.virtualbox.org. This file is free software;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * General Public License (GPL) as published by the Free Software
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * The contents of this file may alternatively be used under the terms
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * of the Common Development and Distribution License Version 1.0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution, in which case the provisions of the
b450d7a1747c5f4fb7c917a8ec1f9ce8440d7ffevboxsync * CDDL are applicable instead of those of the GPL.
b450d7a1747c5f4fb7c917a8ec1f9ce8440d7ffevboxsync * You may elect to license modified versions of this file under the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * terms and conditions of either the GPL or the CDDL or both.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
b450d7a1747c5f4fb7c917a8ec1f9ce8440d7ffevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b450d7a1747c5f4fb7c917a8ec1f9ce8440d7ffevboxsync * additional information or have any questions.
b450d7a1747c5f4fb7c917a8ec1f9ce8440d7ffevboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Header Files *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync*******************************************************************************/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Structures and Typedefs *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync*******************************************************************************/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Linux event semaphore.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Magic value (RTSEMEVENT_MAGIC). */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The object status - !0 when signaled and 0 when reset. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The wait queue. */
6a795f9e75e30c7f1d75cd45e5de233c71662f58vboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pEventInt));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Validate input.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt->u32Magic, pEventInt));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Invalidate it and signal the object just in case.
46a78ba0ce1d037aaed54f3df16ebd9c0b70ed39vboxsync * Validate input.
46a78ba0ce1d037aaed54f3df16ebd9c0b70ed39vboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
152d786a21a506f9e2a2e16ba8efdc2bcae133abvboxsync AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Signal the event object.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Worker for RTSemEvent and RTSemEventNoResume.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pEventInt The event semaphore.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param cMillies The number of milliseconds to wait.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param fInterruptible Whether it's an interruptible wait or not.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int rtSemEventWait(PRTSEMEVENTINTERNAL pEventInt, unsigned cMillies, bool fInterruptible)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Ok wait for it.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync long lTimeout = cMillies == RT_INDEFINITE_WAIT ? MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(cMillies);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync snprintf(current->comm, TASK_COMM_LEN, "e%lx", IPRT_DEBUG_SEMS_ADDRESS(pEventInt));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* make everything thru schedule() atomic scheduling wise. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync prepare_to_wait(&pEventInt->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* check the condition. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* check for pending signals. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Check if someone destroyed the semaphore while we were waiting. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* check for timeout. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync snprintf(current->comm, TASK_COMM_LEN, "e%lx:%d", IPRT_DEBUG_SEMS_ADDRESS(pEventInt), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncRTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rtSemEventWait(pEventInt, cMillies, false /* fInterruptible */);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncRTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rtSemEventWait(pEventInt, cMillies, true /* fInterruptible */);