Multiple Thread Library Support + Java Thread Support GTK's current threading primitives are hardcoded for pthreads. The GNU Classpath Project (http://www.classpath.org) is writing a Java AWT implementation using GTK+. As such, we needed to make gdkthreads work with the threading facilities provided by the Java Virtual Machine. As opposed to adding the ability to compile GTK for either pthreads or JNI (java) threads, I went ahead and extended GTK's threading primitives to easily switch between different thread implementations based on the application using libgtk. It should now be trivial to add new thread library support -- such as cthreads or Sun threads. The new threading calls are structured as follows: gboolean gdk_threads_init (GdkThreadsType threads_type, ...); void gdk_threads_enter (GdkThreadsType threads_type, ...); void gdk_threads_leave (GdkThreadsType threads_type, ...); GdkThreadsType is defined as: typedef enum { GDK_THREADS_INTERNAL, /* calls from within the GDK thread */ GDK_THREADS_PTHREADS, /* posix threads */ GDK_THREADS_JNI /* java threads */ } GdkThreadsType; A GTK application requests what type of threading it would like for GDK to use, by passing a GdkThreadsType to gdk_threads_init. Varargs are used accordingly if the GdkThreadsType needs any initialization parameters. The same calling convention is used for gdk_threads_{enter/leave}. Whenever GDK internally calls gdk_threads_{enter/leave}, GDK_THREADS_INTERNAL is passed without any extra parameters, as any needed thread info was passed in with the original init. Thus, under certain threading libraries, there may be a requirement that the thread calling gdk_threads_init is also the thread which runs the event loop. Java threads require the varargs to pass in a Java interface pointer which is associated with the calling thread. Pthreads do not have this type of requirement. So all the old pthreads code of the form: gdk_threads_init (); ... gdk_threads_enter (); [gtk calls] gdk_threads_leave (); now becomes: gdk_threads_init (GDK_THREADS_PTHREADS); ... gdk_threads_enter (GDK_THREADS_PTHREADS); [gtk calls] gdk_threads_leave (GDK_THREADS_PTHREADS); Java threads are called in the following manner, where "env" is the Java interface pointer (type: JNIEnv *). gdk_threads_init (GDK_THREADS_JNI, env); ... gdk_threads_enter (GDK_THREADS_JNI, env); [gtk calls] gdk_threads_leave (GDK_THREADS_JNI, env); For any thread calls within GDK, regardless of the threading type the application has requested, the following form is used: gdk_threads_enter (GDK_THREADS_INTERNAL); ... gdk_threads_leave (GDK_THREADS_INTERNAL); configure.in has been modified as well. --with-threads has been removed, and --with-posix-threads and --with-java-threads have been added. If --with-posix-threads is successful, USE_PTHREADS is defined. If --with-java-threads is successful, USE_JNI_THREADS is defined. If either is successful, USE_THREADS is defined, and -D_REENTRANT is added to the CFLAGS. -- Paul Fisher * rao@gnu.org