Workaround 'obsolescent usleep called' cppcheck warning (POSIX)
authorIvan Maidanski <ivmai@mail.ru>
Tue, 7 Mar 2017 16:03:00 +0000 (19:03 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 7 Mar 2017 16:03:00 +0000 (19:03 +0300)
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL]: Include time.h.
* pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL] (GC_stop_world):
Use nanosleep() instead of usleep() if CPPCHECK.

pthread_stop_world.c

index 2c027bc..2be887b 100644 (file)
@@ -44,6 +44,7 @@
 #include <signal.h>
 #include <semaphore.h>
 #include <errno.h>
+#include <time.h> /* for nanosleep() */
 #include <unistd.h>
 
 #include "private/gc_atomic_ops.h"
@@ -770,7 +771,18 @@ GC_INNER void GC_stop_world(void)
           }
           wait_usecs = 0;
         }
-        usleep(WAIT_UNIT);
+
+#       if defined(CPPCHECK) /* || _POSIX_C_SOURCE >= 199309L */
+          {
+            struct timespec ts;
+
+            ts.tv_sec = 0;
+            ts.tv_nsec = WAIT_UNIT * 1000;
+            (void)nanosleep(&ts, NULL);
+          }
+#       else
+          usleep(WAIT_UNIT);
+#       endif
         wait_usecs += WAIT_UNIT;
       }
     }