apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r1795947 - /apr/apr/branches/1.6.x/locks/unix/misc.c
Date Tue, 23 May 2017 19:14:12 GMT
Author: wrowe
Date: Tue May 23 19:14:12 2017
New Revision: 1795947

URL: http://svn.apache.org/viewvc?rev=1795947&view=rev
Log:
Revert 1790301; was

semtimedop() takes a delta time, so accept what is given as
the "time remaining"

Modified:
    apr/apr/branches/1.6.x/locks/unix/misc.c

Modified: apr/apr/branches/1.6.x/locks/unix/misc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/unix/misc.c?rev=1795947&r1=1795946&r2=1795947&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/unix/misc.c (original)
+++ apr/apr/branches/1.6.x/locks/unix/misc.c Tue May 23 19:14:12 2017
@@ -146,23 +146,41 @@ int sem_timedwait(sem_t * sem, const str
 #if APR_HAS_SYSVSEM_SERIALIZE
 #if !HAVE_SEMTIMEDOP
 extern int semtimedop(int semid, struct sembuf *sops, unsigned nsops,
-                      const struct timespec *timeout);
+                      const struct timespec *abs_timeout);
 /*
  * A semtimedop() impl for OSX/macOS, which lacks the
  * real thing.
  */
 int semtimedop(int semid, struct sembuf *sops, unsigned nsops,
-               const struct timespec *timeout)
+               const struct timespec *abs_timeout)
 {
     int rv;
-    struct timespec remaining, ts;
+    struct timespec remaining, ts, tod;
+    apr_time_t now;
     struct sembuf proc_mutex_op_try;
 
     proc_mutex_op_try.sem_num = 0;
     proc_mutex_op_try.sem_op = -1;
     proc_mutex_op_try.sem_flg = SEM_UNDO | IPC_NOWAIT;
 
-    remaining = *timeout;
+    remaining = *abs_timeout;
+    now = apr_time_now();
+    tod.tv_sec = apr_time_sec(now);
+    tod.tv_nsec = apr_time_usec(now) * 1000;    /* nanoseconds */
+
+    remaining.tv_sec -= tod.tv_sec;
+    if (tod.tv_nsec <= remaining.tv_nsec) {
+        remaining.tv_nsec -= tod.tv_nsec;
+    }
+    else {
+        remaining.tv_sec--;
+        remaining.tv_nsec =
+            (NANOSECS_PER_SEC - (tod.tv_nsec - remaining.tv_nsec));
+    }
+    /* If we had a REALLY small timeout ;) */
+    if (remaining.tv_sec < 0) {
+        return ETIMEDOUT;
+    }
     errno = 0;
     while (((rv = semop(semid, &proc_mutex_op_try, nsops)) != 0)
            && (errno == EAGAIN)) {



Mime
View raw message