harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r476121 - /incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c
Date Fri, 17 Nov 2006 12:34:05 GMT
Author: varlax
Date: Fri Nov 17 04:34:05 2006
New Revision: 476121

URL: http://svn.apache.org/viewvc?view=rev&rev=476121
Log:
Applied HARMONY-1669 Classlib test tests/api/java/io/PipedInputStreamTest hangs on Windows
2003.
Did some cleanup in the original patch.
Tested on Win2003

Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c?view=diff&rev=476121&r1=476120&r2=476121
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c Fri Nov
17 04:34:05 2006
@@ -22,9 +22,8 @@
 #include <windows.h>
 #include <stdio.h>
 #include "apr_thread_ext.h"
-//#include "apr_arch_threadproc.h"
+#include <apr_atomic.h>
 
-static int convert_priority(apr_int32_t priority);
 
 APR_DECLARE(apr_status_t) apr_thread_set_priority(apr_thread_t *thread, 
                 apr_int32_t priority) 
@@ -36,38 +35,49 @@
         return status;
     }
     
-    if (SetThreadPriority(*os_thread, (int)convert_priority(priority))) {
+    if (SetThreadPriority(*os_thread, (int)priority)) {
         return APR_SUCCESS;
     } else {
         return apr_get_os_error();
     }
-    
-    
-}
-
-static int convert_priority(apr_int32_t priority) {
-    return (int)priority;
 }
 
 // touch thread to flash memory
 APR_DECLARE(apr_status_t) apr_thread_yield_other(apr_thread_t* thread) {
     HANDLE *os_thread = NULL;
-    apr_status_t status;   
-    if (status = apr_os_thread_get(&((apr_os_thread_t *)os_thread), thread)) {
+    apr_status_t status;  
+
+    static CRITICAL_SECTION *yield_other_mutex = NULL;
+    if (yield_other_mutex == NULL) {
+        CRITICAL_SECTION *cs = malloc(sizeof(CRITICAL_SECTION));
+        InitializeCriticalSectionAndSpinCount(cs, 400);
+        // there should be the only one CS
+        // do nothing if some one else already init it.
+        if(apr_atomic_casptr ((volatile void**)&yield_other_mutex, (void*)cs, NULL))
{
+            DeleteCriticalSection(cs);
+            free(cs);
+        }
+    }
+
+	if (status = apr_os_thread_get(&((apr_os_thread_t *)os_thread), thread)) {
         return status;
     }
-        if(!os_thread) {
-//        printf ("detached thread\n");
-              return status;
-        }
-       //printf("suspending %d\n", *os_thread);
-    if(-1!=SuspendThread(*os_thread)) {
-         ResumeThread(*os_thread);
- //      printf("resuming %d\n", *os_thread);
-        } else {
-  //            printf("fail to suspend %d\n", *os_thread);
-        }
-  return APR_SUCCESS; 
+	if(!os_thread) {
+        return status;
+    }
+
+    /* 
+     * Synchronization is needed to avoid cyclic (mutual) suspension problem.
+     * Accordingly to MSDN, it is possible on multiprocessor box that
+     * 2 threads suspend each other and become deadlocked.
+     */
+    EnterCriticalSection(yield_other_mutex);
+    if(-1 != SuspendThread(*os_thread)) {
+        /* suspended successfully, so resume it back. */
+        ResumeThread(*os_thread);
+    } 
+    LeaveCriticalSection(yield_other_mutex);
+    return APR_SUCCESS; 
 }
 
 APR_DECLARE(void) apr_memory_rw_barrier() {



Mime
View raw message