Index: ChangeLog
===================================================================
--- ChangeLog	(revision 1415)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2008-05-23  Philip Van Hoof  <pvanhoof@gnome.org>
+
+	* vapi/glib-2.0.vapi:
+	* gobject/valaccodegenerator.vala: 
+	
+	Spend my Friday evening fixing bug #532329, so that Vala uses GStaticRecMutex 
+	for lock () {}, instead of going out like all other human beings.
+
 2008-05-23  Jürg Billeter  <j@bitron.ch>
 
 	* vapi/packages/gstreamer-video-0.10/:
Index: vapi/glib-2.0.vapi
===================================================================
--- vapi/glib-2.0.vapi	(revision 1415)
+++ vapi/glib-2.0.vapi	(working copy)
@@ -1278,7 +1278,16 @@
 		[CCode (cname = "g_usleep")]
 		public static void usleep (ulong microseconds);
 	}
-	
+
+	[CCode (destroy_function = "g_static_rec_mutex_free", name = "GStaticRecMutex")]
+	public struct StaticRecMutex {
+		public StaticRecMutex ();
+		public void lock ();
+		public bool trylock ();
+		public void unlock ();
+		public void lock_full ();
+	}
+
 	[CCode (free_function = "g_mutex_free")]
 	public class Mutex {
 		public Mutex ();
Index: gobject/valaccodegenerator.vala
===================================================================
--- gobject/valaccodegenerator.vala	(revision 1415)
+++ gobject/valaccodegenerator.vala	(working copy)
@@ -109,7 +109,7 @@
 	public Typesymbol gstringbuilder_type;
 	public Typesymbol garray_type;
 	public DataType gquark_type;
-	public DataType mutex_type;
+	public ValueType mutex_type;
 	public Typesymbol type_module_type;
 	public Interface iterable_type;
 	public Interface iterator_type;
@@ -237,7 +237,7 @@
 		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 = new ValueType ((Typesymbol) glib_ns.scope.lookup ("StaticRecMutex"));
 		
 		type_module_type = (Typesymbol) glib_ns.scope.lookup ("TypeModule");
 
@@ -456,27 +456,31 @@
 	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));
+
+			var initf = new CCodeFunctionCall (
+				new CCodeIdentifier ( ((Struct)mutex_type.type_symbol).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;
 			
-			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 ())))));
-			
-			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) {
+			/* 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 ()));
+			} */
+
+
+			// fc = new CCodeIdentifier (mutex_type.data_type.get_destroy_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));
 			}
@@ -2425,13 +2429,14 @@
 		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.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.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, l));
 		cn.append (new CCodeExpressionStatement (fc));
 		
 		stmt.ccodenode = cn;
