From: Juerg Billeter Date: Fri, 23 May 2008 21:41:15 +0000 (+0000) Subject: Use GStaticRecMutex for lock statements, patch by Philip Van Hoof, fixes X-Git-Tag: VALA_0_3_3~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8d72d1ae35fffb05acea1b4fd0b07b2b0fcb46b;p=thirdparty%2Fvala.git Use GStaticRecMutex for lock statements, patch by Philip Van Hoof, fixes 2008-05-23 Juerg Billeter * vapi/glib-2.0.vapi: * gobject/valaccodegenerator.vala: Use GStaticRecMutex for lock statements, patch by Philip Van Hoof, fixes bug 532329 svn path=/trunk/; revision=1417 --- diff --git a/ChangeLog b/ChangeLog index dbe3d3d9d..250027cf7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-05-23 Jürg Billeter + + * vapi/glib-2.0.vapi: + * gobject/valaccodegenerator.vala: + + Use GStaticRecMutex for lock statements, + patch by Philip Van Hoof, fixes bug 532329 + 2008-05-23 Jürg Billeter * vapi/packages/gtk+-2.0/: fix gtk_window_get_default_size binding, diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index ebf80f203..378071ee6 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -109,7 +109,7 @@ public class Vala.CCodeGenerator : CodeGenerator { public Typesymbol gstringbuilder_type; public Typesymbol garray_type; public DataType gquark_type; - public DataType mutex_type; + public Struct mutex_type; public Typesymbol type_module_type; public Interface iterable_type; public Interface iterator_type; @@ -237,7 +237,7 @@ public class Vala.CCodeGenerator : CodeGenerator { garray_type = (Typesymbol) glib_ns.scope.lookup ("Array"); gquark_type = new ValueType ((Typesymbol) glib_ns.scope.lookup ("Quark")); - mutex_type = new ClassInstanceType ((Class) glib_ns.scope.lookup ("Mutex")); + mutex_type = (Struct) glib_ns.scope.lookup ("StaticRecMutex"); type_module_type = (Typesymbol) glib_ns.scope.lookup ("TypeModule"); @@ -456,27 +456,25 @@ public class Vala.CCodeGenerator : CodeGenerator { public override void visit_member (Member m) { /* stuff meant for all lockable members */ if (m is Lockable && ((Lockable)m).get_lock_used ()) { + CCodeExpression l = new CCodeIdentifier ("self"); + l = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (l, "priv"), get_symbol_lock_name (m)); + instance_priv_struct.add_field (mutex_type.get_cname (), get_symbol_lock_name (m)); - - instance_init_fragment.append ( - new CCodeExpressionStatement ( - new CCodeAssignment ( - new CCodeMemberAccess.pointer ( - new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), - get_symbol_lock_name (m)), - new CCodeFunctionCall (new CCodeIdentifier (((Class)mutex_type.data_type).default_construction_method.get_cname ()))))); - + + var initf = new CCodeFunctionCall ( + new CCodeIdentifier (mutex_type.default_construction_method.get_cname ())); + + initf.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, l)); + + instance_init_fragment.append (new CCodeExpressionStatement (initf)); + requires_free_checked = true; - var fc = new CCodeFunctionCall (new CCodeIdentifier ("VALA_FREE_CHECKED")); - fc.add_argument ( - new CCodeMemberAccess.pointer ( - new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), - get_symbol_lock_name (m))); - if (mutex_type.data_type.get_free_function () == null) { - Report.error (mutex_type.data_type.source_reference, "The type `%s` doesn't contain a free function".printf (mutex_type.data_type.get_full_name ())); - return; - } - fc.add_argument (new CCodeIdentifier (mutex_type.data_type.get_free_function ())); + + + var fc = new CCodeFunctionCall (new CCodeIdentifier ("g_static_rec_mutex_free")); + + fc.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, l)); + if (instance_dispose_fragment != null) { instance_dispose_fragment.append (new CCodeExpressionStatement (fc)); } @@ -2424,14 +2422,15 @@ public class Vala.CCodeGenerator : CodeGenerator { } l = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (l, "priv"), get_symbol_lock_name (stmt.resource.symbol_reference)); - fc = new CCodeFunctionCall (new CCodeIdentifier (((Method) mutex_type.data_type.scope.lookup ("lock")).get_cname ())); - fc.add_argument (l); + fc = new CCodeFunctionCall (new CCodeIdentifier (((Method) mutex_type.scope.lookup ("lock")).get_cname ())); + fc.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, l)); + cn.append (new CCodeExpressionStatement (fc)); cn.append (stmt.body.ccodenode); - fc = new CCodeFunctionCall (new CCodeIdentifier (((Method) mutex_type.data_type.scope.lookup ("unlock")).get_cname ())); - fc.add_argument (l); + fc = new CCodeFunctionCall (new CCodeIdentifier (((Method) mutex_type.scope.lookup ("unlock")).get_cname ())); + fc.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, l)); cn.append (new CCodeExpressionStatement (fc)); stmt.ccodenode = cn; diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 5b696b389..18dfed3f0 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -1286,7 +1286,16 @@ namespace GLib { public bool trylock (); public void unlock (); } - + + [CCode (destroy_function = "g_static_rec_mutex_free")] + public struct StaticRecMutex { + public StaticRecMutex (); + public void lock (); + public bool trylock (); + public void unlock (); + public void lock_full (); + } + [CCode (free_function = "g_cond_free")] public class Cond { public Cond ();