From 0bcb5e4257a1e3bda4c602a6ca7683c6a79fa063 Mon Sep 17 00:00:00 2001
From: Dave Yeo <dave.r.yeo@gmail.com>
Date: Tue, 30 Aug 2011 19:28:27 -0700
Subject: [PATCH 2/5] Workaround for systems lacking clock_gettime()
Fall back to gettimeofday() when system is missing clock_gettime().
Also include sys/time.h for systems such as OS/2 where the timeval struct is
located there.
Signed-off-by: Dave Yeo <dave.r.yeo@gmail.com>
---
build/configure.ac.system | 2 +-
src/cairo-surface-observer.c | 49 ++++++++++++++++++++++++++++++++++++--------
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/build/configure.ac.system b/build/configure.ac.system
index b405740..f3d5483 100644
a
|
b
|
AC_CHECK_HEADER(fenv.h,
|
112 | 112 | [AC_CHECK_FUNCS(feenableexcept fedisableexcept feclearexcept)]) |
113 | 113 | |
114 | 114 | dnl check for misc headers and functions |
115 | | AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h]) |
| 115 | AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h sys/time.h]) |
116 | 116 | AC_CHECK_FUNCS([vasnprintf link ctime_r drand48 flockfile funlockfile ffs]) |
117 | 117 | |
118 | 118 | dnl check for win32 headers (this detects mingw as well) |
diff --git a/src/cairo-surface-observer.c b/src/cairo-surface-observer.c
index 3c4521f..e0cbaa1 100644
a
|
b
|
|
48 | 48 | #include "cairo-surface-subsurface-private.h" |
49 | 49 | #include "cairo-reference-count-private.h" |
50 | 50 | |
| 51 | #if HAVE_SYS_TIME_H |
| 52 | #include <sys/time.h> |
| 53 | #endif |
| 54 | |
| 55 | #if HAVE_CLOCK_TIME |
| 56 | #define tspec timespec |
| 57 | #else |
| 58 | #define tspec timeval |
| 59 | #endif |
| 60 | |
51 | 61 | static const cairo_surface_backend_t _cairo_surface_observer_backend; |
52 | 62 | |
53 | 63 | /* observation/stats */ |
… |
… |
add_record (cairo_observation_t *log,
|
623 | 633 | assert (status == CAIRO_INT_STATUS_SUCCESS); |
624 | 634 | } |
625 | 635 | |
| 636 | #if HAVE_CLOCK_GETTIME |
626 | 637 | static void |
627 | | start_timer (struct timespec *ts) |
| 638 | start_timer (struct tspec *ts) |
628 | 639 | { |
629 | 640 | clock_gettime (CLOCK_MONOTONIC, ts); |
630 | 641 | } |
631 | 642 | |
632 | 643 | static double |
633 | | stop_timer (const struct timespec *then) |
| 644 | stop_timer (const struct tspec *then) |
634 | 645 | { |
635 | | struct timespec now; |
| 646 | struct tspec now; |
636 | 647 | double elapsed; |
637 | 648 | |
638 | 649 | clock_gettime (CLOCK_MONOTONIC, &now); |
… |
… |
stop_timer (const struct timespec *then)
|
642 | 653 | return elapsed; |
643 | 654 | } |
644 | 655 | |
| 656 | #else |
| 657 | |
| 658 | static void |
| 659 | start_timer (struct tspec *ts) |
| 660 | { |
| 661 | gettimeofday (ts, NULL); |
| 662 | } |
| 663 | |
| 664 | static double |
| 665 | stop_timer (const struct tspec *then) |
| 666 | { |
| 667 | struct tspec now; |
| 668 | double elapsed; |
| 669 | |
| 670 | gettimeofday (&now, NULL); |
| 671 | |
| 672 | elapsed = now.tv_usec - then->tv_usec; |
| 673 | elapsed += 1e6 * (now.tv_sec - then->tv_sec); |
| 674 | return elapsed; |
| 675 | } |
| 676 | #endif |
| 677 | |
645 | 678 | static void |
646 | 679 | sync (cairo_surface_t *target, int x, int y) |
647 | 680 | { |
… |
… |
_cairo_surface_observer_paint (void *abstract_surface,
|
704 | 737 | cairo_composite_rectangles_t composite; |
705 | 738 | cairo_rectangle_int_t extents; |
706 | 739 | cairo_int_status_t status; |
707 | | struct timespec ts; |
| 740 | struct tspec ts; |
708 | 741 | double elapsed; |
709 | 742 | int x, y; |
710 | 743 | |
… |
… |
_cairo_surface_observer_mask (void *abstract_surface,
|
790 | 823 | cairo_composite_rectangles_t composite; |
791 | 824 | cairo_rectangle_int_t extents; |
792 | 825 | cairo_int_status_t status; |
793 | | struct timespec ts; |
| 826 | struct tspec ts; |
794 | 827 | double elapsed; |
795 | 828 | int x, y; |
796 | 829 | |
… |
… |
_cairo_surface_observer_fill (void *abstract_surface,
|
892 | 925 | cairo_composite_rectangles_t composite; |
893 | 926 | cairo_rectangle_int_t extents; |
894 | 927 | cairo_int_status_t status; |
895 | | struct timespec ts; |
| 928 | struct tspec ts; |
896 | 929 | double elapsed; |
897 | 930 | int x, y; |
898 | 931 | |
… |
… |
_cairo_surface_observer_stroke (void *abstract_surface,
|
1007 | 1040 | cairo_composite_rectangles_t composite; |
1008 | 1041 | cairo_rectangle_int_t extents; |
1009 | 1042 | cairo_int_status_t status; |
1010 | | struct timespec ts; |
| 1043 | struct tspec ts; |
1011 | 1044 | double elapsed; |
1012 | 1045 | int x, y; |
1013 | 1046 | |
… |
… |
_cairo_surface_observer_glyphs (void *abstract_surface,
|
1125 | 1158 | cairo_rectangle_int_t extents; |
1126 | 1159 | cairo_int_status_t status; |
1127 | 1160 | cairo_glyph_t *dev_glyphs; |
1128 | | struct timespec ts; |
| 1161 | struct tspec ts; |
1129 | 1162 | double elapsed; |
1130 | 1163 | int x, y; |
1131 | 1164 | |