]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Added support for 'volatile' modifier in C code.
authorJared Moore <jaredm@svn.gnome.org>
Tue, 22 Jul 2008 01:13:35 +0000 (01:13 +0000)
committerJared William Moore <jaredm@src.gnome.org>
Tue, 22 Jul 2008 01:13:35 +0000 (01:13 +0000)
2008-07-22  Jared Moore  <jaredm@svn.gnome.org>

* ccode/valaccodedeclaration.vala:
* ccode/valaccodemodifiers.vala:

Added support for 'volatile' modifier in C code.

* gobject/valatyperegisterfunction.vala:

Make *_get_type functions thread safe, fixes bug 540705.

svn path=/trunk/; revision=1717

ChangeLog
ccode/valaccodedeclaration.vala
ccode/valaccodemodifiers.vala
gobject/valaclassregisterfunction.vala
gobject/valainterfaceregisterfunction.vala
gobject/valatyperegisterfunction.vala

index 92a5612d511d02c54dcc068ea564fc428dc88d61..2756f0513fd91ca79f03b20bf11a5f7be1d76b15 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-07-22  Jared Moore  <jaredm@svn.gnome.org>
+
+       * ccode/valaccodedeclaration.vala:
+       * ccode/valaccodemodifiers.vala:
+
+       Added support for 'volatile' modifier in C code.
+
+       * gobject/valatyperegisterfunction.vala:
+
+       Make *_get_type functions thread safe, fixes bug 540705.
+
 2008-07-22  Jared Moore  <jaredm@svn.gnome.org>
 
        * gobject/valaccodeclassbinding.vala:
index eb7ada541a6bab83646b025a470be030a00c0e97..7a0223bab26d9c9b195b608e1ff1267ffc574b48 100644 (file)
@@ -59,6 +59,9 @@ public class Vala.CCodeDeclaration : CCodeStatement {
                        if ((modifiers & CCodeModifiers.STATIC) != 0) {
                                writer.write_string ("static ");
                        }
+                       if ((modifiers & CCodeModifiers.VOLATILE) != 0) {
+                               writer.write_string ("volatile ");
+                       }
                        if ((modifiers & CCodeModifiers.EXTERN) != 0 && !has_initializer ()) {
                                writer.write_string ("extern ");
                        }
index 670bf4e12f2628b997ccf92002182199a76c9df2..90f6809c8b399540ef22e54a862f18701325f3b2 100644 (file)
@@ -29,5 +29,6 @@ public enum Vala.CCodeModifiers {
        STATIC = 1 << 0,
        REGISTER = 1 << 1,
        EXTERN = 1 << 2,
-       INLINE = 1 << 3
+       INLINE = 1 << 3,
+       VOLATILE = 1 << 4
 }
index fa131bee659867bfcbc32d64714f3726fb47436b..5e97b8044b2ff84a0b0c7b50e573ea4cc4a4fad6 100644 (file)
@@ -119,7 +119,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
                        var iface_info_name = "%s_info".printf (iface.get_lower_case_cname (null));
                        
                        var reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_add_interface_static"));
-                       reg_call.add_argument (new CCodeIdentifier ("%s_type_id".printf (class_reference.get_lower_case_cname (null))));
+                       reg_call.add_argument (new CCodeIdentifier ("%s_type_id_temp".printf (class_reference.get_lower_case_cname (null))));
                        reg_call.add_argument (new CCodeIdentifier (iface.get_type_id ()));
                        reg_call.add_argument (new CCodeIdentifier ("&%s".printf (iface_info_name)));
                        frag.append (new CCodeExpressionStatement (reg_call));
index 3be408ceb37e95beb0b05b50af0780ca2d6a6784..b56d141471307d13f77df8c71e31e6ab4dd95600 100644 (file)
@@ -76,7 +76,7 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
                        var prereq = prereq_ref.data_type;
                        
                        var func = new CCodeFunctionCall (new CCodeIdentifier ("g_type_interface_add_prerequisite"));
-                       func.add_argument (new CCodeIdentifier ("%s_type_id".printf (interface_reference.get_lower_case_cname (null))));
+                       func.add_argument (new CCodeIdentifier ("%s_type_id_temp".printf (interface_reference.get_lower_case_cname (null))));
                        func.add_argument (new CCodeIdentifier (prereq.get_type_id()));
                        
                        frag.append (new CCodeExpressionStatement (func));
index 3e81a514603f3144c492cba7641dea6144cf7f4c..7e627dd87ffdc057520f3fa7ec8db50c6682c76e 100644 (file)
@@ -43,9 +43,9 @@ public abstract class Vala.TypeRegisterFunction : Object {
                string type_id_name = "%s_type_id".printf (get_type_declaration ().get_lower_case_cname (null));
 
                var type_block = new CCodeBlock ();
-               var cdecl = new CCodeDeclaration ("GType");
+               var cdecl = new CCodeDeclaration ("gsize");
                cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer (type_id_name, new CCodeConstant ("0")));
-               cdecl.modifiers = CCodeModifiers.STATIC;
+               cdecl.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
                if (!plugin) {
                        type_block.add_statement (cdecl);
                } else {
@@ -110,14 +110,26 @@ public abstract class Vala.TypeRegisterFunction : Object {
                        reg_call.add_argument (new CCodeIdentifier ("&g_define_type_fundamental_info"));
                }
                reg_call.add_argument (new CCodeConstant (get_type_flags ()));
-               type_init.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier (type_id_name), reg_call)));
+
+               string temp_type_id_name = "%s_type_id_temp".printf (get_type_declaration ().get_lower_case_cname (null));
+               if (!plugin) {
+                       var temp_decl = new CCodeDeclaration ("GType");
+                       temp_decl.add_declarator (new CCodeVariableDeclarator.with_initializer (temp_type_id_name, reg_call));
+                       type_init.add_statement (temp_decl);
+               } else {
+                       type_init.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier (type_id_name), reg_call)));
+               }
                
                type_init.add_statement (get_type_interface_init_statements ());
 
                if (!plugin) {
-                       var cond = new CCodeFunctionCall (new CCodeIdentifier ("G_UNLIKELY"));
-                       cond.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier (type_id_name), new CCodeConstant ("0")));
-                       var cif = new CCodeIfStatement (cond, type_init);
+                       var enter = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_enter"));
+                       enter.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (type_id_name)));
+                       var leave = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_leave"));
+                       leave.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (type_id_name)));
+                       leave.add_argument (new CCodeIdentifier (temp_type_id_name));
+                       type_init.add_statement (new CCodeExpressionStatement (leave));
+                       var cif = new CCodeIfStatement (enter, type_init);
                        type_block.add_statement (cif);
                } else {
                        type_block = type_init;