/* $Id$ */
/** @file
* IPRT - FreeBSD Ring-0 Driver Helpers for Abstracting Sleep Queues,
*/
/*
* Copyright (C) 2006-2012 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.
*/
#include "the-freebsd-kernel.h"
#include <iprt/asm-math.h>
/**
* Kernel mode FreeBSD wait state structure.
*/
typedef struct RTR0SEMBSDSLEEP
{
/** The absolute timeout given as nano seconds since the start of the
* monotonic clock. */
/** The timeout in ticks. Updated after waiting. */
int iTimeout;
/** Set if it's an indefinite wait. */
bool fIndefinite;
/** Set if we've already timed out.
* Set by rtR0SemBsdWaitDoIt and read by rtR0SemBsdWaitHasTimedOut. */
bool fTimedOut;
/** Flag whether the wait was interrupted. */
bool fInterrupted;
/** flag whether the wait is interruptible or not. */
bool fInterruptible;
/** Opaque wait channel id. */
void *pvWaitChan;
/** Pointer to a FreeBSD wait state. */
/**
* Updates the timeout of the FreeBSD wait.
*
* @returns RTSEMWAIT_FLAGS_INDEFINITE if the timeout value is too big.
* 0 otherwise
* @param pWait The wait structure.
* @param uTimeout The relative timeout in nanoseconds.
*/
{
#if 0
#else
return RTSEMWAIT_FLAGS_INDEFINITE;
else
#endif
return 0;
}
/**
* Initializes a wait.
*
* The caller MUST check the wait condition BEFORE calling this function or the
* timeout logic will be flawed.
*
* @returns VINF_SUCCESS or VERR_TIMEOUT.
* @param pWait The wait structure.
* @param fFlags The wait flags.
* @param uTimeout The timeout.
* @param pvWaitChan The opaque wait channel.
*/
void *pvWaitChan)
{
/*
* Process the flags and timeout.
*/
if (!(fFlags & RTSEMWAIT_FLAGS_INDEFINITE))
{
/** @todo optimize: millisecs -> nanosecs -> millisec -> jiffies */
if (fFlags & RTSEMWAIT_FLAGS_MILLISECS)
: UINT64_MAX;
if (uTimeout == UINT64_MAX)
else
{
if (fFlags & RTSEMWAIT_FLAGS_RELATIVE)
{
if (uTimeout == 0)
return VERR_TIMEOUT;
u64Now = RTTimeSystemNanoTS();
else
}
else
{
u64Now = RTTimeSystemNanoTS();
return VERR_TIMEOUT;
}
}
}
if (!(fFlags & RTSEMWAIT_FLAGS_INDEFINITE))
{
pWait->fIndefinite = false;
}
if (fFlags & RTSEMWAIT_FLAGS_INDEFINITE)
{
pWait->fIndefinite = true;
}
/*
* Initialize the wait queue related bits.
*/
? true : false;
pWait->fInterrupted = false;
return VINF_SUCCESS;
}
/**
* Prepares the next wait.
*
* This must be called before rtR0SemBsdWaitDoIt, and the caller should check
* the exit conditions inbetween the two calls.
*
* @param pWait The wait structure.
*/
{
/* Lock the queues. */
}
/**
* Do the actual wait.
*
* @param pWait The wait structure.
*/
{
int rcBsd;
int fSleepqFlags = SLEEPQ_CONDVAR;
if (pWait->fInterruptible)
if (!pWait->fIndefinite)
{
if (pWait->fInterruptible)
else
}
else
{
if (pWait->fInterruptible)
else
{
rcBsd = 0;
}
}
switch (rcBsd)
{
case 0:
break;
case ERESTART:
{
if (!pWait->fIndefinite)
{
/* Recalc timeout. */
else
{
}
}
break;
}
case EWOULDBLOCK:
break;
case EINTR:
pWait->fInterrupted = true;
break;
default:
break;
}
}
/**
* Checks if a FreeBSD wait was interrupted.
*
* @returns true / false
* @param pWait The wait structure.
* @remarks This shall be called before the first rtR0SemBsdWaitDoIt().
*/
{
return pWait->fInterrupted;
}
/**
* Checks if a FreeBSD wait has timed out.
*
* @returns true / false
* @param pWait The wait structure.
*/
{
}
/**
* Deletes a FreeBSD wait.
*
* @param pWait The wait structure.
*/
{
}
/**
* Signals the wait channel.
*
* @param pvWaitChan The opaque wait channel handle.
*/
{
if (fWakeupSwapProc)
kick_proc0();
}
/**
* Wakes up all waiters on the wait channel.
*
* @param pvWaitChan The opaque wait channel handle.
*/
{
#endif
}
/**
* Gets the max resolution of the timeout machinery.
*
* @returns Resolution specified in nanoseconds.
*/
{
}
#endif