Ticket #87: 0002-Workaround-for-systems-lacking-clock_gettime.patch

File 0002-Workaround-for-systems-lacking-clock_gettime.patch, 4.0 KB (added by dmik, 9 years ago)
  • build/configure.ac.system

    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,  
    112112        [AC_CHECK_FUNCS(feenableexcept fedisableexcept feclearexcept)])
    113113
    114114dnl check for misc headers and functions
    115 AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h])
     115AC_CHECK_HEADERS([libgen.h byteswap.h signal.h setjmp.h fenv.h sys/time.h])
    116116AC_CHECK_FUNCS([vasnprintf link ctime_r drand48 flockfile funlockfile ffs])
    117117
    118118dnl check for win32 headers (this detects mingw as well)
  • src/cairo-surface-observer.c

    diff --git a/src/cairo-surface-observer.c b/src/cairo-surface-observer.c
    index 3c4521f..e0cbaa1 100644
    a b  
    4848#include "cairo-surface-subsurface-private.h"
    4949#include "cairo-reference-count-private.h"
    5050
     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
    5161static const cairo_surface_backend_t _cairo_surface_observer_backend;
    5262
    5363/* observation/stats */
    add_record (cairo_observation_t *log,  
    623633    assert (status == CAIRO_INT_STATUS_SUCCESS);
    624634}
    625635
     636#if HAVE_CLOCK_GETTIME
    626637static void
    627 start_timer (struct timespec *ts)
     638start_timer (struct tspec *ts)
    628639{
    629640    clock_gettime (CLOCK_MONOTONIC, ts);
    630641}
    631642
    632643static double
    633 stop_timer (const struct timespec *then)
     644stop_timer (const struct tspec *then)
    634645{
    635     struct timespec now;
     646    struct tspec now;
    636647    double elapsed;
    637648
    638649    clock_gettime (CLOCK_MONOTONIC, &now);
    stop_timer (const struct timespec *then)  
    642653    return elapsed;
    643654}
    644655
     656#else
     657
     658static void
     659start_timer (struct tspec *ts)
     660{
     661    gettimeofday (ts, NULL);
     662}
     663
     664static double
     665stop_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
    645678static void
    646679sync (cairo_surface_t *target, int x, int y)
    647680{
    _cairo_surface_observer_paint (void *abstract_surface,  
    704737    cairo_composite_rectangles_t composite;
    705738    cairo_rectangle_int_t extents;
    706739    cairo_int_status_t status;
    707     struct timespec ts;
     740    struct tspec ts;
    708741    double elapsed;
    709742    int x, y;
    710743
    _cairo_surface_observer_mask (void *abstract_surface,  
    790823    cairo_composite_rectangles_t composite;
    791824    cairo_rectangle_int_t extents;
    792825    cairo_int_status_t status;
    793     struct timespec ts;
     826    struct tspec ts;
    794827    double elapsed;
    795828    int x, y;
    796829
    _cairo_surface_observer_fill (void *abstract_surface,  
    892925    cairo_composite_rectangles_t composite;
    893926    cairo_rectangle_int_t extents;
    894927    cairo_int_status_t status;
    895     struct timespec ts;
     928    struct tspec ts;
    896929    double elapsed;
    897930    int x, y;
    898931
    _cairo_surface_observer_stroke (void *abstract_surface,  
    10071040    cairo_composite_rectangles_t composite;
    10081041    cairo_rectangle_int_t extents;
    10091042    cairo_int_status_t status;
    1010     struct timespec ts;
     1043    struct tspec ts;
    10111044    double elapsed;
    10121045    int x, y;
    10131046
    _cairo_surface_observer_glyphs (void *abstract_surface,  
    11251158    cairo_rectangle_int_t extents;
    11261159    cairo_int_status_t status;
    11271160    cairo_glyph_t *dev_glyphs;
    1128     struct timespec ts;
     1161    struct tspec ts;
    11291162    double elapsed;
    11301163    int x, y;
    11311164