You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2017/05/23 19:18:46 UTC

svn commit: r1795949 - in /apr/apr/branches/1.6.x: CHANGES locks/unix/misc.c locks/unix/proc_mutex.c

Author: wrowe
Date: Tue May 23 19:18:46 2017
New Revision: 1795949

URL: http://svn.apache.org/viewvc?rev=1795949&view=rev
Log:
Revert 1790159, 1790156, 1790155

userland change... the timedacquire stuff

format onlt

and the rest of the timedacquires


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

Modified: apr/apr/branches/1.6.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/CHANGES?rev=1795949&r1=1795948&r2=1795949&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.6.x/CHANGES [utf-8] Tue May 23 19:18:46 2017
@@ -4,10 +4,6 @@ Changes for APR 1.6.1
 
 Changes for APR 1.6.0
 
-  *) locks: provide portable implementations of timedlock()s for
-     posix-sems, sysv-sems and pthreads for those platforms that
-     lack native versions (eg: OSX/macOS). [Jim Jagielski]
-
   *) apr_allocator: Provide apr_allocator_align() to get the true size that
      would be allocated for the given size (including the header and
      alignment).  [Yann Ylavic]

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=1795949&r1=1795948&r2=1795949&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:18:46 2017
@@ -18,194 +18,61 @@
 #include "apr_arch_thread_mutex.h"
 #define APR_WANT_MEMFUNC
 #include "apr_want.h"
-
+#include <stdio.h>
 #if APR_HAS_THREADS
-#if APR_HAS_SYSVSEM_SERIALIZE
-#if !HAVE_SEMTIMEDOP
-#include <sys/sem.h>
-#endif
-#endif
-#define SLEEP_TIME_NS      10000000
-#define NANOSECS_PER_SEC 1000000000
-extern int errno;
 
 #ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
-extern int pthread_mutex_timedlock(pthread_mutex_t * mutex,
-                                   const struct timespec *abs_timeout);
-/*
- * A pthread_mutex_timedlock() impl for OSX/macOS, which lacks the
- * real thing.
- * NOTE: Unlike the real McCoy, won't return EOWNERDEAD, EDEADLK
- *       or EOWNERDEAD
- */
-int pthread_mutex_timedlock(pthread_mutex_t * mutex,
-                            const struct timespec *abs_timeout)
-{
-    int rv;
-    struct timespec remaining, ts, tod;
-    apr_time_t now;
-
-    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;
-    }
-    while ((rv = pthread_mutex_trylock(mutex)) == EBUSY) {
-        ts.tv_sec = 0;
-        ts.tv_nsec = (remaining.tv_sec > 0 ? SLEEP_TIME_NS :
-                      (remaining.tv_nsec <
-                       SLEEP_TIME_NS ? remaining.tv_nsec : SLEEP_TIME_NS));
-        nanosleep(&ts, &ts);
-        if (ts.tv_nsec <= remaining.tv_nsec) {
-            remaining.tv_nsec -= ts.tv_nsec;
-        }
-        else {
-            remaining.tv_sec--;
-            remaining.tv_nsec =
-                (NANOSECS_PER_SEC - (ts.tv_nsec - remaining.tv_nsec));
-        }
-        if (remaining.tv_sec < 0
-            || (!remaining.tv_sec && remaining.tv_nsec <= SLEEP_TIME_NS)) {
-            return ETIMEDOUT;
-        }
-    }
-
-    return rv;
-}
-#endif /* HAVE_PTHREAD_MUTEX_TIMEDLOCK */
-
-#if APR_HAS_POSIXSEM_SERIALIZE
-#if !HAVE_SEM_TIMEDWAIT
-extern int sem_timedwait(sem_t * sem, const struct timespec *abs_timeout);
-/*
- * A sem_timedwait() impl for OSX/macOS, which lacks the
- * real thing.
- */
-int sem_timedwait(sem_t * sem, const struct timespec *abs_timeout)
-{
-    int rv;
-    struct timespec remaining, ts, tod;
-    apr_time_t now;
-
-    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 = sem_trywait(sem)) != 0) && (errno == EAGAIN)) {
-        ts.tv_sec = 0;
-        ts.tv_nsec = (remaining.tv_sec > 0 ? SLEEP_TIME_NS :
-                      (remaining.tv_nsec <
-                       SLEEP_TIME_NS ? remaining.tv_nsec : SLEEP_TIME_NS));
-        nanosleep(&ts, &ts);
-        if (ts.tv_nsec <= remaining.tv_nsec) {
-            remaining.tv_nsec -= ts.tv_nsec;
-        }
-        else {
-            remaining.tv_sec--;
-            remaining.tv_nsec =
-                (NANOSECS_PER_SEC - (ts.tv_nsec - remaining.tv_nsec));
-        }
-        if (remaining.tv_sec < 0
-            || (!remaining.tv_sec && remaining.tv_nsec <= SLEEP_TIME_NS)) {
-            return ETIMEDOUT;
-        }
-    }
-    return rv;
-}
-#endif /* HAVE_SEM_TIMEDWAIT */
-#endif /* APR_HAS_POSIXSEM_SERIALIZE */
-
-#if APR_HAS_SYSVSEM_SERIALIZE
-#if !HAVE_SEMTIMEDOP
-extern int semtimedop(int semid, struct sembuf *sops, unsigned nsops,
-                      const struct timespec *abs_timeout);
+extern int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout);
+#define SLEEP_TIME_NS      10000000
+#define NANOSECS_PER_SEC 1000000000
 /*
- * A semtimedop() impl for OSX/macOS, which lacks the
- * real thing.
- */
-int semtimedop(int semid, struct sembuf *sops, unsigned nsops,
-               const struct timespec *abs_timeout)
+* A pthread_mutex_timedlock() impl for OSX/macOS, which lacks the
+* real thing.
+* NOTE: Unlike the real McCoy, won't return EOWNERDEAD, EDEADLK
+*       or EOWNERDEAD
+*/
+int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abs_timeout)
 {
-    int rv;
-    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 = *abs_timeout;
-    now = apr_time_now();
-    tod.tv_sec = apr_time_sec(now);
-    tod.tv_nsec = apr_time_usec(now) * 1000;    /* nanoseconds */
+   int rv;
+   struct timespec remaining, ts, tod;
+   apr_time_t now;
+
+   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 pthread_mutex_trylock(mutex);
+   }
+   while ((rv = pthread_mutex_trylock(mutex)) == EBUSY) {
+       ts.tv_sec = 0;
+       ts.tv_nsec = (remaining.tv_sec > 0 ? SLEEP_TIME_NS : 
+                    (remaining.tv_nsec < SLEEP_TIME_NS ? remaining.tv_nsec : SLEEP_TIME_NS));
+       nanosleep(&ts, &ts);
+       if (ts.tv_nsec <= remaining.tv_nsec) {
+           remaining.tv_nsec -= ts.tv_nsec;
+       }
+       else {
+           remaining.tv_sec--;
+           remaining.tv_nsec = (NANOSECS_PER_SEC - (ts.tv_nsec - remaining.tv_nsec));
+       }
+       if (remaining.tv_sec < 0 || (!remaining.tv_sec && remaining.tv_nsec <= SLEEP_TIME_NS)) {
+           return ETIMEDOUT;
+       }
+   }
 
