VirtualBox

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

Last change on this file since 2225 was 197, checked in by vboxsync, 18 years ago

A stab at generic timers (untested).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/** @file
2 *
3 * InnoTek Portable Runtime - Timer.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef __iprt_timer_h__
23#define __iprt_timer_h__
24
25
26#include <iprt/cdefs.h>
27#include <iprt/types.h>
28
29
30__BEGIN_DECLS
31
32/** @defgroup grp_rt_timer RTTimer - Timer
33 *
34 * The IPRT timer API provides a simple abstraction of recurring and one-shot callback timers.
35 *
36 * Because of the great variation in the native APIs and the quality of
37 * the service delivered by those native APIs, the timers are operated
38 * on at best effort basis.
39 *
40 * All the ring-3 implementations are naturally at the mercy of the scheduler,
41 * which means that the callback rate might vary quite a bit and we might skip
42 * ticks. Many systems have a restriction that a process can only have one
43 * timer. IPRT currently makes no efforts at multiplexing timers in those kind
44 * of situations and will simply fail if you try to create more than one timer.
45 *
46 * Things are generally better in ring-0. The implementations will use interrupt
47 * time callbacks wherever available, and if not, resort to a high priority
48 * kernel thread.
49 *
50 * @ingroup grp_rt
51 * @{
52 */
53
54
55/** Timer handle. */
56typedef struct RTTIMER *PRTTIMER;
57
58/**
59 * Timer callback function.
60 *
61 * The context this call is made in varies with different platforms and
62 * kernel / user mode IPRT.
63 *
64 * In kernel mode a timer callback should not waste time, it shouldn't
65 * waste stack and it should be prepared that some APIs might not work
66 * correctly because of weird OS restrictions in this context that we
67 * haven't discovered and avoided yet. Please fix those APIs so they
68 * at least avoid panics and weird behaviour.
69 *
70 * @param pTimer Timer handle.
71 * @param pvUser User argument.
72 */
73typedef DECLCALLBACK(void) FNRTTIMER(PRTTIMER pTimer, void *pvUser);
74/** Pointer to FNRTTIMER() function. */
75typedef FNRTTIMER *PFNRTTIMER;
76
77
78/**
79 * Create a recurring timer.
80 *
81 * @returns iprt status code.
82 * @param ppTimer Where to store the timer handle.
83 * @param uMilliesInterval Milliseconds between the timer ticks.
84 * This is rounded up to the system granularity.
85 * @param pfnTimer Callback function which shall be scheduled for execution
86 * on every timer tick.
87 * @param pvUser User argument for the callback.
88 * @see RTTimerDestroy, RTTimerStop
89 */
90RTDECL(int) RTTimerCreate(PRTTIMER *ppTimer, unsigned uMilliesInterval, PFNRTTIMER pfnTimer, void *pvUser);
91
92/**
93 * Create a suspended timer.
94 *
95 * @returns iprt status code.
96 * @param ppTimer Where to store the timer handle.
97 * @param u64NanoInterval The interval between timer ticks specified in nanoseconds if it's
98 * a recurring timer. This is rounded to the fit the system timer granularity.
99 * For one shot timers, pass 0.
100 * @param fFlags Timer flags. No flags has been defined yet, pass 0.
101 * @param pfnTimer Callback function which shall be scheduled for execution
102 * on every timer tick.
103 * @param pvUser User argument for the callback.
104 * @see RTTimerStart, RTTimerStop, RTTimerDestroy, RTTimerGetSystemGranularity
105 */
106RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser);
107
108/**
109 * Stops and destroys a running timer.
110 *
111 * @returns iprt status code.
112 * @param pTimer Timer to stop and destroy. NULL is ok.
113 */
114RTDECL(int) RTTimerDestroy(PRTTIMER pTimer);
115
116/**
117 * Stops an active timer.
118 *
119 * @returns IPRT status code.
120 * @retval VERR_INVALID_HANDLE if pTimer isn't valid.
121 * @retval VERR_TIMER_ACTIVE if the timer isn't suspended.
122 *
123 * @param pTimer The timer to activate.
124 * @param u64First The RTTimeSystemNanoTS() for when the timer should start firing.
125 * If 0 is specified, the timer will fire ASAP.
126 * @see RTTimerStop
127 */
128RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First);
129
130/**
131 * Stops an active timer.
132 *
133 * @returns IPRT status code.
134 * @retval VERR_INVALID_HANDLE if pTimer isn't valid.
135 * @retval VERR_TIMER_SUSPENDED if the timer isn't active.
136 * @retval VERR_NOT_SUPPORTED if the IPRT implementation doesn't support stopping a timer.
137 *
138 * @param pTimer The timer to suspend.
139 * @see RTTimerStart
140 */
141RTDECL(int) RTTimerStop(PRTTIMER pTimer);
142
143
144/**
145 * Gets the (current) timer granularity of the system.
146 *
147 * @returns The timer granularity of the system in nanoseconds.
148 * @see RTTimerRequestSystemGranularity
149 */
150RTDECL(uint32_t) RTTimerGetSystemGranularity(void);
151
152/**
153 * Requests a specific system timer granularity.
154 *
155 * Successfull calls to this API must be coupled with the exact same number of
156 * calls to RTTimerReleaseSystemGranularity() in order to undo any changes made.
157 *
158 *
159 * @returns IPRT status code.
160 * @retval VERR_NOT_SUPPORTED if the requested value isn't supported by the host platform
161 * or if the host platform doesn't support modifying the system timer granularity.
162 * @retval VERR_PERMISSION_DENIED if the caller doesn't have the necessary privilege to
163 * modify the system timer granularity.
164 *
165 * @param u32Request The requested system timer granularity in nanoseconds.
166 * @param pu32Granted Where to store the granted system granularity. This is the value
167 * that should be passed to RTTimerReleaseSystemGranularity(). It
168 * is what RTTimerGetSystemGranularity() would return immediately
169 * after the change was made.
170 *
171 * The value differ from the request in two ways; rounding and
172 * scale. Meaning if your request is for 10.000.000 you might
173 * be granted 10.000.055 or 1.000.000.
174 * @see RTTimerReleaseSystemGranularity, RTTimerGetSystemGranularity
175 */
176RTDECL(int) RTTimerRequestSystemGranularity(uint32_t u32Request, uint32_t *pu32Granted);
177
178/**
179 * Releases a system timer granularity grant acquired by RTTimerRequestSystemGranularity().
180 *
181 * @returns IPRT status code.
182 * @retval VERR_NOT_SUPPORTED if the host platform doesn't have any way of modifying
183 * the system timer granularity.
184 * @retval VERR_WRONG_ORDER if nobody call RTTimerRequestSystemGranularity() with the
185 * given grant value.
186 * @param u32Granted The granted system granularity.
187 * @see RTTimerRequestSystemGranularity
188 */
189RTDECL(int) RTTimerReleaseSystemGranularity(uint32_t u32Granted);
190
191/** @} */
192
193__END_DECLS
194
195#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