From 3feba75a3ce93756113c01cb5279f1d8d029fec1 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 6 Jan 2015 00:44:05 +0100 Subject: [PATCH] zzuf: replace a critical section with a simple spinlock. --- src/timer.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/timer.c b/src/timer.c index 551a84a..721362d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -39,24 +39,15 @@ int64_t _zz_time(void) gettimeofday(&tv, NULL); return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; #else - /* FIXME: use a simple spinlock here instead */ - static CRITICAL_SECTION cs; - static unsigned long int prev; - static int64_t tv_base = 0; + static zz_mutex mutex = 0; + static unsigned long int prev = 0; - if (tv_base == 0) - { - tv_base = 1; - prev = 0; - InitializeCriticalSection(&cs); - } - - EnterCriticalSection(&cs); + zz_lock(&mutex); unsigned long int tv_msec = GetTickCount(); if (tv_msec < prev) tv_base += 0x100000000LL; /* We wrapped */ prev = tv_msec; - LeaveCriticalSection(&cs); + zz_unlock(&mutex); return (tv_base + tv_msec) * 1000; #endif