This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

[RFA] Suspend counting for JDWP


Hi,

So now all the pieces are in place to implement _Jv_ThreadDebug*. The attached patch does this for POSIX threads only. Win32 and whatever threading system supported by gij will need implementing eventually.

Keith

ChangeLog
2006-06-26  Keith Seitz  <keiths@redhat.com>

        * include/posix-threads.h (_Jv_Thread_t): Add mutex and
        count for JDWP suspend counting.
        * posix-threads.cc (_Jv_ThreadInitData): Initialize suspend
        couont mutex and initial count.
        (_Jv_ThreadDestroyData): Destroy suspend count mutex.
        (_Jv_ThreadDebugResume): Implement.
        (_Jv_ThreadDebugSuspendCount): Likewise.
        (_Jv_ThreadDebugSuspend): Likewise.


Index: include/posix-threads.h
===================================================================
--- include/posix-threads.h	(revision 115021)
+++ include/posix-threads.h	(working copy)
@@ -40,6 +40,10 @@
   pthread_cond_t wait_cond;
   pthread_mutex_t wait_mutex;
 
+  // Suspend count support for JDWP
+  pthread_mutex_t suspend_count_mutex;
+  jint suspend_count;
+
   // Next thread for Condition Variable wait-list chain.
   _Jv_Thread_t *next;
   
Index: posix-threads.cc
===================================================================
--- posix-threads.cc	(revision 115021)
+++ posix-threads.cc	(working copy)
@@ -357,6 +357,9 @@
   pthread_mutex_init (&data->wait_mutex, NULL);
   pthread_cond_init (&data->wait_cond, NULL);
 
+  pthread_mutex_init (&data->suspend_count_mutex, NULL);
+  data->suspend_count = 0;
+
   return data;
 }
 
@@ -365,6 +368,7 @@
 {
   pthread_mutex_destroy (&data->wait_mutex);
   pthread_cond_destroy (&data->wait_cond);
+  pthread_mutex_destroy (&data->suspend_count_mutex);
   _Jv_Free ((void *)data);
 }
 
@@ -508,17 +512,39 @@
 void
 _Jv_ThreadDebugSuspend (_Jv_Thread_t *data)
 {
+  pthread_mutex_lock (&data->suspend_count_mutex);
+  if (++data->suspend_count == 1)
+    {
+      pthread_mutex_unlock (&data->suspend_count_mutex);
+      _Jv_SuspendThread (data);
+      return;
+    }
+
+  pthread_mutex_unlock (&data->suspend_count_mutex);
 }
 
 void
 _Jv_ThreadDebugResume (_Jv_Thread_t *data)
 {
+  pthread_mutex_lock (&data->suspend_count_mutex);
+  if (data->suspend_count > 0 && --data->suspend_count == 0)
+    {
+      pthread_mutex_unlock (&data->suspend_count_mutex);
+      _Jv_ResumeThread (data);
+      return;
+    }
+
+  pthread_mutex_unlock (&data->suspend_count_mutex);
 }
 
 jint
 _Jv_ThreadDebugSuspendCount (_Jv_Thread_t *data)
 {
-  return -1;
+  jint count;
+  pthread_mutex_lock (&data->suspend_count_mutex);
+  count = data->suspend_count;
+  pthread_mutex_unlock (&data->suspend_count_mutex);
+  return count;
 }
 
 #if defined(SLOW_PTHREAD_SELF)

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