apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yla...@apache.org
Subject svn commit: r1667962 - in /apr/apr/trunk/locks: beos/ netware/ os2/ unix/ win32/
Date Fri, 20 Mar 2015 09:16:56 GMT
Author: ylavic
Date: Fri Mar 20 09:16:56 2015
New Revision: 1667962

URL: http://svn.apache.org/r1667962
Log:
Follow up to r1667900: handle negative (infinite) timeout in mutex/cond timedlock/timedwait.

Modified:
    apr/apr/trunk/locks/beos/proc_mutex.c
    apr/apr/trunk/locks/beos/thread_mutex.c
    apr/apr/trunk/locks/netware/thread_cond.c
    apr/apr/trunk/locks/netware/thread_mutex.c
    apr/apr/trunk/locks/os2/proc_mutex.c
    apr/apr/trunk/locks/os2/thread_cond.c
    apr/apr/trunk/locks/os2/thread_mutex.c
    apr/apr/trunk/locks/unix/global_mutex.c
    apr/apr/trunk/locks/unix/proc_mutex.c
    apr/apr/trunk/locks/unix/thread_cond.c
    apr/apr/trunk/locks/unix/thread_mutex.c
    apr/apr/trunk/locks/win32/proc_mutex.c
    apr/apr/trunk/locks/win32/thread_cond.c
    apr/apr/trunk/locks/win32/thread_mutex.c

