Patch: per-surface locking for jawt: take 2

Anthony Green green@redhat.com
Wed Apr 6 22:35:00 GMT 2005


Here's take 2 of this patch.  I've moved all gtk specific code out of jawt.c.

Ok for 4.0 branch and HEAD?

Thanks,

AG


-------------- next part --------------
2005-04-06  Anthony Green  <green@redhat.com>

	* jni/gtk-peer/gtk_jawt.c (classpath_jawt_object_lock,
	classpath_jawt_object_unlock, classpath_jawt_create_lock,
	classpath_jawt_destroy_lock): New functions.
	* jni/classpath/classpath_jawt.h (classpath_jawt_object_lock,
	classpath_jawt_object_unlock, classpath_jawt_create_lock,
	classpath_jawt_destroy_lock): New functions.
	* include/jawt.h (struct _JAWT_DrawingSurface): Add lock
	field.
	* jawt.c: #include malloc.h.
	(_Jv_Lock): Use lock.
	(_Jv_Unlock): Ditto.
	(_Jv_GetDrawingSurface): Initialize lock.
	(_Jv_FreeDrawingSurface): Destroy lock.
	(_Jv_FreeDrawingSurfaceInfo): Free platformInfo.


Index: jni/gtk-peer/gtk_jawt.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gtk_jawt.c,v
retrieving revision 1.2.6.1
diff -u -r1.2.6.1 gtk_jawt.c
--- jni/gtk-peer/gtk_jawt.c	7 Mar 2005 19:58:41 -0000	1.2.6.1
+++ jni/gtk-peer/gtk_jawt.c	6 Apr 2005 22:20:25 -0000
@@ -153,6 +153,21 @@
 }
 
 jint
+classpath_jawt_object_lock (jobject lock)
+{
+  JNIEnv *env = gdk_env();
+  (*env)->MonitorEnter (env, lock);
+  return 0;
+}
+
+void
+classpath_jawt_object_unlock (jobject lock)
+{
+  JNIEnv *env = gdk_env();
+  (*env)->MonitorExit (env, lock);
+}
+
+jint
 classpath_jawt_lock ()
 {
   gdk_threads_enter ();
@@ -164,3 +179,19 @@
 {
   gdk_threads_leave ();
 }
+
+jobject
+classpath_jawt_create_lock ()
+{
+  JNIEnv *env = gdk_env ();
+  jobject lock = (*env)->NewStringUTF (env, "jawt-lock");
+  NSA_SET_GLOBAL_REF (env, lock);
+  return lock;
+}
+
+void
+classpath_jawt_destroy_lock (jobject lock)
+{
+  JNIEnv *env = gdk_env ();
+  NSA_DEL_GLOBAL_REF (env, lock);
+}
Index: jni/classpath/classpath_jawt.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/classpath/classpath_jawt.h,v
retrieving revision 1.2.6.1
diff -u -r1.2.6.1 classpath_jawt.h
--- jni/classpath/classpath_jawt.h	7 Mar 2005 19:58:41 -0000	1.2.6.1
+++ jni/classpath/classpath_jawt.h	6 Apr 2005 22:20:25 -0000
@@ -54,7 +54,11 @@
 Display* classpath_jawt_get_default_display (JNIEnv* env, jobject canvas);
 Drawable classpath_jawt_get_drawable (JNIEnv* env, jobject canvas);
 VisualID classpath_jawt_get_visualID (JNIEnv* env, jobject canvas);
+jint     classpath_jawt_object_lock (jobject lock);
+void     classpath_jawt_object_unlock (jobject lock);
 jint     classpath_jawt_lock ();
 void     classpath_jawt_unlock ();
+jobject  classpath_jawt_create_lock ();
+void     classpath_jawt_destroy_lock (jobject lock);
 
 #endif /* __classpath_jawt_h__ */
Index: include/jawt.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jawt.h,v
retrieving revision 1.2.6.1
diff -u -r1.2.6.1 jawt.h
--- include/jawt.h	7 Mar 2005 19:58:41 -0000	1.2.6.1
+++ include/jawt.h	6 Apr 2005 22:20:25 -0000
@@ -72,6 +72,9 @@
 
   struct _JAWT_DrawingSurfaceInfo* surface_info;
 
+  /* An object we're going to use for locking the surface.  */
+  jobject lock;
+
   /* FIXME: also include bounding rectangle of drawing surface. */
   /* FIXME: also include current clipping region. */
 };
Index: jawt.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jawt.c,v
retrieving revision 1.2.6.1
diff -u -r1.2.6.1 jawt.c
--- jawt.c	7 Mar 2005 19:58:40 -0000	1.2.6.1
+++ jawt.c	6 Apr 2005 22:20:25 -0000
@@ -40,6 +40,7 @@
 #include <jawt.h>
 #include <jawt_md.h>
 #include "classpath_jawt.h"
+#include <malloc.h>
 
 static jint (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface);
 static void (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface);
@@ -76,14 +77,13 @@
 static jint
 (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface)
 {
-  /* lock the drawing surface */
-  return classpath_jawt_lock ();
+  return classpath_jawt_object_lock (surface->lock);
 }
 
 static void
 (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface)
 {
-  classpath_jawt_unlock ();
+  classpath_jawt_object_unlock (surface->lock);
 }
 
 static JAWT_DrawingSurfaceInfo*
@@ -109,6 +109,7 @@
   surface_info_x11->drawable = 0;
   surface_info_x11->visualID = 0;
 
+  free (surface_info->platformInfo);
   free (surface_info);
   surface_info = NULL;
 }
@@ -135,6 +136,8 @@
 
   surface->surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof (JAWT_DrawingSurfaceInfo));
 
+  surface->lock = classpath_jawt_create_lock ();
+
   if (surface->surface_info == NULL)
     return NULL;
 
@@ -158,6 +161,7 @@
 static void
 (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface)
 {
+  classpath_jawt_destroy_lock (surface->lock);
   free (surface);
 }
 


More information about the Java-patches mailing list