timer-r0drv-freebsd.c revision 5b281ba489ca18f0380d7efc7a5108b606cce449
/* $Id$ */
/** @file
* IPRT - Memory Allocation, 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/spinlock.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The internal representation of an FreeBSD timer handle.
*/
typedef struct RTTIMER
{
/** Magic.
* This is RTTIMER_MAGIC, but changes to something else before the timer
* is destroyed to indicate clearly that thread should exit. */
/** Flag indicating the the timer is suspended. */
uint8_t volatile fSuspended;
/** Whether the timer must run on a specific CPU or not. */
/** The CPU it must run on if fSpecificCpu is set. */
/** The FreeBSD callout structure. */
/** Callback. */
/** User argument. */
void *pvUser;
/** The timer interval. 0 if one-shot. */
/** The start of the current run.
* This is used to calculate when the timer ought to fire the next time. */
uint64_t volatile u64StartTS;
/** The start of the current run.
* This is used to calculate when the timer ought to fire the next time. */
/** The current tick number (since u64StartTS). */
} RTTIMER;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static void rtTimerFreeBSDCallback(void *pvTimer);
RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser)
{
/*
* Validate flags.
*/
if (!RTTIMER_FLAGS_IS_VALID(fFlags))
return VERR_INVALID_PARAMETER;
if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
return VERR_INVALID_PARAMETER;
/*
* Allocate and initialize the timer handle.
*/
if (!pTimer)
return VERR_NO_MEMORY;
pTimer->fSuspended = true;
pTimer->u64StartTS = 0;
return VINF_SUCCESS;
}
/**
* Validates the timer handle.
*
* @returns true if valid, false if invalid.
* @param pTimer The handle.
*/
{
return true;
}
{
/* It's ok to pass NULL pointer. */
return VINF_SUCCESS;
if (!rtTimerIsValid(pTimer))
return VERR_INVALID_HANDLE;
/*
* Free the associated resources.
*/
return VINF_SUCCESS;
}
{
if (!rtTimerIsValid(pTimer))
return VERR_INVALID_HANDLE;
if (!pTimer->fSuspended)
return VERR_TIMER_ACTIVE;
/*
* Calc when it should start fireing.
*/
u64First += RTTimeNanoTS();
pTimer->fSuspended = false;
return VINF_SUCCESS;
}
{
if (!rtTimerIsValid(pTimer))
return VERR_INVALID_HANDLE;
if (pTimer->fSuspended)
return VERR_TIMER_SUSPENDED;
/*
* Suspend the timer.
*/
pTimer->fSuspended = true;
return VINF_SUCCESS;
}
/**
* smp_rendezvous action callback.
*
* This will perform the timer callback if we're on the right CPU.
*
* @param pvTimer The timer.
*/
static void rtTimerFreeBSDIpiAction(void *pvTimer)
{
}
static void rtTimerFreeBSDCallback(void *pvTimer)
{
/* calculate and set the next timeout */
if (!pTimer->u64NanoInterval)
{
pTimer->fSuspended = true;
}
else
{
}
/* callback */
if ( !pTimer->fSpecificCpu
else
}
{
}
{
return VERR_NOT_SUPPORTED;
}
{
return VERR_NOT_SUPPORTED;
}