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: java/lang/Thread.h and CNI


java/lang/Thread.h contains some friend declarations that break CNI code
that tries to #include it:

  friend int _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
jlong millis, jint nanos);
  friend int _Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t
*mu);
  friend void _Jv_ThreadInterrupt (_Jv_Thread_t *data);

$ c++ -c `gtk-config --cflags` gnu/awt/peer/gtk/natGtkMainThread.cc -o
build/gnu/awt/peer/gtk/natGtkMainThread.o -Ibuild
/usr/local/gcc/include/java/lang/Thread.h:83: `_Jv_ConditionVariable_t'
was not declared in this scope
/usr/local/gcc/include/java/lang/Thread.h:83: `cv' was not declared in
this scope
/usr/local/gcc/include/java/lang/Thread.h:83: `_Jv_Mutex_t' was not
declared in this scope
/usr/local/gcc/include/java/lang/Thread.h:83: `mu' was not declared in
this scope
/usr/local/gcc/include/java/lang/Thread.h:83: parse error before `,'
/usr/local/gcc/include/java/lang/Thread.h:84: `_Jv_ConditionVariable_t'
was not declared in this scope
/usr/local/gcc/include/java/lang/Thread.h:84: `cv' was not declared in
this scope
/usr/local/gcc/include/java/lang/Thread.h:84: `_Jv_Mutext' was not
declared in this scope
/usr/local/gcc/include/java/lang/Thread.h:84: `mu' was not declared in
this scope
/usr/local/gcc/include/java/lang/Thread.h:84: invalid data member
initiailization
/usr/local/gcc/include/java/lang/Thread.h:84: use `=' to initialize
static data members
[...]

This solution takes advantage of the property of CNI where
package-private fields are actually mapped to public fields in C++. This
way the native threads implementation can access the interrupt_flag
without polluting the Java API. This is a bit of a hack, but the only
solution I can come up with right now: interrupt_flag must be accessible
from both the native thread implementation and the java.lang.Thread
code, and putting it inside Thread itself is the only convenient way to
do it.

I'm checking this in.

regards

  [ bryce ]

2000-09-07  Bryce McKinlay  <bryce@albatross.co.nz>

	* Makefile.am (Thread.h): Don't be friends with native threads 
	functions.
	* Makefile.in: Rebuilt.
	* java/lang/Thread.java (interrupt_flag): Make package-private.

Index: Makefile.am
===================================================================
RCS file: /cvs/java/libgcj/libjava/Makefile.am,v
retrieving revision 1.87
diff -u -r1.87 Makefile.am
--- Makefile.am	2000/09/04 16:55:47	1.87
+++ Makefile.am	2000/09/07 11:40:22
@@ -246,9 +246,6 @@
 		-friend '_Jv_JNIEnv * _Jv_GetCurrentJNIEnv ();' \
 		-friend 'void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *env);' \
 		-friend 'class gnu::gcj::jni::NativeThread;' \
-		-friend 'int _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu, jlong millis, jint nanos);' \
-		-friend 'int _Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu);' \
-		-friend 'void _Jv_ThreadInterrupt (_Jv_Thread_t *data);' \
 		$(basename $<)
 
 java/lang/String.h: java/lang/String.class libgcj.zip
Index: java/lang/Thread.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Thread.java,v
retrieving revision 1.12
diff -u -r1.12 Thread.java
--- Thread.java	2000/06/21 03:55:35	1.12
+++ Thread.java	2000/09/07 11:40:23
@@ -288,7 +288,7 @@
   private Runnable runnable;
   private int priority;
   private boolean daemon_flag;
-  private boolean interrupt_flag;
+  boolean interrupt_flag;
   private boolean alive_flag;
   private boolean startable_flag;
 

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