-    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)) {
-        ts.tv_sec = 0;
-        ts.tv_nsec = (remaining.tv_sec > 0 ? SLEEP_TIME_NS :
-                      (remaining.tv_nsec <
-                       SLEEP_TIME_NS ? remaining.tv_nsec : SLEEP_TIME_NS));
-        nanosleep(&ts, &ts);
-        if (ts.tv_nsec <= remaining.tv_nsec) {
-            remaining.tv_nsec -= ts.tv_nsec;
-        }
-        else {
-            remaining.tv_sec--;
-            remaining.tv_nsec =
-                (NANOSECS_PER_SEC - (ts.tv_nsec - remaining.tv_nsec));
-        }
-        if (remaining.tv_sec < 0
-            || (!remaining.tv_sec && remaining.tv_nsec <= SLEEP_TIME_NS)) {
-            return ETIMEDOUT;
-        }
-    }
-    return rv;
+   return rv;
 }
-#endif /* HAVE_SEMTIMEDOP */
-#endif /* APR_HAS_SYSVSEM_SERIALIZE */
-
 
+#endif /* HAVE_PTHREAD_MUTEX_TIMEDLOCK */
 #endif /* APR_HAS_THREADS */

Modified: apr/apr/branches/1.6.x/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/locks/unix/proc_mutex.c?rev=1795949&r1=1795948&r2=1795949&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/locks/unix/proc_mutex.c (original)
+++ apr/apr/branches/1.6.x/locks/unix/proc_mutex.c Tue May 23 19:18:46 2017
@@ -187,9 +187,7 @@ static apr_status_t proc_mutex_posix_tim
                                                   apr_time_t timeout,
                                                   int absolute)
 {
-#if !HAVE_SEM_TIMEDWAIT
-extern int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
-#endif
+#if HAVE_SEM_TIMEDWAIT
     if (timeout < 0) {
         return proc_mutex_posix_acquire(mutex);
     }
@@ -215,6 +213,9 @@ extern int sem_timedwait(sem_t *sem, con
     }
     mutex->curr_locked = 1;
     return APR_SUCCESS;
+#else
+    return APR_ENOTIMPL;
+#endif
 }
 
 static apr_status_t proc_mutex_posix_release(apr_proc_mutex_t *mutex)
@@ -341,10 +342,7 @@ static apr_status_t proc_mutex_sysv_time
                                                  apr_time_t timeout,
                                                  int absolute)
 {
-#if !HAVE_SEMTIMEDOP
-extern int semtimedop(int semid, struct sembuf *sops, unsigned nsops,
-                      const struct timespec *abs_timeout);
-#endif
+#if HAVE_SEMTIMEDOP
     if (timeout < 0) {
         return proc_mutex_sysv_acquire(mutex);
     }
@@ -369,6 +367,9 @@ extern int semtimedop(int semid, struct
     }
     mutex->curr_locked = 1;
     return APR_SUCCESS;
+#else
+    return APR_ENOTIMPL;
+#endif
 }
 
 static apr_status_t proc_mutex_sysv_release(apr_proc_mutex_t *mutex)
@@ -1220,9 +1221,11 @@ static apr_status_t proc_mutex_choose_me
 #if APR_HAS_PROC_PTHREAD_SERIALIZE \
             && defined(HAVE_PTHREAD_MUTEX_ROBUST)
         new_mutex->meth = &mutex_proc_pthread_methods;
-#elif APR_HAS_SYSVSEM_SERIALIZE
+#elif APR_HAS_SYSVSEM_SERIALIZE \
+            && defined(HAVE_SEMTIMEDOP)
         new_mutex->meth = &mutex_sysv_methods;
-#elif APR_HAS_POSIXSEM_SERIALIZE
+#elif APR_HAS_POSIXSEM_SERIALIZE \
+            && defined(HAVE_SEM_TIMEDWAIT)
         new_mutex->meth = &mutex_posixsem_methods;
 #else
         return APR_ENOTIMPL;