Index: build/win32/apr/include/arch/win32/apr_arch_thread_rwlock.h
===================================================================
--- build/win32/apr/include/arch/win32/apr_arch_thread_rwlock.h	(revision 1597949)
+++ build/win32/apr/include/arch/win32/apr_arch_thread_rwlock.h	(working copy)
@@ -21,7 +21,7 @@
 
 struct apr_thread_rwlock_t {
     apr_pool_t *pool;
-    HANDLE      write_mutex;
+    apr_thread_mutex_t *write_mutex;
     HANDLE      read_event;
     LONG        readers;
 };
Index: build/win32/apr/locks/win32/thread_rwlock.c
===================================================================
--- build/win32/apr/locks/win32/thread_rwlock.c	(revision 1597949)
+++ build/win32/apr/locks/win32/thread_rwlock.c	(working copy)
@@ -28,31 +28,28 @@ static apr_status_t thread_rwlock_cleanup(void *da
     if (! CloseHandle(rwlock->read_event))
         return apr_get_os_error();
 
-    if (! CloseHandle(rwlock->write_mutex))
-        return apr_get_os_error();
-    
-    return APR_SUCCESS;
+    return apr_thread_mutex_destroy(rwlock->write_mutex);
 }
 
 APR_DECLARE(apr_status_t)apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
                                                   apr_pool_t *pool)
 {
+    apr_status_t rv;
     *rwlock = apr_palloc(pool, sizeof(**rwlock));
 
     (*rwlock)->pool        = pool;
     (*rwlock)->readers     = 0;
 
+    rv = apr_thread_mutex_create(&(*rwlock)->write_mutex,
+                                 APR_THREAD_MUTEX_DEFAULT, pool);
+    if (rv != APR_SUCCESS)
+      return rv;
+
     if (! ((*rwlock)->read_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
         *rwlock = NULL;
         return apr_get_os_error();
     }
 
-    if (! ((*rwlock)->write_mutex = CreateMutex(NULL, FALSE, NULL))) {
-        CloseHandle((*rwlock)->read_event);
-        *rwlock = NULL;
-        return apr_get_os_error();
-    }
-
     apr_pool_cleanup_register(pool, *rwlock, thread_rwlock_cleanup,
                               apr_pool_cleanup_null);
 
@@ -60,13 +57,18 @@ APR_DECLARE(apr_status_t)apr_thread_rwlock_create(
 }
 
 static apr_status_t apr_thread_rwlock_rdlock_core(apr_thread_rwlock_t *rwlock,
-                                                  DWORD  milliseconds)
+                                                  int wait)
 {
-    DWORD   code = WaitForSingleObject(rwlock->write_mutex, milliseconds);
+    apr_status_t r;
 
-    if (code == WAIT_FAILED || code == WAIT_TIMEOUT)
-        return APR_FROM_OS_ERROR(code);
+    if (wait)
+        r = apr_thread_mutex_lock(rwlock->write_mutex);
+    else
+        r = apr_thread_mutex_trylock(rwlock->write_mutex);
 
+    if (r != APR_SUCCESS)
+        return r;
+
     /* We've successfully acquired the writer mutex, we can't be locked
      * for write, so it's OK to add the reader lock.  The writer mutex
      * doubles as race condition protection for the readers counter.   
@@ -75,48 +77,56 @@ static apr_status_t apr_thread_rwlock_rdlock_core(
     
     if (! ResetEvent(rwlock->read_event))
         return apr_get_os_error();
-    
-    if (! ReleaseMutex(rwlock->write_mutex))
-        return apr_get_os_error();
-    
-    return APR_SUCCESS;
+
+    return apr_thread_mutex_unlock(rwlock->write_mutex);
 }
 
 APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
 {
-    return apr_thread_rwlock_rdlock_core(rwlock, INFINITE);
+    return apr_thread_rwlock_rdlock_core(rwlock, TRUE);
 }
 
 APR_DECLARE(apr_status_t) 
 apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
 {
-    return apr_thread_rwlock_rdlock_core(rwlock, 0);
+    return apr_thread_rwlock_rdlock_core(rwlock, FALSE);
 }
 
 static apr_status_t 
-apr_thread_rwlock_wrlock_core(apr_thread_rwlock_t *rwlock, DWORD milliseconds)
+apr_thread_rwlock_wrlock_core(apr_thread_rwlock_t *rwlock,
+                              int wait)
 {
-    DWORD   code = WaitForSingleObject(rwlock->write_mutex, milliseconds);
+    apr_status_t r;
 
-    if (code == WAIT_FAILED || code == WAIT_TIMEOUT)
-        return APR_FROM_OS_ERROR(code);
+    if (wait)
+        r = apr_thread_mutex_lock(rwlock->write_mutex);
+    else
+        r = apr_thread_mutex_trylock(rwlock->write_mutex);
 
+    if (r != APR_SUCCESS)
+        return r;
+
     /* We've got the writer lock but we have to wait for all readers to
      * unlock before it's ok to use it.
      */
     if (rwlock->readers) {
+        DWORD code;
+
         /* Must wait for readers to finish before returning, unless this
-         * is an trywrlock (milliseconds == 0):
+         * is an trywrlock:
          */
-        code = milliseconds
-          ? WaitForSingleObject(rwlock->read_event, milliseconds)
+        code = wait
+          ? WaitForSingleObject(rwlock->read_event, INFINITE)
           : WAIT_TIMEOUT;
         
         if (code == WAIT_FAILED || code == WAIT_TIMEOUT) {
             /* Unable to wait for readers to finish, release write lock: */
-            if (! ReleaseMutex(rwlock->write_mutex))
-                return apr_get_os_error();
-            
+
+            r = apr_thread_mutex_unlock(rwlock->write_mutex);
+
+            if (r != APR_SUCCESS)
+                return r;
+
             return APR_FROM_OS_ERROR(code);
         }
     }
@@ -126,12 +136,12 @@ static apr_status_t
 
 APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
 {
-    return apr_thread_rwlock_wrlock_core(rwlock, INFINITE);
+    return apr_thread_rwlock_wrlock_core(rwlock, TRUE);
 }
 
 APR_DECLARE(apr_status_t)apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
 {
-    return apr_thread_rwlock_wrlock_core(rwlock, 0);
+    return apr_thread_rwlock_wrlock_core(rwlock, FALSE);
 }
 
 APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
@@ -138,14 +148,12 @@ APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock
 {
     apr_status_t rv = 0;
 
-    /* First, guess that we're unlocking a writer */
-    if (! ReleaseMutex(rwlock->write_mutex))
-        rv = apr_get_os_error();
-    
-    if (rv == APR_FROM_OS_ERROR(ERROR_NOT_OWNER)) {
+    if (!rwlock->readers) {
+        /* We have a writer lock */
+        rv = apr_thread_mutex_unlock(rwlock->write_mutex);
+    } else {
         /* Nope, we must have a read lock */
-        if (rwlock->readers &&
-            ! InterlockedDecrement(&rwlock->readers) &&
+        if (! InterlockedDecrement(&rwlock->readers) &&
             ! SetEvent(rwlock->read_event)) {
             rv = apr_get_os_error();
         }
