This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: fix in _Jv_CondWait


This patch fixes an apparent bug in the pthreads _Jv_CondWait.
Without this patch, a previously interrupted call will fail to remove
the thread from the cv's wait set.

Bryce, does this patch look ok to you?

2000-09-26  Tom Tromey  <tromey@cygnus.com>

	* posix-threads.cc (_Jv_CondWait): Check to see if we are
	interrupted before modifying the cv's wait set.

Tom

Index: posix-threads.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/posix-threads.cc,v
retrieving revision 1.20
diff -u -r1.20 posix-threads.cc
--- posix-threads.cc	2000/09/07 12:09:40	1.20
+++ posix-threads.cc	2000/09/26 23:36:35
@@ -1,6 +1,6 @@
 // posix-threads.cc - interface between libjava and POSIX threads.
 
-/* Copyright (C) 1998, 1999  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -104,6 +104,16 @@
   _Jv_Thread_t *current = _Jv_ThreadCurrentData ();
   java::lang::Thread *current_obj = _Jv_ThreadCurrent ();
 
+  pthread_mutex_lock (&current->wait_mutex);
+
+  // Now that we hold the wait mutex, check if this thread has been 
+  // interrupted already.
+  if (current_obj->interrupt_flag)
+    {
+      pthread_mutex_unlock (&current->wait_mutex);
+      return _JV_INTERRUPTED;
+    }
+
   // Add this thread to the cv's wait set.
   current->next = NULL;
 
@@ -118,16 +128,6 @@
             break;
           }
       }
-
-  pthread_mutex_lock (&current->wait_mutex);
-  
-  // Now that we hold the wait mutex, check if this thread has been 
-  // interrupted already.
-  if (current_obj->interrupt_flag)
-    {
-      pthread_mutex_unlock (&current->wait_mutex);
-      return _JV_INTERRUPTED;
-    }
 
   // Record the current lock depth, so it can be restored when we re-aquire it.
   int count = mu->count;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]