Modified: apr/apr/trunk/locks/beos/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/beos/proc_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/beos/proc_mutex.c (original)
+++ apr/apr/trunk/locks/beos/proc_mutex.c Fri Mar 20 09:16:56 2015
@@ -115,27 +115,28 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
     int32 stat;
 
     if (atomic_add(&mutex->LockCount, 1) > 0) {
-        int flag = 0;
-#ifdef B_ABSOLUTE_TIMEOUT
-        if (timeout) {
-            flag = absolute ? B_ABSOLUTE_TIMEOUT : B_RELATIVE_TIMEOUT;
+        if (timeout < 0) {
+            stat = acquire_sem(mutex->Lock);
         }
-        stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout);
-#else
-        if (absolute) {
-            apr_time_t now = apr_time_now();
-            if (timeout > now) {
-                timeout -= now;
+        else {
+            int flag = 0;
+            if (timeout > 0) {
+                if (absolute) {
+                    apr_time_t now = apr_time_now();
+                    if (timeout > now) {
+                        timeout -= now;
+                    }
+                    else {
+                        timeout = 0;
+                    }
+                    flag = B_ABSOLUTE_TIMEOUT;
+                }
+                else {
+                    flag = B_RELATIVE_TIMEOUT;
+                }
             }
-            else {
-                timeout = 0;
-            }
-        }
-        if (timeout) {
-            flag = B_RELATIVE_TIMEOUT;
+            stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout);
         }
-        stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout);
-#endif
         if (stat < B_NO_ERROR) {
             atomic_add(&mutex->LockCount, -1);
             if (stat == B_TIMED_OUT) {

Modified: apr/apr/trunk/locks/beos/thread_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/beos/thread_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/beos/thread_mutex.c (original)
+++ apr/apr/trunk/locks/beos/thread_mutex.c Fri Mar 20 09:16:56 2015
@@ -116,8 +116,7 @@ APR_DECLARE(apr_status_t) apr_thread_mut
     }
     
     if (atomic_add(&mutex->LockCount, 1) > 0) {
-        if ((stat = acquire_sem_etc(mutex->Lock, 1,
-                                    B_TIMEOUT, 0)) < B_NO_ERROR) {
+        if ((stat = acquire_sem_etc(mutex->Lock, 1, 0, 0)) < B_NO_ERROR) {
             atomic_add(&mutex->LockCount, -1);
             if (stat == B_WOULD_BLOCK) {
                 stat = APR_EBUSY;
@@ -145,24 +144,29 @@ APR_DECLARE(apr_status_t) apr_thread_mut
     }
     
     if (atomic_add(&mutex->LockCount, 1) > 0) {
-#ifdef B_ABSOLUTE_TIMEOUT
-        stat = acquire_sem_etc(mutex->Lock, 1,
-                               absolute ? B_ABSOLUTE_TIMEOUT
-                                        : B_RELATIVE_TIMEOUT,
-                               timeout);
-#else
-        if (absolute) {
-            apr_time_t now = apr_time_now();
-            if (timeout > now) {
-                timeout -= now;
-            }
-            else {
-                timeout = 0;
+        if (timeout < 0) {
+            stat = acquire_sem(mutex->Lock);
+        }
+        else {
+            int flag = 0;
+            if (timeout > 0) {
+                if (absolute) {
+                    apr_time_t now = apr_time_now();
+                    if (timeout > now) {
+                        timeout -= now;
+                    }
+                    else {
+                        timeout = 0;
+                    }
+                    flag = B_ABSOLUTE_TIMEOUT;
+                }
+                else {
+                    flag = B_RELATIVE_TIMEOUT;
+                }
             }
+            stat = acquire_sem_etc(mutex->Lock, 1, flag, timeout);
         }
-        stat = acquire_sem_etc(mutex->Lock, 1, B_TIMEOUT, timeout);
-#endif
-        if (stat  < B_NO_ERROR) {
+        if (stat < B_NO_ERROR) {
             atomic_add(&mutex->LockCount, -1);
             if (stat == B_TIMED_OUT) {
                 stat = APR_TIMEUP;

Modified: apr/apr/trunk/locks/netware/thread_cond.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/netware/thread_cond.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/netware/thread_cond.c (original)
+++ apr/apr/trunk/locks/netware/thread_cond.c Fri Mar 20 09:16:56 2015
@@ -66,10 +66,21 @@ APR_DECLARE(apr_status_t) apr_thread_con
 
 APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
                                                     apr_thread_mutex_t *mutex,
-                                                    apr_interval_time_t timeout){
-    if (NXCondTimedWait(cond->cond, mutex->mutex, 
-        (timeout*1000)/NXGetSystemTick()) == NX_ETIMEDOUT) {
-        return APR_TIMEUP;
+                                                    apr_interval_time_t timeout)
+{
+    int rc;
+    if (timeout < 0) {
+        rc = NXCondWait(cond->cond, mutex->mutex);
+    }
+    else {
+        timeout = timeout * 1000 / XGetSystemTick();
+        rc = NXCondTimedWait(cond->cond, mutex->mutex, timeout);
+        if (rc == NX_ETIMEDOUT) {
+            return APR_TIMEUP;
+        }
+    }
+    if (rc != 0) {
+        return APR_EINTR;
     }
     return APR_SUCCESS;
 }

Modified: apr/apr/trunk/locks/netware/thread_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/netware/thread_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/netware/thread_mutex.c (original)
+++ apr/apr/trunk/locks/netware/thread_mutex.c Fri Mar 20 09:16:56 2015
@@ -119,17 +119,22 @@ APR_DECLARE(apr_status_t) apr_thread_mut
         apr_status_t rv;
         NXLock(mutex->mutex);
         if (mutex->locked) {
-            if (absolute) {
-                apr_time_t now = apr_time_now();
-                if (timeout > now) {
-                    timeout -= now;
-                }
-                else {
-                    timeout = 0;
+            mutex->num_waiters++;
+            if (timeout < 0) {
+                rv = apr_thread_cond_dwait(mutex->cond, mutex);
+            }
+            else {
+                if (absolute) {
+                    apr_time_t now = apr_time_now();
+                    if (timeout > now) {
+                        timeout -= now;
+                    }
+                    else {
+                        timeout = 0;
+                    }
                 }
+                rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout);
             }
-            mutex->num_waiters++;
-            rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout);
             mutex->num_waiters--;
         }
         else {

Modified: apr/apr/trunk/locks/os2/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/os2/proc_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/os2/proc_mutex.c (original)
+++ apr/apr/trunk/locks/os2/proc_mutex.c Fri Mar 20 09:16:56 2015
@@ -162,19 +162,24 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
 {
     ULONG rc;
     
-    if (absolute) {
-        apr_time_t now = apr_time_now();
-        if (timeout > now) {
-            timeout -= now;
-        }
-        else {
-            timeout = 0;
-        }
+    if (timeout < 0) {
+        rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
     }
+    else {
+        if (absolute) {
+            apr_time_t now = apr_time_now();
+            if (timeout > now) {
+                timeout -= now;
+            }
+            else {
+                timeout = 0;
+            }
+        }
 
-    rc = DosRequestMutexSem(mutex->hMutex, apr_time_as_msec(timeout));
-    if (rc == ERROR_TIMEOUT) {
-        return APR_TIMEUP;
+        rc = DosRequestMutexSem(mutex->hMutex, apr_time_as_msec(timeout));
+        if (rc == ERROR_TIMEOUT) {
+            return APR_TIMEUP;
+        }
     }
 
     if (rc == 0) {

Modified: apr/apr/trunk/locks/os2/thread_cond.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/os2/thread_cond.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/os2/thread_cond.c (original)
+++ apr/apr/trunk/locks/os2/thread_cond.c Fri Mar 20 09:16:56 2015
@@ -131,7 +131,8 @@ APR_DECLARE(apr_status_t) apr_thread_con
                                                     apr_thread_mutex_t *mutex,
                                                     apr_interval_time_t timeout)
 {
-    ULONG timeout_ms = apr_time_as_msec(timeout);
+    ULONG timeout_ms = (timeout >= 0) ? apr_time_as_msec(timeout)
+                                      : SEM_INDEFINITE_WAIT;
     return thread_cond_timedwait(cond, mutex, timeout_ms);
 }
 

Modified: apr/apr/trunk/locks/os2/thread_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/os2/thread_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/os2/thread_mutex.c (original)
+++ apr/apr/trunk/locks/os2/thread_mutex.c Fri Mar 20 09:16:56 2015
@@ -82,21 +82,25 @@ APR_DECLARE(apr_status_t) apr_thread_mut
 {
     ULONG rc;
 
-    if (absolute) {
-        apr_time_t now = apr_time_now();
-        if (timeout > now) {
-            timeout -= now;
+    if (timeout < 0) {
+        rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
+    }
+    else {
+        if (absolute) {
+            apr_time_t now = apr_time_now();
+            if (timeout > now) {
+                timeout -= now;
+            }
+            else {
+                timeout = 0;
+            }
         }
-        else {
-            timeout = 0;
+        rc = DosRequestMutexSem(mutex->hMutex, apr_time_as_msec(usec));
+        if (rc == ERROR_TIMEOUT) {
+            return APR_TIMEUP;
         }
     }
 
-    rc = DosRequestMutexSem(mutex->hMutex, apr_time_as_msec(usec));
-    if (rc == ERROR_TIMEOUT) {
-        return APR_TIMEUP;
-    }
-
     return APR_FROM_OS_ERROR(rc);
 }
 

Modified: apr/apr/trunk/locks/unix/global_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/global_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/global_mutex.c (original)
+++ apr/apr/trunk/locks/unix/global_mutex.c Fri Mar 20 09:16:56 2015
@@ -147,7 +147,7 @@ APR_DECLARE(apr_status_t) apr_global_mut
 {
     apr_status_t rv;
 
-    if (!absolute) {
+    if (timeout >= 0 && !absolute) {
         timeout += apr_time_now();
     }
 

Modified: apr/apr/trunk/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/proc_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/proc_mutex.c (original)
+++ apr/apr/trunk/locks/unix/proc_mutex.c Fri Mar 20 09:16:56 2015
@@ -179,19 +179,28 @@ static apr_status_t proc_mutex_posix_tim
                                                   int absolute)
 {
 #if HAVE_SEM_TIMEDWAIT
-    struct timespec abstime;
-
-    if (!absolute) {
-        timeout += apr_time_now();
+    if (timeout < 0) {
+        return proc_mutex_posix_acquire(mutex);
     }
-    abstime.tv_sec = apr_time_sec(timeout);
-    abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
+    else {
+        int rc;
+        struct timespec abstime;
 
-    if (sem_timedwait(mutex->psem_interproc, &abstime) < 0) {
-        if (errno == ETIMEDOUT) {
-            return APR_TIMEUP;
+        if (!absolute) {
+            timeout += apr_time_now();
+        }
+        abstime.tv_sec = apr_time_sec(timeout);
+        abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
+        
+        do {
+            rc = sem_timedwait(mutex->psem_interproc, &abstime);
+        } while (rc < 0 && errno == EINTR);
+        if (rc < 0) {
+            if (errno == ETIMEDOUT) {
+                return APR_TIMEUP;
+            }
+            return errno;
         }
-        return errno;
     }
     mutex->curr_locked = 1;
     return APR_SUCCESS;
@@ -325,24 +334,27 @@ static apr_status_t proc_mutex_sysv_time
                                                  int absolute)
 {
 #if HAVE_SEMTIMEDOP
-    int rc;
-    struct timespec abstime;
-
-    if (!absolute) {
-        timeout += apr_time_now();
+    if (timeout < 0) {
+        return proc_mutex_sysv_acquire(mutex);
     }
-    abstime.tv_sec = apr_time_sec(timeout);
-    abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
-
-    do {
-        rc = semtimedop(mutex->interproc->filedes, &proc_mutex_op_on, 1,
-                        &abstime);
-    } while (rc < 0 && errno == EINTR);
-    if (rc < 0) {
-        if (errno == EAGAIN) {
-            return APR_TIMEUP;
+    else {
+        int rc;
+        struct timespec abstime;
+        if (!absolute) {
+            timeout += apr_time_now();
+        }
+        abstime.tv_sec = apr_time_sec(timeout);
+        abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
+        do {
+            rc = semtimedop(mutex->interproc->filedes, &proc_mutex_op_on, 1,
+                            &abstime);
+        } while (rc < 0 && errno == EINTR);
+        if (rc < 0) {
+            if (errno == EAGAIN) {
+                return APR_TIMEUP;
+            }
+            return errno;
         }
-        return errno;
     }
     mutex->curr_locked = 1;
     return APR_SUCCESS;
@@ -567,7 +579,7 @@ static apr_status_t proc_mutex_proc_pthr
 #endif
     }
     mutex->curr_locked = 1;
-    return rv;
+    return APR_SUCCESS;
 }
 
 static apr_status_t
@@ -575,36 +587,42 @@ proc_mutex_proc_pthread_timedacquire(apr
                                      apr_time_t timeout,
                                      int absolute)
 {
-    apr_status_t rv;
-    struct timespec abstime;
-
-    if (!absolute) {
-        timeout += apr_time_now();
+    if (timeout < 0) {
+        return proc_mutex_proc_pthread_acquire(mutex);
     }
-    abstime.tv_sec = apr_time_sec(timeout);
-    abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
+    else {
+        apr_status_t rv;
+        struct timespec abstime;
 
-    if ((rv = pthread_mutex_timedlock(mutex->pthread_interproc, &abstime))) {
+        if (!absolute) {
+            timeout += apr_time_now();
+        }
+        abstime.tv_sec = apr_time_sec(timeout);
+        abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
+
+        if ((rv = pthread_mutex_timedlock(mutex->pthread_interproc,
+                                          &abstime))) {
 #ifdef HAVE_ZOS_PTHREADS 
-        rv = errno;
+            rv = errno;
 #endif
-        if (rv == ETIMEDOUT) {
-            return APR_TIMEUP;
-        }
+            if (rv == ETIMEDOUT) {
+                return APR_TIMEUP;
+            }
 #ifdef HAVE_PTHREAD_MUTEX_ROBUST
-        /* Okay, our owner died.  Let's try to make it consistent again. */
-        if (rv == EOWNERDEAD) {
-            pthread_mutex_consistent_np(mutex->pthread_interproc);
-            rv = APR_SUCCESS;
-        }
-        else
-            return rv;
+            /* Okay, our owner died.  Let's try to make it consistent again. */
+            if (rv == EOWNERDEAD) {
+                pthread_mutex_consistent_np(mutex->pthread_interproc);
+                rv = APR_SUCCESS;
+            }
+            else
+                return rv;
 #else
-        return rv;
+            return rv;
 #endif
+        }
     }
     mutex->curr_locked = 1;
-    return rv;
+    return APR_SUCCESS;
 }
 
 static apr_status_t proc_mutex_proc_pthread_release(apr_proc_mutex_t *mutex)

Modified: apr/apr/trunk/locks/unix/thread_cond.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/thread_cond.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/thread_cond.c (original)
+++ apr/apr/trunk/locks/unix/thread_cond.c Fri Mar 20 09:16:56 2015
@@ -79,21 +79,31 @@ APR_DECLARE(apr_status_t) apr_thread_con
                                                     apr_interval_time_t timeout)
 {
     apr_status_t rv;
-    apr_time_t then;
-    struct timespec abstime;
+    if (timeout < 0) {
+        rv = pthread_cond_wait(&cond->cond, &mutex->mutex);
+#ifdef HAVE_ZOS_PTHREADS
+        if (rv) {
+            rv = errno;
+        }
+#endif
+    }
+    else {
+        apr_time_t then;
+        struct timespec abstime;
 
-    then = apr_time_now() + timeout;
-    abstime.tv_sec = apr_time_sec(then);
-    abstime.tv_nsec = apr_time_usec(then) * 1000; /* nanoseconds */
+        then = apr_time_now() + timeout;
+        abstime.tv_sec = apr_time_sec(then);
+        abstime.tv_nsec = apr_time_usec(then) * 1000; /* nanoseconds */
 
-    rv = pthread_cond_timedwait(&cond->cond, &mutex->mutex, &abstime);
+        rv = pthread_cond_timedwait(&cond->cond, &mutex->mutex, &abstime);
 #ifdef HAVE_ZOS_PTHREADS
-    if (rv) {
-        rv = errno;
-    }
+        if (rv) {
+            rv = errno;
+        }
 #endif
-    if (ETIMEDOUT == rv) {
-        return APR_TIMEUP;
+        if (ETIMEDOUT == rv) {
+            return APR_TIMEUP;
+        }
     }
     return rv;
 }

Modified: apr/apr/trunk/locks/unix/thread_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/thread_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/unix/thread_mutex.c (original)
+++ apr/apr/trunk/locks/unix/thread_mutex.c Fri Mar 20 09:16:56 2015
@@ -196,21 +196,31 @@ APR_DECLARE(apr_status_t) apr_thread_mut
     apr_status_t rv = APR_ENOTIMPL;
 
 #ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK
-    struct timespec abstime;
-
-    if (!absolute) {
-        timeout += apr_time_now();
+    if (timeout < 0) {
+        rv = pthread_mutex_lock(&mutex->mutex);
+        if (rv) {
+#ifdef HAVE_ZOS_PTHREADS
+            rv = errno;
+#endif
+        }
     }
-    abstime.tv_sec = apr_time_sec(timeout);
-    abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
+    else {
+        struct timespec abstime;
+
+        if (!absolute) {
+            timeout += apr_time_now();
+        }
+        abstime.tv_sec = apr_time_sec(timeout);
+        abstime.tv_nsec = apr_time_usec(timeout) * 1000; /* nanoseconds */
 
-    rv = pthread_mutex_timedlock(&mutex->mutex, &abstime);
-    if (rv) {
+        rv = pthread_mutex_timedlock(&mutex->mutex, &abstime);
+        if (rv) {
 #ifdef HAVE_ZOS_PTHREADS
-        rv = errno;
+            rv = errno;
 #endif
-        if (rv == ETIMEDOUT) {
-            rv = APR_TIMEUP;
+            if (rv == ETIMEDOUT) {
+                rv = APR_TIMEUP;
+            }
         }
     }
 
@@ -228,17 +238,22 @@ APR_DECLARE(apr_status_t) apr_thread_mut
         }
 
         if (mutex->locked) {
-            if (absolute) {
-                apr_time_t now = apr_time_now();
-                if (timeout > now) {
-                    timeout -= now;
-                }
-                else {
-                    timeout = 0;
+            mutex->num_waiters++;
+            if (timeout < 0) {
+                rv = apr_thread_cond_wait(mutex->cond, mutex);
+            }
+            else {
+                if (absolute) {
+                    apr_time_t now = apr_time_now();
+                    if (timeout > now) {
+                        timeout -= now;
+                    }
+                    else {
+                        timeout = 0;
+                    }
                 }
+                rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout);
             }
-            mutex->num_waiters++;
-            rv = apr_thread_cond_timedwait(mutex->cond, mutex, timeout);
             mutex->num_waiters--;
         }
         else {

Modified: apr/apr/trunk/locks/win32/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/win32/proc_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/win32/proc_mutex.c (original)
+++ apr/apr/trunk/locks/win32/proc_mutex.c Fri Mar 20 09:16:56 2015
@@ -166,24 +166,28 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
 {
     DWORD rv;
 
-    if (absolute) {
-        apr_time_t now = apr_time_now();
-        if (timeout > now) {
-            timeout -= now;
+    if (timeout < 0) {
+        rv = WaitForSingleObject(mutex->handle, INFINITE);
+    }
+    else {
+        if (absolute) {
+            apr_time_t now = apr_time_now();
+            if (timeout > now) {
+                timeout -= now;
+            }
+            else {
+                timeout = 0;
+            }
         }
-        else {
-            timeout = 0;
+        rv = WaitForSingleObject(mutex->handle, apr_time_as_msec(timeout));
+        if (rv == WAIT_TIMEOUT) {
+            return APR_TIMEUP;
         }
     }
 
-    rv = WaitForSingleObject(mutex->handle, apr_time_as_msec(timeout));
-
     if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
         return APR_SUCCESS;
     } 
-    else if (rv == WAIT_TIMEOUT) {
-        return APR_TIMEUP;
-    }
     return apr_get_os_error();
 }
 

Modified: apr/apr/trunk/locks/win32/thread_cond.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/win32/thread_cond.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/win32/thread_cond.c (original)
+++ apr/apr/trunk/locks/win32/thread_cond.c Fri Mar 20 09:16:56 2015
@@ -61,9 +61,9 @@ APR_DECLARE(apr_status_t) apr_thread_con
     return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
 }
 
-static APR_INLINE apr_status_t _thread_cond_timedwait(apr_thread_cond_t *cond,
-                                                      apr_thread_mutex_t *mutex,
-                                                      DWORD timeout_ms )
+static APR_INLINE apr_status_t thread_cond_timedwait(apr_thread_cond_t *cond,
+                                                     apr_thread_mutex_t *mutex,
+                                                     DWORD timeout_ms )
 {
     DWORD res;
     apr_status_t rv;
@@ -115,16 +115,15 @@ static APR_INLINE apr_status_t _thread_c
 APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
                                                apr_thread_mutex_t *mutex)
 {
-    return _thread_cond_timedwait(cond, mutex, INFINITE);
+    return thread_cond_timedwait(cond, mutex, INFINITE);
 }
 
 APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
                                                     apr_thread_mutex_t *mutex,
                                                     apr_interval_time_t timeout)
 {
-    DWORD timeout_ms = (DWORD) apr_time_as_msec(timeout);
-
-    return _thread_cond_timedwait(cond, mutex, timeout_ms);
+    DWORD timeout_ms = (timeout >= 0) ? apr_time_as_msec(timeout) : INFINITE;
+    return thread_cond_timedwait(cond, mutex, timeout_ms);
 }
 
 APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)

Modified: apr/apr/trunk/locks/win32/thread_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/win32/thread_mutex.c?rev=1667962&r1=1667961&r2=1667962&view=diff
==============================================================================
--- apr/apr/trunk/locks/win32/thread_mutex.c (original)
+++ apr/apr/trunk/locks/win32/thread_mutex.c Fri Mar 20 09:16:56 2015
@@ -119,19 +119,25 @@ APR_DECLARE(apr_status_t) apr_thread_mut
                                                      int absolute)
 {
     if (mutex->type != thread_mutex_critical_section) {
-        DWORD rv;
-        if (absolute) {
-            apr_time_t now = apr_time_now();
-            if (timeout > now) {
-                timeout -= now;
-            }
-            else {
-                timeout = 0;
+        DWORD rv, timeout_ms;
+        if (timeout < 0) {
+            timeout_ms = INFINITE;
+        }
+        else {
+            if (absolute) {
+                apr_time_t now = apr_time_now();
+                if (timeout > now) {
+                    timeout -= now;
+                }
+                else {
+                    timeout = 0;
+                }
             }
+            timeout_ms = apr_time_as_msec(timeout);
         }
-        rv = WaitForSingleObject(mutex->handle, apr_time_as_msec(timeout));
+        rv = WaitForSingleObject(mutex->handle, timeout_ms);
         if ((rv != WAIT_OBJECT_0) && (rv != WAIT_ABANDONED)) {
-            return (rv == WAIT_TIMEOUT) ? APR_EBUSY : apr_get_os_error();
+            return (rv == WAIT_TIMEOUT) ? APR_TIMEUP : apr_get_os_error();
         }
         return APR_SUCCESS;
     }        



Mime
View raw message