semevent-r0drv-linux.c revision 683eff3070b1b86fe71b71af7fda82766ea19d17
/* $Id$ */
/** @file
* IPRT - Single Release Event Semaphores, Ring-0 Driver, Linux.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* 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 (GPL) 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-linux-kernel.h"
#include <iprt/semaphore.h>
#include <iprt/lockvalidator.h>
#include "waitqueue-r0drv-linux.h"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Linux event semaphore.
*/
typedef struct RTSEMEVENTINTERNAL
{
/** Magic value (RTSEMEVENT_MAGIC). */
/** The object status - !0 when signaled and 0 when reset. */
/** Reference counter. */
/** The wait queue. */
{
}
RTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem, uint32_t fFlags, RTLOCKVALCLASS hClass, const char *pszNameFmt, ...)
{
if (!pThis)
return VERR_NO_MEMORY;
*phEventSem = pThis;
return VINF_SUCCESS;
}
/**
* Retains a reference to the event semaphore.
*
* @param pThis The event semaphore.
*/
{
}
/**
* Releases a reference to the event semaphore.
*
* @param pThis The event semaphore.
*/
{
}
{
/*
* Validate input.
*/
if (pThis == NIL_RTSEMEVENT)
return VINF_SUCCESS;
AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
/*
* Invalidate it and signal the object just in case.
*/
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
/*
* Signal the event object.
*/
return VINF_SUCCESS;
}
/**
* Worker for RTSemEventWaitEx and RTSemEventWaitExDebug.
*
* @returns VBox status code.
* @param pThis The event semaphore.
* @param fFlags See RTSemEventWaitEx.
* @param uTimeout See RTSemEventWaitEx.
* @param pSrcPos The source code position of the wait.
*/
{
int rc;
/*
* Validate the input.
*/
AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
/*
* Try grab the event without setting up the wait.
*/
if ( 1 /** @todo check if there are someone waiting already - waitqueue_active, but then what do we do below? */
rc = VINF_SUCCESS;
else
{
/*
* We have to wait.
*/
if (RT_SUCCESS(rc))
{
for (;;)
{
/* The destruction test. */
else
{
/* Check the exit conditions. */
rc = VINF_SUCCESS;
else if (rtR0SemLnxWaitHasTimedOut(&Wait))
rc = VERR_TIMEOUT;
else if (rtR0SemLnxWaitWasInterrupted(&Wait))
else
{
/* Do the wait and then recheck the conditions. */
continue;
}
}
break;
}
}
}
return rc;
}
{
#ifndef RTSEMEVENT_STRICT
#else
#endif
}
{
}