1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
https://bugzilla.gnome.org/show_bug.cgi?id=766774
In fix-unexpected-threaded-call, we will actually make concurrent hash accesses
from both the application and from the glib thread.
--- a/jni/src/jawimpl.c
+++ b/jni/src/jawimpl.c
@@ -92,7 +92,9 @@ typedef struct _JawInterfaceInfo {
static gpointer jaw_impl_parent_class = NULL;
+static GMutex typeTableMutex;
static GHashTable *typeTable = NULL;
+static GMutex objectTableMutex;
static GHashTable *objectTable = NULL;
static gboolean jaw_debug = FALSE;
@@ -106,7 +108,9 @@ object_table_insert (JNIEnv *jniEnv, job
"hashCode",
"()I");
gint hash_key = (gint)(*jniEnv)->CallIntMethod(jniEnv, ac, jmid);
+ g_mutex_lock(&objectTableMutex);
g_hash_table_insert(objectTable, GINT_TO_POINTER(hash_key), GINT_TO_POINTER(jaw_impl));
+ g_mutex_unlock(&objectTableMutex);
}
static JawImpl*
@@ -120,10 +124,15 @@ object_table_lookup (JNIEnv *jniEnv, job
"()I" );
gint hash_key = (gint)(*jniEnv)->CallIntMethod( jniEnv, ac, jmid );
gpointer value = NULL;
+ g_mutex_lock(&objectTableMutex);
if (objectTable==NULL)
+ {
return NULL;
+ g_mutex_unlock(&objectTableMutex);
+ }
value = g_hash_table_lookup(objectTable, GINT_TO_POINTER(hash_key));
+ g_mutex_unlock(&objectTableMutex);
return (JawImpl*)value;
}
@@ -138,7 +147,9 @@ object_table_remove(JNIEnv *jniEnv, jobj
"()I" );
gint hash_key = (gint)(*jniEnv)->CallIntMethod( jniEnv, ac, jmid );
+ g_mutex_lock(&objectTableMutex);
g_hash_table_remove(objectTable, GINT_TO_POINTER(hash_key));
+ g_mutex_unlock(&objectTableMutex);
}
GHashTable*
@@ -147,6 +158,12 @@ jaw_impl_get_object_hash_table(void)
return objectTable;
}
+GMutex*
+jaw_impl_get_object_hash_table_mutex(void)
+{
+ return &objectTableMutex;
+}
+
static void
aggregate_interface(JNIEnv *jniEnv, JawObject *jaw_obj, guint tflag)
{
@@ -265,8 +282,10 @@ jaw_impl_get_instance (JNIEnv *jniEnv, j
if (jniEnv == NULL)
return NULL;
+ g_mutex_lock(&objectTableMutex);
if (objectTable == NULL)
objectTable = g_hash_table_new (NULL, NULL);
+ g_mutex_unlock(&objectTableMutex);
jaw_impl = object_table_lookup(jniEnv, ac);
@@ -411,11 +430,13 @@ jaw_impl_get_type (guint tflag)
NULL
};
+ g_mutex_lock(&typeTableMutex);
if (typeTable == NULL) {
typeTable = g_hash_table_new( NULL, NULL );
}
type = GPOINTER_TO_GTYPE(g_hash_table_lookup(typeTable, GUINT_TO_POINTER(tflag)));
+ g_mutex_unlock(&typeTableMutex);
if (type == 0) {
GTypeInfo tinfo = {
sizeof(JawImplClass),
@@ -465,7 +486,9 @@ jaw_impl_get_type (guint tflag)
if (tflag & INTERFACE_TABLE_CELL)
g_type_add_interface_static (type, ATK_TYPE_TABLE_CELL, &atk_table_cell_info);
+ g_mutex_lock(&typeTableMutex);
g_hash_table_insert(typeTable, GINT_TO_POINTER(tflag), GTYPE_TO_POINTER(type));
+ g_mutex_unlock(&typeTableMutex);
}
return type;
--- a/jni/src/jawimpl.h
+++ b/jni/src/jawimpl.h
@@ -52,6 +52,7 @@ struct _JawImpl
JawImpl* jaw_impl_get_instance(JNIEnv*, jobject);
JawImpl* jaw_impl_find_instance(JNIEnv*, jobject);
GHashTable* jaw_impl_get_object_hash_table(void);
+GMutex* jaw_impl_get_object_hash_table_mutex(void);
GType jaw_impl_get_type (guint);
AtkRelationType jaw_impl_get_atk_relation_type(JNIEnv *jniEnv, jstring jrel_key);
--- a/jni/src/jawobject.c
+++ b/jni/src/jawobject.c
@@ -56,7 +56,6 @@ static AtkRelationSet *jaw_object_ref_re
static AtkObject *jaw_object_ref_child(AtkObject *atk_obj, gint i);
static gpointer parent_class = NULL;
-static GHashTable *object_table = NULL;
static JawObject* jaw_object_table_lookup (JNIEnv *jniEnv, jobject ac);
enum {
@@ -651,7 +650,8 @@ jaw_object_ref_child(AtkObject *atk_obj,
static JawObject*
jaw_object_table_lookup (JNIEnv *jniEnv, jobject ac)
{
- object_table = jaw_impl_get_object_hash_table();
+ GHashTable *object_table = jaw_impl_get_object_hash_table();
+ GMutex *object_table_mutex = jaw_impl_get_object_hash_table_mutex();
jclass classAccessibleContext = (*jniEnv)->FindClass( jniEnv,
"javax/accessibility/AccessibleContext" );
jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
@@ -663,7 +663,9 @@ jaw_object_table_lookup (JNIEnv *jniEnv,
if (object_table == NULL)
return NULL;
+ g_mutex_lock(object_table_mutex);
value = g_hash_table_lookup(object_table, GINT_TO_POINTER(hash_key));
+ g_mutex_unlock(object_table_mutex);
return (JawObject*)value;
}
|