2009-11-18 Chris Toshok <toshok@ximian.com>
[moon.git] / cairo / perf / cairo-perf-os2.c
blob4cb6447a9df47e2809ba52a57bc95a762faea175
1 /*
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)
30 #define INCL_BASE
31 #include <os2.h>
33 #include "cairo-perf.h"
35 /* timers */
36 typedef struct _cairo_perf_timer
38 /* make them double so that they can store the full QWORD precision */
39 double start;
40 double stop;
41 } cairo_perf_timer_t;
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;
47 void
48 cairo_perf_timer_set_synchronize (cairo_perf_timer_synchronize_t synchronize,
49 void *closure)
51 cairo_perf_timer_synchronize = synchronize;
52 cairo_perf_timer_synchronize_closure = closure;
55 void
56 cairo_perf_timer_start (void) {
57 QWORD time;
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);
65 void
66 cairo_perf_timer_stop (void) {
67 QWORD time;
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);
75 cairo_perf_ticks_t
76 cairo_perf_timer_elapsed (void) {
77 ULONG freq;
79 DosTmrQueryFreq(&freq);
80 /* return time difference in milliseconds */
81 return (timer.stop - timer.start) / freq * 1000;
84 cairo_perf_ticks_t
85 cairo_perf_ticks_per_second (void) {
86 return 1000; /* in ms */
90 /* yield */
91 void
92 cairo_perf_yield (void) {
93 /* try to deactivate this thread until the scheduler calls it again */
94 DosSleep (0);