VirtualBox

source: vbox/trunk/include/iprt/timer.h@ 9433

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

RTTimerCreateEx spec update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/** @file
2 * IPRT - Timer.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_timer_h
31#define ___iprt_timer_h
32
33
34#include <iprt/cdefs.h>
35#include <iprt/types.h>
36
37
38__BEGIN_DECLS
39
40/** @defgroup grp_rt_timer RTTimer - Timer
41 *
42 * The IPRT timer API provides a simple abstraction of recurring and one-shot callback timers.
43 *
44 * Because of the great variation in the native APIs and the quality of
45 * the service delivered by those native APIs, the timers are operated
46 * on at best effort basis.
47 *
48 * All the ring-3 implementations are naturally at the mercy of the scheduler,
49 * which means that the callback rate might vary quite a bit and we might skip
50 * ticks. Many systems have a restriction that a process can only have one
51 * timer. IPRT currently makes no efforts at multiplexing timers in those kind
52 * of situations and will simply fail if you try to create more than one timer.
53 *
54 * Things are generally better in ring-0. The implementations will use interrupt
55 * time callbacks wherever available, and if not, resort to a high priority
56 * kernel thread.
57 *
58 * @ingroup grp_rt
59 * @{
60 */
61
62
63/** Timer handle. */
64typedef struct RTTIMER *PRTTIMER;
65
66/**
67 * Timer callback function.
68 *
69 * The context this call is made in varies with different platforms and
70 * kernel / user mode IPRT.
71 *
72 * In kernel mode a timer callback should not waste time, it shouldn't
73 * waste stack and it should be prepared that some APIs might not work
74 * correctly because of weird OS restrictions in this context that we
75 * haven't discovered and avoided yet. Please fix those APIs so they
76 * at least avoid panics and weird behaviour.
77 *
78 * @param pTimer Timer handle.
79 * @param pvUser User argument.
80 */
81typedef DECLCALLBACK(void) FNRTTIMER(PRTTIMER pTimer, void *pvUser);
82/** Pointer to FNRTTIMER() function. */
83typedef FNRTTIMER *PFNRTTIMER;
84
85
86/**
87 * Create a recurring timer.
88 *
89 * @returns iprt status code.
90 * @param ppTimer Where to store the timer handle.
91 * @param uMilliesInterval Milliseconds between the timer ticks.
92 * This is rounded up to the system granularity.
93 * @param pfnTimer Callback function which shall be scheduled for execution
94 * on every timer tick.
95 * @param pvUser User argument for the callback.
96 * @see RTTimerDestroy, RTTimerStop
97 */
98RTDECL(int) RTTimerCreate(PRTTIMER *ppTimer, unsigned uMilliesInterval, PFNRTTIMER pfnTimer, void *pvUser);
99
100/**
101 * Create a suspended timer.
102 *
103 * @returns iprt status code.
104 * @retval VERR_NOT_SUPPORTED if an unsupported flag was specfied.
105 *
106 * @param ppTimer Where to store the timer handle.
107 * @param u64NanoInterval The interval between timer ticks specified in nanoseconds if it's
108 * a recurring timer. This is rounded to the fit the system timer granularity.
109 * For one shot timers, pass 0.
110 * @param fFlags Timer flags.
111 * @param pfnTimer Callback function which shall be scheduled for execution
112 * on every timer tick.
113 * @param pvUser User argument for the callback.
114 * @see RTTimerStart, RTTimerStop, RTTimerDestroy, RTTimerGetSystemGranularity
115 */
116RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser);
117
118/** @name RTTimerCreateEx flags
119 * @{ */
120/** Any CPU is fine. (Must be 0.) */
121#define RTTIMER_FLAGS_CPU_ANY 0
122/** One specific CPU */
123#define RTTIMER_FLAGS_CPU_SPECIFIC RT_BIT(8)
124/** All online CPUs. */
125#define RTTIMER_FLAGS_CPU_ALL ( RTTIMER_FLAGS_CPU_MASK | RTTIMER_FLAGS_CPU_SPECIFIC )
126/** CPU mask. */
127#define RTTIMER_FLAGS_CPU_MASK 0xff
128/** Convert a CPU number (0-based) to RTTimerCreateEx flags.
129 * This will automatically OR in the RTTIMER_FLAG_CPU_SPECIFIC flag. */
130#define RTTIMER_FLAGS_CPU(iCpu) ( (iCpu) | RTTIMER_FLAG_CPU_SPECIFIC )
131/** Macro that validates the flags. */
132#define RTTIMER_FLAGS_IS_VALID(fFlags) ( !((fFlags) & ((fFlags) & RTTIMER_FLAGS_CPU_SPECIFIC ? 0x1ff : 0x100)) )
133/** @} */
134
135/**
136 * Stops and destroys a running timer.
137 *
138 * @returns iprt status code.
139 * @param pTimer Timer to stop and destroy. NULL is ok.
140 */
141RTDECL(int) RTTimerDestroy(PRTTIMER pTimer);
142
143/**
144 * Stops an active timer.
145 *
146 * @returns IPRT status code.
147 * @retval VERR_INVALID_HANDLE if pTimer isn't valid.
148 * @retval VERR_TIMER_ACTIVE if the timer isn't suspended.
149 *
150 * @param pTimer The timer to activate.
151 * @param u64First The RTTimeSystemNanoTS() for when the timer should start
152 * firing (relative). If 0 is specified, the timer will fire ASAP.
153 * @see RTTimerStop
154 */
155RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First);
156
157/**
158 * Stops an active timer.
159 *
160 * @returns IPRT status code.
161 * @retval VERR_INVALID_HANDLE if pTimer isn't valid.
162 * @retval VERR_TIMER_SUSPENDED if the timer isn't active.
163 * @retval VERR_NOT_SUPPORTED if the IPRT implementation doesn't support stopping a timer.
164 *
165 * @param pTimer The timer to suspend.
166 * @see RTTimerStart
167 */
168RTDECL(int) RTTimerStop(PRTTIMER pTimer);
169
170
171/**
172 * Gets the (current) timer granularity of the system.
173 *
174 * @returns The timer granularity of the system in nanoseconds.
175 * @see RTTimerRequestSystemGranularity
176 */
177RTDECL(uint32_t) RTTimerGetSystemGranularity(void);
178
179/**
180 * Requests a specific system timer granularity.
181 *
182 * Successfull calls to this API must be coupled with the exact same number of
183 * calls to RTTimerReleaseSystemGranularity() in order to undo any changes made.
184 *
185 *
186 * @returns IPRT status code.
187 * @retval VERR_NOT_SUPPORTED if the requested value isn't supported by the host platform
188 * or if the host platform doesn't support modifying the system timer granularity.
189 * @retval VERR_PERMISSION_DENIED if the caller doesn't have the necessary privilege to
190 * modify the system timer granularity.
191 *
192 * @param u32Request The requested system timer granularity in nanoseconds.
193 * @param pu32Granted Where to store the granted system granularity. This is the value
194 * that should be passed to RTTimerReleaseSystemGranularity(). It
195 * is what RTTimerGetSystemGranularity() would return immediately
196 * after the change was made.
197 *
198 * The value differ from the request in two ways; rounding and
199 * scale. Meaning if your request is for 10.000.000 you might
200 * be granted 10.000.055 or 1.000.000.
201 * @see RTTimerReleaseSystemGranularity, RTTimerGetSystemGranularity
202 */
203RTDECL(int) RTTimerRequestSystemGranularity(uint32_t u32Request, uint32_t *pu32Granted);
204
205/**
206 * Releases a system timer granularity grant acquired by RTTimerRequestSystemGranularity().
207 *
208 * @returns IPRT status code.
209 * @retval VERR_NOT_SUPPORTED if the host platform doesn't have any way of modifying
210 * the system timer granularity.
211 * @retval VERR_WRONG_ORDER if nobody call RTTimerRequestSystemGranularity() with the
212 * given grant value.
213 * @param u32Granted The granted system granularity.
214 * @see RTTimerRequestSystemGranularity
215 */
216RTDECL(int) RTTimerReleaseSystemGranularity(uint32_t u32Granted);
217
218/** @} */
219
220__END_DECLS
221
222#endif
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