chiark / gitweb /
thread-safety in nlopt_seconds(), assuming we have __thread or equivalent
authorstevenj <stevenj@alum.mit.edu>
Thu, 15 Jul 2010 21:32:58 +0000 (17:32 -0400)
committerstevenj <stevenj@alum.mit.edu>
Thu, 15 Jul 2010 21:32:58 +0000 (17:32 -0400)
darcs-hash:20100715213258-c8de0-d2cdf53cb97a6abc8c587f00d9027851b8ef6d29.gz

util/timer.c

index cb2f10bda8523f5bf9b4443e49c0df01e969f81a..1795b6909708d8328ba7c06e6bd4e19f66d40963 100644 (file)
@@ -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();