2 * Copyright (c) 2007 Netlabs
3 * Copyright (c) 2006 Mozilla Corporation
4 * Copyright (c) 2006 Red Hat, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without
8 * fee, provided that the above copyright notice appear in all copies
9 * and that both that copyright notice and this permission notice
10 * appear in supporting documentation, and that the name of
11 * the authors not be used in advertising or publicity pertaining to
12 * distribution of the software without specific, written prior
13 * permission. The authors make no representations about the
14 * suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
20 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
23 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * Authors: Peter Weilbacher <mozilla@weilbacher.org>
26 * Vladimir Vukicevic <vladimir@pobox.com> (win32/linux code)
27 * Carl Worth <cworth@cworth.org> (win32/linux code)
33 #include "cairo-perf.h"
36 typedef struct _cairo_perf_timer
38 /* make them double so that they can store the full QWORD precision */
43 static cairo_perf_timer_t timer
;
45 static cairo_perf_timer_synchronize_t cairo_perf_timer_synchronize
= NULL
;
46 static void *cairo_perf_timer_synchronize_closure
= NULL
;
48 cairo_perf_timer_set_synchronize (cairo_perf_timer_synchronize_t synchronize
,
51 cairo_perf_timer_synchronize
= synchronize
;
52 cairo_perf_timer_synchronize_closure
= closure
;
56 cairo_perf_timer_start (void) {
59 if (cairo_perf_timer_synchronize
)
60 cairo_perf_timer_synchronize (cairo_perf_timer_synchronize_closure
);
61 DosTmrQueryTime(&time
);
62 timer
.start
= (time
.ulHi
*4294967296.0 + time
.ulLo
);
66 cairo_perf_timer_stop (void) {
69 if (cairo_perf_timer_synchronize
)
70 cairo_perf_timer_synchronize (cairo_perf_timer_synchronize_closure
);
71 DosTmrQueryTime(&time
);
72 timer
.stop
= (time
.ulHi
*4294967296.0 + time
.ulLo
);
76 cairo_perf_timer_elapsed (void) {
79 DosTmrQueryFreq(&freq
);
80 /* return time difference in milliseconds */
81 return (timer
.stop
- timer
.start
) / freq
* 1000;
85 cairo_perf_ticks_per_second (void) {
86 return 1000; /* in ms */
92 cairo_perf_yield (void) {
93 /* try to deactivate this thread until the scheduler calls it again */