semevent-r0drv-linux.c revision a8e0cb7ddfd05bcabf5e18959cf09e723f254663
/* $Id$ */
/** @file
* innotek Portable Runtime - Single Release Event Semaphores, Ring-0 Driver, Linux.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-linux-kernel.h"
#include <iprt/semaphore.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Linux event semaphore.
*/
typedef struct RTSEMEVENTINTERNAL
{
/** Magic value (RTSEMEVENT_MAGIC). */
/** The object status - !0 when signaled and 0 when reset. */
/** The wait queue. */
{
if (pEventInt)
{
return VINF_SUCCESS;
}
return VERR_NO_MEMORY;
}
{
/*
* Validate input.
*/
if (!pEventInt)
return VERR_INVALID_PARAMETER;
{
return VERR_INVALID_PARAMETER;
}
/*
* Invalidate it and signal the object just in case.
*/
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
if (!pEventInt)
return VERR_INVALID_PARAMETER;
if ( !pEventInt
{
AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
return VERR_INVALID_PARAMETER;
}
/*
* Signal the event object.
*/
return VINF_SUCCESS;
}
/**
* Worker for RTSemEvent and RTSemEventNoResume.
*
* @returns VBox status code.
* @param pEventInt The event semaphore.
* @param cMillies The number of milliseconds to wait.
* @param fInterruptible Whether it's an interruptible wait or not.
*/
{
/*
* Ok wait for it.
*/
int rc = VINF_SUCCESS;
for (;;)
{
/* make everything thru schedule() atomic scheduling wise. */
prepare_to_wait(&pEventInt->Head, &Wait, fInterruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
/* check the condition. */
break;
/* check for pending signals. */
{
break;
}
/* wait */
/* Check if someone destroyed the semaphore while we were waiting. */
{
break;
}
/* check for timeout. */
if (!lTimeout)
{
rc = VERR_TIMEOUT;
break;
}
}
return rc;
}
{
if (!pEventInt)
return VERR_INVALID_PARAMETER;
if ( !pEventInt
{
AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
return VERR_INVALID_PARAMETER;
}
return VINF_SUCCESS;
}
{
if (!pEventInt)
return VERR_INVALID_PARAMETER;
if ( !pEventInt
{
AssertMsgFailed(("pEventInt->u32Magic=%RX32 pEventInt=%p\n", pEventInt ? pEventInt->u32Magic : 0, pEventInt));
return VERR_INVALID_PARAMETER;
}
return VINF_SUCCESS;
}