From: stevenj Date: Thu, 15 Jul 2010 21:32:58 +0000 (-0400) Subject: thread-safety in nlopt_seconds(), assuming we have __thread or equivalent X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=af453f18e8c621ac0ac8b06660a26c16811237fd;p=nlopt.git thread-safety in nlopt_seconds(), assuming we have __thread or equivalent darcs-hash:20100715213258-c8de0-d2cdf53cb97a6abc8c587f00d9027851b8ef6d29.gz --- diff --git a/util/timer.c b/util/timer.c index cb2f10b..1795b69 100644 --- a/util/timer.c +++ b/util/timer.c @@ -40,9 +40,9 @@ /* return time in seconds since some arbitrary point in the past */ double nlopt_seconds(void) { - static int start_inited = 0; /* whether start time has been initialized */ + static THREADLOCAL int start_inited = 0; /* whether start time has been initialized */ #if defined(HAVE_GETTIMEOFDAY) - static struct timeval start; + static THREADLOCAL struct timeval start; struct timeval tv; if (!start_inited) { start_inited = 1; @@ -53,7 +53,7 @@ double nlopt_seconds(void) #elif defined(HAVE_TIME) return time(NULL); #elif defined(_WIN32) || defined(__WIN32__) - static ULONGLONG start; + static THREADLOCAL ULONGLONG start; FILETIME ft; if (!start_inited) { start_inited = 1; @@ -65,7 +65,7 @@ double nlopt_seconds(void) #else /* use clock() as a fallback... this is somewhat annoying because clock() may wrap around with a fairly short period */ - static clock_t start; + static THREADLOCAL clock_t start; if (!start_inited) { start_inited = 1; start = clock();