VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/vbi/timer-r0drv-solaris.c@ 9444

Last change on this file since 9444 was 9444, checked in by vboxsync, 17 years ago

Added iTick to FNTIMER (the timer callback).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/** $Id: timer-r0drv-solaris.c 9444 2008-06-05 18:08:17Z vboxsync $ */
2/** @file
3 * IPRT - Timer, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-solaris-kernel.h"
36
37#include <iprt/timer.h>
38#include <iprt/time.h>
39#include <iprt/spinlock.h>
40#include <iprt/err.h>
41#include <iprt/asm.h>
42#include <iprt/assert.h>
43#include <iprt/alloc.h>
44
45#include "internal/magics.h"
46
47
48/*******************************************************************************
49* Structures and Typedefs *
50*******************************************************************************/
51/**
52 * The internal representation of a Solaris timer handle.
53 */
54typedef struct RTTIMER
55{
56 /** Magic.
57 * This is RTTIMER_MAGIC, but changes to something else before the timer
58 * is destroyed to indicate clearly that thread should exit. */
59 uint32_t volatile u32Magic;
60 /** Flag indicating the the timer is suspended. */
61 uint8_t volatile fSuspended;
62 /** Whether the timer must run on a specific CPU or not. */
63 uint8_t fSpecificCpu;
64 /** The CPU it must run on if fSpecificCpu is set. */
65 uint8_t iCpu;
66 /** The Solaris timer handle. */
67 void *handle;
68 /** The user callback. */
69 PFNRTTIMER pfnTimer;
70 /** The current tick count. */
71 uint64_t iTick;
72
73} RTTIMER;
74
75
76/**
77 * Callback wrapper for adding the new iTick argument.
78 *
79 * @param pTimer The timer.
80 * @param pvUser The user argument.
81 */
82static void rtTimerSolarisCallbackWrapper(PRTTIMER pTimer, void *pvUser)
83{
84 pTimer->pfnTimer(pTimer, pvUser, ++pTimer->iTick);
85}
86
87
88
89
90RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser)
91{
92 *ppTimer = NULL;
93
94 /*
95 * Validate flags.
96 */
97 if (!RTTIMER_FLAGS_ARE_VALID(fFlags))
98 return VERR_INVALID_PARAMETER;
99 if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
100 /** @todo implement && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL*/)
101 return VERR_NOT_SUPPORTED;
102
103 /*
104 * Allocate and initialize the timer handle.
105 */
106 PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer));
107 if (!pTimer)
108 return VERR_NO_MEMORY;
109
110 pTimer->u32Magic = RTTIMER_MAGIC;
111 pTimer->fSuspended = true;
112 pTimer->fSpecificCpu = !!(fFlags & RTTIMER_FLAGS_CPU_SPECIFIC);
113 pTimer->iCpu = fFlags & RTTIMER_FLAGS_CPU_MASK;
114 pTimer->handle = vbi_timer_create(rtTimerSolarisCallbackWrapper, pTimer, pvUser, u64NanoInterval);
115 pTimer->pfnTimer = pfnTimer;
116 pTimer->iTick = 0;
117
118 *ppTimer = pTimer;
119 return VINF_SUCCESS;
120}
121
122
123/**
124 * Validates the timer handle.
125 *
126 * @returns true if valid, false if invalid.
127 * @param pTimer The handle.
128 */
129DECLINLINE(bool) rtTimerIsValid(PRTTIMER pTimer)
130{
131 AssertReturn(VALID_PTR(pTimer), false);
132 AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, false);
133 return true;
134}
135
136
137RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
138{
139 if (pTimer == NULL)
140 return VINF_SUCCESS;
141 if (!rtTimerIsValid(pTimer))
142 return VERR_INVALID_HANDLE;
143
144 /*
145 * Free the associated resources.
146 */
147 pTimer->u32Magic++;
148 vbi_timer_stop(pTimer->handle);
149 vbi_timer_destroy(pTimer->handle);
150 RTMemFree(pTimer);
151 return VINF_SUCCESS;
152}
153
154
155RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First)
156{
157 if (!rtTimerIsValid(pTimer))
158 return VERR_INVALID_HANDLE;
159 if (!pTimer->fSuspended)
160 return VERR_TIMER_ACTIVE;
161
162 /*
163 * Calc when it should start firing.
164 */
165 pTimer->fSuspended = false;
166 vbi_timer_start(pTimer->handle, u64First);
167
168 return VINF_SUCCESS;
169}
170
171
172RTDECL(int) RTTimerStop(PRTTIMER pTimer)
173{
174 if (!rtTimerIsValid(pTimer))
175 return VERR_INVALID_HANDLE;
176 if (pTimer->fSuspended)
177 return VERR_TIMER_SUSPENDED;
178
179 /*
180 * Suspend the timer.
181 */
182 pTimer->fSuspended = true;
183 vbi_timer_stop(pTimer->handle);
184
185 return VINF_SUCCESS;
186}
187
188
189
190RTDECL(uint32_t) RTTimerGetSystemGranularity(void)
191{
192 return vbi_timer_granularity();
193}
194
195
196RTDECL(int) RTTimerRequestSystemGranularity(uint32_t u32Request, uint32_t *pu32Granted)
197{
198 return VERR_NOT_SUPPORTED;
199}
200
201
202RTDECL(int) RTTimerReleaseSystemGranularity(uint32_t u32Granted)
203{
204 return VERR_NOT_SUPPORTED;
205}
206
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette