2 * Copyright (c) 2005 SilverStorm Technologies. All rights reserved.
\r
3 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
\r
5 * This software is available to you under the OpenIB.org BSD license
\r
8 * Redistribution and use in source and binary forms, with or
\r
9 * without modification, are permitted provided that the following
\r
10 * conditions are met:
\r
12 * - Redistributions of source code must retain the above
\r
13 * copyright notice, this list of conditions and the following
\r
16 * - Redistributions in binary form must reproduce the above
\r
17 * copyright notice, this list of conditions and the following
\r
18 * disclaimer in the documentation and/or other materials
\r
19 * provided with the distribution.
\r
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
\r
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
36 * Declaration of timer abstraction.
\r
43 #ifndef _CL_TIMER_H_
\r
44 #define _CL_TIMER_H_
\r
47 #include <complib/cl_types.h>
\r
50 /****h* Component Library/Timer
\r
55 * The Timer provides the ability to schedule a function to be invoked at
\r
56 * a given time in the future.
\r
58 * The timer callback function must not perform any blocking operations.
\r
60 * The timer functions operate on a cl_timer_t structure which should be
\r
61 * treated as opaque and should be manipulated only through the provided
\r
69 * cl_pfn_timer_callback_t
\r
72 * cl_timer_construct, cl_timer_init, cl_timer_destroy
\r
75 * cl_timer_start, cl_timer_stop
\r
79 /****d* Component Library: Timer/cl_pfn_timer_callback_t
\r
81 * cl_pfn_timer_callback_t
\r
84 * The cl_pfn_timer_callback_t function type defines the prototype for
\r
85 * functions used to notify users of a timer expiration.
\r
90 (CL_API *cl_pfn_timer_callback_t)(
\r
95 * [in] Value specified in a previous call to cl_timer_init.
\r
98 * This function does not return a value.
\r
101 * This function type is provided as function prototype reference for the
\r
102 * function provided by users as a parameter to the cl_timer_init function.
\r
105 * Timer, cl_timer_init
\r
110 * This include file defines the timer structure, and depends on the timer
\r
111 * callback definition.
\r
113 #include <complib/cl_timer_osd.h>
\r
122 /****f* Component Library: Timer/cl_timer_construct
\r
124 * cl_timer_construct
\r
127 * The cl_timer_construct function initializes the state of a timer.
\r
131 CL_EXPORT void CL_API
\r
132 cl_timer_construct(
\r
133 IN cl_timer_t* const p_timer );
\r
137 * [in] Pointer to a cl_timer_t structure whose state to initialize.
\r
140 * This function does not return a value.
\r
143 * Allows calling cl_timer_destroy without first calling cl_timer_init.
\r
145 * Calling cl_timer_construct is a prerequisite to calling any other
\r
146 * timer function except cl_timer_init.
\r
149 * Timer, cl_timer_init, cl_timer_destroy
\r
153 /****f* Component Library: Timer/cl_timer_init
\r
158 * The cl_timer_init function initializes a timer for use.
\r
162 CL_EXPORT cl_status_t CL_API
\r
164 IN cl_timer_t* const p_timer,
\r
165 IN cl_pfn_timer_callback_t pfn_callback,
\r
166 IN const void* const context );
\r
170 * [in] Pointer to a cl_timer_t structure to initialize.
\r
173 * [in] Address of a callback function to be invoked when a timer expires.
\r
174 * See the cl_pfn_timer_callback_t function type definition for details
\r
175 * about the callback function.
\r
178 * [in] Value to pass to the callback function.
\r
181 * CL_SUCCESS if the timer was successfully initialized.
\r
183 * CL_ERROR otherwise.
\r
186 * Allows calling cl_timer_start and cl_timer_stop.
\r
189 * Timer, cl_timer_construct, cl_timer_destroy, cl_timer_start,
\r
190 * cl_timer_stop, cl_pfn_timer_callback_t
\r
194 /****f* Component Library: Timer/cl_timer_destroy
\r
199 * The cl_timer_destroy function performs any necessary cleanup of a timer.
\r
203 CL_EXPORT void CL_API
\r
205 IN cl_timer_t* const p_timer );
\r
209 * [in] Pointer to a cl_timer_t structure to destroy.
\r
212 * This function does not return a value.
\r
215 * cl_timer_destroy cancels any pending callbacks.
\r
217 * This function should only be called after a call to cl_timer_construct
\r
218 * or cl_timer_init.
\r
221 * Timer, cl_timer_construct, cl_timer_init
\r
225 /****f* Component Library: Timer/cl_timer_start
\r
230 * The cl_timer_start function sets a timer to expire after a given interval.
\r
234 CL_EXPORT cl_status_t CL_API
\r
236 IN cl_timer_t* const p_timer,
\r
237 IN const uint32_t time_ms );
\r
241 * [in] Pointer to a cl_timer_t structure to schedule.
\r
244 * [in] Time, in milliseconds, before the timer should expire.
\r
247 * CL_SUCCESS if the timer was successfully scheduled.
\r
249 * CL_ERROR otherwise.
\r
252 * cl_timer_start implicitly stops the timer before being scheduled.
\r
254 * The interval specified by the time_ms parameter is a minimum interval.
\r
255 * The timer is guaranteed to expire no sooner than the desired interval, but
\r
256 * may take longer to expire.
\r
259 * Timer, cl_timer_stop, cl_timer_trim
\r
263 /****f* Component Library: Timer/cl_timer_stop
\r
268 * The cl_timer_stop function stops a pending timer from expiring.
\r
272 CL_EXPORT void CL_API
\r
274 IN cl_timer_t* const p_timer );
\r
278 * [in] Pointer to a cl_timer_t structure.
\r
281 * This function does not return a value.
\r
284 * Timer, cl_timer_start, cl_timer_trim
\r
288 /****f* Component Library: Timer/cl_timer_trim
\r
293 * The cl_timer_trim function pulls in the absolute expiration
\r
294 * time of a timer if the current expiration time exceeds the specified
\r
297 * sets a timer to expire after a given
\r
298 * interval if that interval is less than the current timer expiration.
\r
302 CL_EXPORT cl_status_t CL_API
\r
304 IN cl_timer_t* const p_timer,
\r
305 IN const uint32_t time_ms );
\r
309 * [in] Pointer to a cl_timer_t structure to schedule.
\r
312 * [in] Maximum time, in milliseconds, before the timer should expire.
\r
315 * CL_SUCCESS if the timer was successfully scheduled.
\r
317 * CL_ERROR otherwise.
\r
320 * cl_timer_trim has no effect if the time interval is greater than the
\r
321 * remaining time when the timer is set.
\r
323 * If the new interval time is less than the remaining time, cl_timer_trim
\r
324 * implicitly stops the timer before reseting it.
\r
326 * If the timer is reset, it is guaranteed to expire no sooner than the
\r
327 * new interval, but may take longer to expire.
\r
330 * Timer, cl_timer_start, cl_timer_stop
\r
334 /****f* Component Library: Time Stamp/cl_get_time_stamp
\r
336 * cl_get_time_stamp
\r
339 * The cl_get_time_stamp function returns the current time stamp in
\r
340 * microseconds since the system was booted.
\r
344 CL_EXPORT uint64_t CL_API
\r
345 cl_get_time_stamp( void );
\r
348 * Time elapsed, in microseconds, since the system was booted.
\r
351 * Timer, cl_get_time_stamp_usec, cl_get_time_stamp_sec
\r
355 /****f* Component Library: Time Stamp/cl_get_time_stamp_usec
\r
357 * cl_get_time_stamp_usec
\r
360 * The cl_get_time_stamp_usec function returns the current time stamp in
\r
361 * microseconds since the system was booted.
\r
365 CL_INLINE uint64_t CL_API
\r
366 cl_get_time_stamp_usec( void )
\r
368 return cl_get_time_stamp();
\r
372 * Time elapsed, in microseconds, since the system was booted.
\r
375 * Timer, cl_get_time_stamp, cl_get_time_stamp_sec
\r
379 /****f* Component Library: Time Stamp/cl_get_time_stamp_sec
\r
381 * cl_get_time_stamp_sec
\r
384 * The cl_get_time_stamp_sec function returns the current time stamp in
\r
385 * seconds since the system was booted.
\r
389 CL_EXPORT uint32_t CL_API
\r
390 cl_get_time_stamp_sec( void );
\r
393 * Time elapsed, in seconds, since the system was booted.
\r
396 * Timer, cl_get_time_stamp
\r
400 /****f* Component Library: Time Stamp/cl_get_tick_count
\r
402 * cl_get_tick_count
\r
405 * The cl_get_tick_count function returns the raw high-resolution
\r
406 * performance counter value.
\r
410 CL_EXPORT uint64_t CL_API
\r
411 cl_get_tick_count( void );
\r
414 * Value of the high-resolution performance counter.
\r
417 * Timer, cl_get_time_stamp, cl_get_frequency
\r
421 /****f* Component Library: Time Stamp/cl_get_frequency
\r
426 * The cl_get_frequency function returns the frequency of the
\r
427 * high-resolution performance counter.
\r
431 CL_EXPORT uint64_t CL_API
\r
432 cl_get_frequency( void );
\r
435 * The frequency of the high-resolution performance counter.
\r
438 * Timer, cl_get_time_stamp, cl_get_tick_count
\r
446 #endif /* _CL_TIMER_H_ */
\r