You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2021/11/26 18:15:24 UTC

svn commit: r1895361 - in /apr/apr/trunk: configure.in time/unix/time.c

Author: ylavic
Date: Fri Nov 26 18:15:23 2021
New Revision: 1895361

URL: http://svn.apache.org/viewvc?rev=1895361&view=rev
Log:
apr_sleep: use nanosleep() when available.


Modified:
    apr/apr/trunk/configure.in
    apr/apr/trunk/time/unix/time.c

Modified: apr/apr/trunk/configure.in
URL: http://svn.apache.org/viewvc/apr/apr/trunk/configure.in?rev=1895361&r1=1895360&r2=1895361&view=diff
==============================================================================
--- apr/apr/trunk/configure.in (original)
+++ apr/apr/trunk/configure.in Fri Nov 26 18:15:23 2021
@@ -802,6 +802,10 @@ case $host in
        ;;
 esac
 
+AC_CHECK_HEADERS([time.h])
+AC_CHECK_FUNCS([nanosleep])
+AC_SEARCH_LIBS(nanosleep, rt)
+
 dnl ----------------------------- Checking for Threads
 AC_MSG_NOTICE([${nl}Checking for Threads...])
 

Modified: apr/apr/trunk/time/unix/time.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/time/unix/time.c?rev=1895361&r1=1895360&r2=1895361&view=diff
==============================================================================
--- apr/apr/trunk/time/unix/time.c (original)
+++ apr/apr/trunk/time/unix/time.c Fri Nov 26 18:15:23 2021
@@ -242,6 +242,11 @@ APR_DECLARE(void) apr_sleep(apr_interval
     snooze(t);
 #elif defined(NETWARE)
     delay(t/1000);
+#elif defined(HAVE_NANOSLEEP)
+    struct timespec ts;
+    ts.tv_sec = t / APR_USEC_PER_SEC; 
+    ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000;
+    nanosleep(&ts, NULL);
 #else
     struct timeval tv;
     tv.tv_usec = t % APR_USEC_PER_SEC;