VirtualBox

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

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

iprt_hdr_h -> _iprt_hdr_h

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