timer-r0drv-solaris.c revision 0f77dc54d7ec617480988ccdfcd080f480e79698
/** $Id$ */
/** @file
* IPRT - Timer, Ring-0 Driver, Solaris.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-solaris-kernel.h"
#include <iprt/spinlock.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The internal representation of a Solaris 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 current timer tick (since last timer start). */
/** The Solaris cyclic structure. */
/** The Solaris cyclic handle. */
/** Callback. */
/** User argument. */
void *pvUser;
/** The timer interval. 0 for one-shot timer */
} RTTIMER;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static void rtTimerSolarisCallback(void *pvTimer);
RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser)
{
/*
* Validate flags.
*/
if (!RTTIMER_FLAGS_ARE_VALID(fFlags))
return VERR_INVALID_PARAMETER;
if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
/** @todo implement && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL*/)
return VERR_NOT_SUPPORTED;
/*
* Allocate and initialize the timer handle.
*/
if (!pTimer)
return VERR_NO_MEMORY;
pTimer->fSuspended = true;
return VINF_SUCCESS;
}
/**
* Validates the timer handle.
*
* @returns true if valid, false if invalid.
* @param pTimer The handle.
*/
{
return true;
}
{
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;
}
static void rtTimerSolarisCallback(void *pvTimer)
{
/* If this is a one shot timer, call pfnTimer and suspend
* as Solaris does not support 0 interval timers implictly
*/
if (!pTimer->u64NanoInterval)
{
pTimer->fSuspended = true;
}
/* Callback user defined callback function */
}
{
/* Important we check for invalid cyclic object */
{
}
}
{
return nsec_per_tick;
}
{
return VERR_NOT_SUPPORTED;
}
{
return VERR_NOT_SUPPORTED;
}