[kaffe] CVS kaffe (guilhem): Fixes for netbsd.

Kaffe CVS cvs-commits at kaffe.org
Sat Apr 2 09:51:49 PST 2005


PatchSet 5645 
Date: 2005/04/02 17:44:40
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Fixes for netbsd.

        * kaffe/kaffevm/systems/unix-jthreads/jthread.c,
        kaffe/kaffevm/systems/unix-jthreads/jthread.h:
        (jthread_is_blocking): Added to the API for compatibility with
        unix-pthreads.

        * kaffe/kaffevm/systems/unix-pthreads/thread-impl.c,
        kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:
        (jthread_exit): Changed shutdown loop to take into account
        modifications to activeThreads list.
        (jthread_is_blocking): New jthread call.

        * kaffe/kaffevm/systems/unix-pthreads/lock-impl.c
        (clearBlockState): Set active to 0 when exiting.

        * kaffe/kaffevm/systems/unix-pthreads/syscalls.c
        (jthreadedRecvFrom): Fixed logic to avoid eating all CPU.

        * config/katomic.h (__atomic_val_bysize, __atomic_bool_bysize):
        If gcc is 2.95 then the syntax is also different.

Members: 
	ChangeLog:1.3815->1.3816 
	config/katomic.h:1.2->1.3 
	kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.130->1.131 
	kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.67->1.68 
	kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.21->1.22 
	kaffe/kaffevm/systems/unix-pthreads/syscalls.c:1.29->1.30 
	kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.80->1.81 
	kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.38->1.39 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3815 kaffe/ChangeLog:1.3816
--- kaffe/ChangeLog:1.3815	Sat Apr  2 16:38:21 2005
+++ kaffe/ChangeLog	Sat Apr  2 17:44:40 2005
@@ -1,3 +1,25 @@
+2005-04-02  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* kaffe/kaffevm/systems/unix-jthreads/jthread.c,
+	kaffe/kaffevm/systems/unix-jthreads/jthread.h:
+	(jthread_is_blocking): Added to the API for compatibility with
+	unix-pthreads.
+
+	* kaffe/kaffevm/systems/unix-pthreads/thread-impl.c,
+	kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:
+	(jthread_exit): Changed shutdown loop to take into account
+	modifications to activeThreads list.
+	(jthread_is_blocking): New jthread call.
+	
+	* kaffe/kaffevm/systems/unix-pthreads/lock-impl.c
+	(clearBlockState): Set active to 0 when exiting.
+
+	* kaffe/kaffevm/systems/unix-pthreads/syscalls.c
+	(jthreadedRecvFrom): Fixed logic to avoid eating all CPU.
+	
+	* config/katomic.h (__atomic_val_bysize, __atomic_bool_bysize): 
+	If gcc is 2.95 then the syntax is also different.
+
 2005-04-02  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/javalib/Makefile.am.in: (compile-classes)
Index: kaffe/config/katomic.h
diff -u kaffe/config/katomic.h:1.2 kaffe/config/katomic.h:1.3
--- kaffe/config/katomic.h:1.2	Fri Apr  1 21:32:21 2005
+++ kaffe/config/katomic.h	Sat Apr  2 17:44:46 2005
@@ -28,7 +28,42 @@
    and following args.  */
    
    
-#if __GNUC__ == 2 
+#if defined(__GNUC__) && __GNUC__ == 2 
+
+#if __GNUC_MINOR__ == 95
+
+#define __atomic_val_bysize(pre, post, mem, args...)			      \
+  ({									      \
+    __typeof (*mem) __result;						      \
+    if (sizeof (*mem) == 1)						      \
+      __result = pre##_8_##post (mem, args);			              \
+    else if (sizeof (*mem) == 2)					      \
+      __result = pre##_16_##post (mem, args);			      \
+    else if (sizeof (*mem) == 4)					      \
+      __result = pre##_32_##post (mem, args);			      \
+    else if (sizeof (*mem) == 8)					      \
+      __result = pre##_64_##post (mem, args);			      \
+    else								      \
+      abort ();								      \
+    __result;								      \
+  })
+#define __atomic_bool_bysize(pre, post, mem, args...)			      \
+  ({									      \
+    int __result;							      \
+    if (sizeof (*mem) == 1)						      \
+      __result = pre##_8_##post (mem, args);			              \
+    else if (sizeof (*mem) == 2)					      \
+      __result = pre##_16_##post (mem, args);			      \
+    else if (sizeof (*mem) == 4)					      \
+      __result = pre##_32_##post (mem, args);			      \
+    else if (sizeof (*mem) == 8)					      \
+      __result = pre##_64_##post (mem, args);			      \
+    else								      \
+      abort ();								      \
+    __result;								      \
+  })
+
+#else /* __GNUC_MINOR__ == 95 */
 
 #define __atomic_val_bysize(pre, post, mem, args...)			      \
   ({									      \
@@ -61,7 +96,9 @@
     __result;								      \
   })
 
