GDBus codegen: generate code with embedded GMutex

Modify GDBus code generator to emit code that uses GMutex embedded into
the structure of the skeleton instead of a pointer.

https://bugzilla.gnome.org/show_bug.cgi?id=660739
This commit is contained in:
Ryan Lortie 2011-10-04 00:09:53 -04:00
parent 8bcdabf25a
commit 7d4dea748d

View File

@ -2062,7 +2062,7 @@ class CodeGenerator:
' GList *changed_properties;\n' ' GList *changed_properties;\n'
' GSource *changed_properties_idle_source;\n' ' GSource *changed_properties_idle_source;\n'
' GMainContext *context;\n' ' GMainContext *context;\n'
' GMutex *lock;\n' ' GMutex lock;\n'
'};\n' '};\n'
'\n'%i.camel_name) '\n'%i.camel_name)
@ -2284,14 +2284,14 @@ class CodeGenerator:
self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n' self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
' gboolean emit_changed = FALSE;\n' ' gboolean emit_changed = FALSE;\n'
'\n' '\n'
' g_mutex_lock (skeleton->priv->lock);\n' ' g_mutex_lock (&skeleton->priv->lock);\n'
' if (skeleton->priv->changed_properties_idle_source != NULL)\n' ' if (skeleton->priv->changed_properties_idle_source != NULL)\n'
' {\n' ' {\n'
' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n' ' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
' skeleton->priv->changed_properties_idle_source = NULL;\n' ' skeleton->priv->changed_properties_idle_source = NULL;\n'
' emit_changed = TRUE;\n' ' emit_changed = TRUE;\n'
' }\n' ' }\n'
' g_mutex_unlock (skeleton->priv->lock);\n' ' g_mutex_unlock (&skeleton->priv->lock);\n'
'\n' '\n'
' if (emit_changed)\n' ' if (emit_changed)\n'
' _%s_emit_changed (skeleton);\n' ' _%s_emit_changed (skeleton);\n'
@ -2344,7 +2344,7 @@ class CodeGenerator:
self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n') self.c.write(' g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
self.c.write(' if (skeleton->priv->context != NULL)\n') self.c.write(' if (skeleton->priv->context != NULL)\n')
self.c.write(' g_main_context_unref (skeleton->priv->context);\n') self.c.write(' g_main_context_unref (skeleton->priv->context);\n')
self.c.write(' g_mutex_free (skeleton->priv->lock);\n') self.c.write(' g_mutex_clear (&skeleton->priv->lock);\n')
self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n' self.c.write(' G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
'}\n' '}\n'
'\n'%(i.name_lower)) '\n'%(i.name_lower))
@ -2359,9 +2359,9 @@ class CodeGenerator:
'{\n'%(i.name_lower)) '{\n'%(i.name_lower))
self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n' self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
' g_assert (prop_id != 0 && prop_id - 1 < %d);\n' ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
' g_mutex_lock (skeleton->priv->lock);\n' ' g_mutex_lock (&skeleton->priv->lock);\n'
' g_value_copy (&skeleton->priv->properties->values[prop_id - 1], value);\n' ' g_value_copy (&skeleton->priv->properties->values[prop_id - 1], value);\n'
' g_mutex_unlock (skeleton->priv->lock);\n' ' g_mutex_unlock (&skeleton->priv->lock);\n'
%(i.camel_name, i.ns_upper, i.name_upper, len(i.properties))) %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
self.c.write('}\n' self.c.write('}\n'
'\n') '\n')
@ -2388,7 +2388,7 @@ class CodeGenerator:
' GVariantBuilder invalidated_builder;\n' ' GVariantBuilder invalidated_builder;\n'
' guint num_changes;\n' ' guint num_changes;\n'
'\n' '\n'
' g_mutex_lock (skeleton->priv->lock);\n' ' g_mutex_lock (&skeleton->priv->lock);\n'
' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n' ' g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n' ' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n' ' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
@ -2427,7 +2427,7 @@ class CodeGenerator:
self.c.write(' g_list_free (skeleton->priv->changed_properties);\n') self.c.write(' g_list_free (skeleton->priv->changed_properties);\n')
self.c.write(' skeleton->priv->changed_properties = NULL;\n') self.c.write(' skeleton->priv->changed_properties = NULL;\n')
self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n') self.c.write(' skeleton->priv->changed_properties_idle_source = NULL;\n')
self.c.write(' g_mutex_unlock (skeleton->priv->lock);\n') self.c.write(' g_mutex_unlock (&skeleton->priv->lock);\n')
self.c.write(' return FALSE;\n' self.c.write(' return FALSE;\n'
'}\n' '}\n'
'\n') '\n')
@ -2470,7 +2470,7 @@ class CodeGenerator:
' GParamSpec *pspec)\n' ' GParamSpec *pspec)\n'
'{\n' '{\n'
' %sSkeleton *skeleton = %s%s_SKELETON (object);\n' ' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
' g_mutex_lock (skeleton->priv->lock);\n' ' g_mutex_lock (&skeleton->priv->lock);\n'
' if (skeleton->priv->changed_properties != NULL &&\n' ' if (skeleton->priv->changed_properties != NULL &&\n'
' skeleton->priv->changed_properties_idle_source == NULL)\n' ' skeleton->priv->changed_properties_idle_source == NULL)\n'
' {\n' ' {\n'
@ -2480,7 +2480,7 @@ class CodeGenerator:
' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n' ' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
' g_source_unref (skeleton->priv->changed_properties_idle_source);\n' ' g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
' }\n' ' }\n'
' g_mutex_unlock (skeleton->priv->lock);\n' ' g_mutex_unlock (&skeleton->priv->lock);\n'
'}\n' '}\n'
'\n' '\n'
%(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower)) %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
@ -2493,7 +2493,7 @@ class CodeGenerator:
'{\n'%(i.name_lower)) '{\n'%(i.name_lower))
self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n' self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
' g_assert (prop_id != 0 && prop_id - 1 < %d);\n' ' g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
' g_mutex_lock (skeleton->priv->lock);\n' ' g_mutex_lock (&skeleton->priv->lock);\n'
' g_object_freeze_notify (object);\n' ' g_object_freeze_notify (object);\n'
' if (!_g_value_equal (value, &skeleton->priv->properties->values[prop_id - 1]))\n' ' if (!_g_value_equal (value, &skeleton->priv->properties->values[prop_id - 1]))\n'
' {\n' ' {\n'
@ -2502,7 +2502,7 @@ class CodeGenerator:
' g_value_copy (value, &skeleton->priv->properties->values[prop_id - 1]);\n' ' g_value_copy (value, &skeleton->priv->properties->values[prop_id - 1]);\n'
' g_object_notify_by_pspec (object, pspec);\n' ' g_object_notify_by_pspec (object, pspec);\n'
' }\n' ' }\n'
' g_mutex_unlock (skeleton->priv->lock);\n' ' g_mutex_unlock (&skeleton->priv->lock);\n'
' g_object_thaw_notify (object);\n' ' g_object_thaw_notify (object);\n'
%(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower)) %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
self.c.write('}\n' self.c.write('}\n'
@ -2513,7 +2513,7 @@ class CodeGenerator:
'{\n' '{\n'
' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n' ' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
%(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.camel_name)) %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.camel_name))
self.c.write(' skeleton->priv->lock = g_mutex_new ();\n') self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
self.c.write(' skeleton->priv->context = g_main_context_get_thread_default ();\n') self.c.write(' skeleton->priv->context = g_main_context_get_thread_default ();\n')
self.c.write(' if (skeleton->priv->context != NULL)\n') self.c.write(' if (skeleton->priv->context != NULL)\n')
self.c.write(' g_main_context_ref (skeleton->priv->context);\n') self.c.write(' g_main_context_ref (skeleton->priv->context);\n')
@ -2536,9 +2536,9 @@ class CodeGenerator:
%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name)) %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper)) self.c.write(' %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
self.c.write(' %svalue;\n' self.c.write(' %svalue;\n'
' g_mutex_lock (skeleton->priv->lock);\n' ' g_mutex_lock (&skeleton->priv->lock);\n'
' value = %s (&(skeleton->priv->properties->values[%d]));\n' ' value = %s (&(skeleton->priv->properties->values[%d]));\n'
' g_mutex_unlock (skeleton->priv->lock);\n' ' g_mutex_unlock (&skeleton->priv->lock);\n'
%(p.arg.ctype_in_g, p.arg.gvalue_get, n)) %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
self.c.write(' return value;\n') self.c.write(' return value;\n')
self.c.write('}\n') self.c.write('}\n')