semeventmulti-r0drv-freebsd.c revision 24b814713d57519124d491243137f551be686c66
/* $Id$ */
/** @file
* IPRT - Multiple Release Event Semaphores, Ring-0 Driver, FreeBSD.
*/
/*
* Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-freebsd-kernel.h"
#include <iprt/semaphore.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* FreeBSD multiple release event semaphore.
*/
typedef struct RTSEMEVENTMULTIINTERNAL
{
/** Magic value (RTSEMEVENTMULTI_MAGIC). */
/** The number of waiting threads. */
/** Set if the event object is signaled. */
/** The number of threads in the process of waking up. */
/** The FreeBSD spinlock protecting this structure. */
{
Assert(sizeof(RTSEMEVENTMULTIINTERNAL) > sizeof(void *));
PRTSEMEVENTMULTIINTERNAL pEventMultiInt = (PRTSEMEVENTMULTIINTERNAL)RTMemAllocZ(sizeof(*pEventMultiInt));
if (pEventMultiInt)
{
pEventMultiInt->cWaiters = 0;
pEventMultiInt->cWaking = 0;
pEventMultiInt->fSignaled = 0;
return VINF_SUCCESS;
}
return VERR_NO_MEMORY;
}
{
return VERR_INVALID_HANDLE;
if (pEventMultiInt->cWaiters > 0)
{
/* abort waiting thread, last man cleans up. */
}
else if (pEventMultiInt->cWaking)
/* the last waking thread is gonna do the cleanup */
else
{
}
return VINF_SUCCESS;
}
{
if (pEventMultiInt->cWaiters > 0)
{
}
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
static int rtSemEventMultiWait(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies, bool fInterruptible)
{
int rc;
if (pEventMultiInt->fSignaled)
rc = VINF_SUCCESS;
else
{
/*
* Translate milliseconds into ticks and go to sleep.
*/
int cTicks;
if (cMillies != RT_INDEFINITE_WAIT)
{
if (hz == 1000)
else if (hz == 100)
else
{
}
}
else
cTicks = 0;
//fInterruptible ? PZERO | PCATCH : PZERO,
"iprte", /* max 6 chars */
cTicks);
switch (rc)
{
case 0:
{
rc = VINF_SUCCESS;
}
else
{
* could've woken up just before destruction... */
{
/* The event was destroyed, as the last thread do the cleanup.
we don't actually know whether */
return rc;
}
}
break;
case EWOULDBLOCK:
if (pEventMultiInt->cWaiters > 0)
rc = VERR_TIMEOUT;
break;
case EINTR:
case ERESTART:
if (pEventMultiInt->cWaiters > 0)
break;
default:
break;
}
}
return rc;
}
{
}
{
}