-#else
+#endif /* __GNUC_MINOR__ == 95 */
+
+#else /* __GNUC__ */
   
 #define __atomic_val_bysize(pre, post, mem, ...)			      \
   ({									      \
Index: kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c
diff -u kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.130 kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.131
--- kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.130	Sun Mar 20 20:30:43 2005
+++ kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c	Sat Apr  2 17:44:45 2005
@@ -3387,6 +3387,13 @@
 	intsRestore();
 }
 
+int jthread_is_blocking(int fd)
+{
+	assert(fd < FD_SETSIZE);
+
+	return blockingFD[fd];
+}
+
 jlong jthread_get_usage(jthread_t jt)
 {
        jlong retval;
Index: kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h
diff -u kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.67 kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.68
--- kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.67	Sun Mar 20 20:30:43 2005
+++ kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h	Sat Apr  2 17:44:45 2005
@@ -337,6 +337,8 @@
 
 void jthread_set_blocking(int fd, int blocking);
 
+int jthread_is_blocking(int fd);
+
 /* restore an fd, i.e., put it in blocking state without async I/O */
 #define JTHREAD_RESTORE_FD
 void jthreadRestoreFD(int fd);
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.21 kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.22
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.21	Sat Apr  2 15:33:36 2005
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c	Sat Apr  2 17:44:46 2005
@@ -77,7 +77,11 @@
    * This is needed for Darwin's pthreads.
    */
   if (cur->status == THREAD_KILL && ((cur->blockState & BS_THREAD) == 0))
+  {
+    /* Mark the thread as inactive now to acknowledge the shutdown. */
+    cur->active = 0;
     pthread_exit(NULL);
+  }
 
   pthread_sigmask(SIG_SETMASK, old_mask, NULL);
   /* Here the state is not SS_PENDING_SUSPEND so releasing the signal will
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/syscalls.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/syscalls.c:1.29 kaffe/kaffe/kaffevm/systems/unix-pthreads/syscalls.c:1.30
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/syscalls.c:1.29	Thu Feb 10 21:48:35 2005
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/syscalls.c	Sat Apr  2 17:44:46 2005
@@ -586,6 +586,7 @@
 	int r;
 	jlong deadline = 0;
 	int poll_timeout;
+	int blocking = jthread_is_blocking(fd);
 
 	jthread_set_blocking(fd, 0);
 	SET_DEADLINE(deadline, timeout)
@@ -597,12 +598,12 @@
 		}
 		IGNORE_EINTR(r)
 		poll_timeout = deadline - currentTime();
-		if (poll_timeout > 0) {
+		if (poll_timeout > 0 || timeout == NOTIMEOUT) {
 			waitForTimeout(fd, poll_timeout);
 		}
 		BREAK_IF_LATE(deadline, timeout)
 	}
-	jthread_set_blocking(fd, 1);
+	jthread_set_blocking(fd, blocking);
 	SET_RETURN_OUT(r, out, r)
 	return (r);
 }
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.80 kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.81
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.80	Sat Apr  2 15:33:36 2005
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c	Sat Apr  2 17:44:46 2005
@@ -1060,10 +1060,11 @@
 		repsem_post(&t->sem);
 	  }
 
-	  for ( t=activeThreads; t != NULL; t = t->next ){
+	  t = activeThreads;
+	  while (t != NULL) {
 		/* We must not kill the current thread and the main thread
 		 */
-		if ( t != cur && t != firstThread) {
+		if ( t != cur && t != firstThread && t->active) {
 		  /* Mark the thread as to be killed. */
 		  t->status = THREAD_KILL;
 		  /* Send an interrupt event to the remote thread to wake up.
@@ -1074,7 +1075,10 @@
 		  unprotectThreadList(cur);
 		  pthread_join(t->tid, NULL);
 		  protectThreadList(cur);
-		}
+
+		  t = activeThreads;
+		} else
+		  t = t->next;
 	  }
 
 #if defined(KAFFE_VMDEBUG)
@@ -1550,6 +1554,20 @@
   protectThreadList(cur);
   jthread_walkLiveThreads (func, private);
   unprotectThreadList(cur);
+}
+
+int
+jthread_is_blocking (int fd)
+{
+  int r;
+ 
+  r = fcntl(fd, F_GETFL, 0);
+  if (r < 0) {
+    perror("fcntl(F_GETFL)");
+    return 0;
+  }
+		  
+  return (r & O_NONBLOCK) != 0;
 }
 
 void
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.38 kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.39
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.38	Sun Mar 20 20:30:44 2005
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-internal.h	Sat Apr  2 17:44:46 2005
@@ -336,6 +336,11 @@
  */
 void jthread_set_blocking (int fd, int blocking);
 
+/**
+ * Check the blocking state of a file descriptor
+ */
+int jthread_is_blocking (int fd);
+
 void jthread_suspend(UNUSED jthread_t jt, UNUSED void *suspender);
 
 void jthread_resume(UNUSED jthread_t jt, UNUSED void *suspender);



More information about the kaffe mailing list