]> granicus.if.org Git - gc/commitdiff
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>
Thu, 6 Apr 2017 08:31:24 +0000 (11:31 +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 2cb9b76ceb86ef6ccdbe370148c6bc1d3a092996..72efbf0701c113872e2d298a6def9d78ca39e5ba 100644 (file)
@@ -44,6 +44,7 @@
 #include <signal.h>
 #include <semaphore.h>
 #include <errno.h>
+#include <time.h> /* for nanosleep() */
 #include <unistd.h>
 #include "atomic_ops.h"
 
@@ -769,7 +770,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;
       }
     }