perf: Switch from alarm to setitimer for more fine-grained control of timers

This commit is contained in:
Carl Worth 2006-08-31 14:08:43 -07:00
parent 2ebb9af434
commit 6ae6d91c0c
5 changed files with 20 additions and 7 deletions

View file

@ -63,8 +63,21 @@ alarm_handler (int signal) {
}
void
set_alarm (int seconds) {
set_alarm (double seconds) {
struct itimerval tr;
long sec, usec;
cairo_perf_alarm_expired = 0;
signal (SIGALRM, alarm_handler);
alarm (seconds);
sec = floor (seconds);
seconds -= sec;
usec = seconds * 1e6;
tr.it_interval.tv_sec = 0;
tr.it_interval.tv_usec = 0;
tr.it_value.tv_sec = sec;
tr.it_value.tv_usec = usec;
setitimer (ITIMER_REAL, &tr, NULL);
}

View file

@ -64,7 +64,7 @@ alarm_handler (void *closure, DWORD dwTimerLowValue, DWORD dwTimerHighValue) {
HANDLE hTimer = NULL;
void
set_alarm (int seconds) {
set_alarm (double seconds) {
if (hTimer == NULL)
hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
cairo_perf_alarm_expired = 0;

View file

@ -60,6 +60,6 @@ void
alarm_handler (int signal);
void
set_alarm (int seconds);
set_alarm (double seconds);
#endif

View file

@ -27,7 +27,7 @@
#include "cairo-perf.h"
int cairo_perf_duration = 1;
double cairo_perf_duration = 1;
int cairo_perf_iterations = 10;
@ -134,7 +134,7 @@ main (int argc, char *argv[])
stats_t stats;
if (getenv("CAIRO_PERF_DURATION"))
cairo_perf_duration = strtol(getenv("CAIRO_PERF_DURATION"), NULL, 0);
cairo_perf_duration = strtod(getenv("CAIRO_PERF_DURATION"), NULL);
if (getenv("CAIRO_PERF_ITERATIONS"))
cairo_perf_iterations = strtol(getenv("CAIRO_PERF_ITERATIONS"), NULL, 0);

View file

@ -32,7 +32,7 @@
#include "cairo-perf-timer.h"
extern int cairo_perf_duration;
extern double cairo_perf_duration;
extern int cairo_perf_alarm_expired;
#if CAIRO_HAS_WIN32_SURFACE