[kaffe] CVS kaffe (guilhem): PThreads fixes.

Kaffe CVS cvs-commits at kaffe.org
Wed Nov 3 11:30:45 PST 2004


PatchSet 5397 
Date: 2004/11/03 19:25:49
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
PThreads fixes.

2004-11-02  Eric Anholt  <eta at lclark.edu>

        * kaffe/kaffevm/systems/unix-pthreads/thread-impl.c,
        kaffe/kaffevm/systems/unix-pthreads/thread-impl.h
        (jthread_atexit, jthread_spinon, jthread_spinoff): Implemented.
        (jthread_create, jthread_exit): Protect nonDaemons, pendingExits,
        execute runOnExit.

Members: 
	ChangeLog:1.2946->1.2947 
	kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.51->1.52 
	kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.21->1.22 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2946 kaffe/ChangeLog:1.2947
--- kaffe/ChangeLog:1.2946	Mon Nov  1 19:56:16 2004
+++ kaffe/ChangeLog	Wed Nov  3 19:25:49 2004
@@ -1,3 +1,33 @@
+2004-11-02  Eric Anholt  <eta at lclark.edu>
+
+	* kaffe/kaffevm/systems/unix-pthreads/thread-impl.c,
+	kaffe/kaffevm/systems/unix-pthreads/thread-impl.h
+	(jthread_atexit, jthread_spinon, jthread_spinoff): Implemented.
+	(jthread_create, jthread_exit): Protect nonDaemons, pendingExits,
+	execute runOnExit.
+	
+2004-11-02  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* libraries/javalib/java/io/Vector.java,
+	libraries/javalib/java/io/ObjectOutputStream.java:
+	Resynced with GNU Classpath.	
+
+	2004-11-02  Mattias Rehnberg  <Mattias.Rehnberg at home.se>
+
+        * java/io/Vector.java
+        (readObject, writeObject): New function to match Sun's
+        serialized output for Vector.
+
+        * java/io/ObjectOutputStream.java
+        (writeObject): Move the assignment of the class handle to after
+        the assignment of class descriptor handle.
+
+2004-11-02 Mattias Rehnberg <Mattias.Rehnberg at home.se>
+
+	* libraries/clib/io/ObjectInputStream.c
+	(getFieldAddress): Use the class decriptor from the field object
+	instead of using the class of the target object.
+	
 2004-11-01  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/javalib/gnu/xml/dom/DomNode.java:
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.51 kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.52
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.51	Sun Oct 31 14:35:38 2004
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c	Wed Nov  3 19:25:54 2004
@@ -117,6 +117,10 @@
  */
 pthread_mutex_t		activeThreadsLock = PTHREAD_MUTEX_INITIALIZER;
 
+/** This mutex lock protects calls into non-reentrant system services.
+ */
+pthread_mutex_t		systemMutex = PTHREAD_MUTEX_INITIALIZER;
+
 /** We don't throw away threads when their user func terminates, but suspend
  * and cache them for later re-use */
 static jthread_t	cache;
@@ -158,6 +162,9 @@
 /** This callback is to be called when a thread exits. */
 static void (*threadDestructor)(void *);
 
+/** This callback is called when all non-daemon threads exit. */
+static void (*runOnExit)(void);
+
 #ifdef KAFFE_VMDEBUG
 /** an optional deadlock watchdog thread (not in the activeThread list),
  * activated by KAFFE_VMDEBUG topic JTHREAD */
@@ -827,8 +834,10 @@
 
   sp.sched_priority = priorities[pri];
 
+  protectThreadList(cur);
   if ( !isDaemon ) 
 	nonDaemons++;
+  unprotectThreadList(cur);
 
   if ( cache ) {
 	protectThreadList(cur);
@@ -980,10 +989,14 @@
 
   if ( !cur->daemon ) {
 	/* the last non daemon should shut down the process */
+	protectThreadList(cur);
 	if ( --nonDaemons == 0 ) {
-	  protectThreadList(cur);
-
 	  DBG( JTHREAD, dprintf("exit on last nonDaemon\n"))
+	  if (runOnExit != NULL) {
+	    unprotectThreadList(cur);
+	    runOnExit();
+	    protectThreadList(cur);
+	  }
 
 	  /*
 	   * be a nice citizen, try to cancel all other threads before we
@@ -1018,6 +1031,7 @@
 	  /* we shouldn't get here, this is a last safeguard */
 	  EXIT(0);
 	}
+	unprotectThreadList(cur);
   }
 
   if ( cur == firstThread ) {
@@ -1047,7 +1061,9 @@
   else {
 	/* flag that we soon will get a new cache entry (would be annoying to
 	 * create a new thread in the meantime) */
+	protectThreadList(cur);
 	pendingExits++;
+	unprotectThreadList(cur);
   }
 }
 
@@ -1480,3 +1496,35 @@
   }
 }
 
+
+/**
+ * Lock a mutex which will be used for critical sections when entering
+ * non-reentrant system code, for example.
+ *
+ * @param dummy unused pointer
+ */
+void jthread_spinon(UNUSED void *dummy)
+{
+  pthread_mutex_lock(&systemMutex);
+}
+
+/**
+ * Unock a mutex used for critical sections when entering non-reentrant system
+ * code.
+ *
+ * @param dummy unused pointer
+ */
+void jthread_spinoff(UNUSED void *dummy)
+{
+  pthread_mutex_unlock(&systemMutex);
+}
+
+/**
+ * Sets a function to be run when all non-daemon threads have exited.
+ *
+ * @param func the function to be called when exiting.
+ */
+void jthread_atexit(void (* func)(void))
+{
+  runOnExit = func;
+}
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.21 kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.22
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.21	Wed Oct 20 16:47:14 2004
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h	Wed Nov  3 19:25:54 2004
@@ -144,14 +144,11 @@
 void jthread_interrupt(jthread_t tid);
 
 /**
- * Register a function to be called when the vm exits.
+ * Register a function to be called when the all non-daemon threads have exited.
  * 
  * @param func the func to execute.
  */
-static inline
-void jthread_atexit(UNUSED void (* func)(void))
-{
-}
+void jthread_atexit(void (* func)(void));
 
 /**
  * Dump some information about a thread to stderr.
@@ -264,26 +261,20 @@
 static inline
 void jthread_yield (void)
 {
-  sched_yield();
+  pthread_yield();
 }
 
 /**
  * Acquire a spin lock.
  *
  */
-static inline
-void jthread_spinon(UNUSED int dummy)
-{
-}
+void jthread_spinon(UNUSED void *dummy);
 
 /**
  * Release a spin lock.
  *
  */
-static inline
-void jthread_spinoff(UNUSED int dummy)
-{
-}
+void jthread_spinoff(UNUSED void *dummy);
 
 struct _exceptionFrame;
 typedef void (*exchandler_t)(struct _exceptionFrame*);




More information about the kaffe mailing list