From: Juerg Billeter Date: Tue, 10 Jul 2007 07:46:04 +0000 (+0000) Subject: add --thread option to enable multithreading support X-Git-Tag: VALA_0_1_1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d501ef0b2cef38e5ae753629fba622c39f202e95;p=thirdparty%2Fvala.git add --thread option to enable multithreading support 2007-07-10 Juerg Billeter * vala/valacodecontext.vala, gobject/valaccodecompiler.vala, gobject/valacodegeneratormethod.vala, compiler/valacompiler.vala: add --thread option to enable multithreading support svn path=/trunk/; revision=340 --- diff --git a/ChangeLog b/ChangeLog index abb7abe46..12afd726c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-07-10 Jürg Billeter + + * vala/valacodecontext.vala, gobject/valaccodecompiler.vala, + gobject/valacodegeneratormethod.vala, compiler/valacompiler.vala: + add --thread option to enable multithreading support + 2007-07-10 Jürg Billeter * gobject/valaccodecompiler.vala: always use gobject-2.0 diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index e0381ed3c..f63377d04 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -38,6 +38,7 @@ class Vala.Compiler { static bool compile_only; static string output; static bool debug; + static bool thread; static int optlevel; static bool disable_assert; static bool enable_checking; @@ -55,6 +56,7 @@ class Vala.Compiler { { "compile", 'c', 0, OptionArg.NONE, ref compile_only, "Compile but do not link", null }, { "output", 'o', 0, OptionArg.FILENAME, out output, "Place output in file FILE", "FILE" }, { "debug", 'g', 0, OptionArg.NONE, ref debug, "Produce debug information", null }, + { "thread", 0, 0, OptionArg.NONE, ref thread, "Enable multithreading support", null }, { "optimize", 'O', 0, OptionArg.INT, ref optlevel, "Optimization level", "OPTLEVEL" }, { "disable-assert", 0, 0, OptionArg.NONE, ref disable_assert, "Disable assertions", null }, { "enable-checking", 0, 0, OptionArg.NONE, ref enable_checking, "Enable run-time checks", null }, @@ -152,6 +154,7 @@ class Vala.Compiler { context.compile_only = compile_only; context.output = output; context.debug = debug; + context.thread = thread; context.optlevel = optlevel; /* default package */ diff --git a/gobject/valaccodecompiler.vala b/gobject/valaccodecompiler.vala index cb10ce17a..9d7e2d1ed 100644 --- a/gobject/valaccodecompiler.vala +++ b/gobject/valaccodecompiler.vala @@ -41,6 +41,9 @@ public class Vala.CCodeCompiler { pc += " --libs"; } pc += " gobject-2.0"; + if (context.thread) { + pc += " gthread-2.0"; + } foreach (string pkg in context.get_packages ()) { pc += " " + pkg; } diff --git a/gobject/valacodegeneratormethod.vala b/gobject/valacodegeneratormethod.vala index 270e3d5b2..211ab3782 100644 --- a/gobject/valacodegeneratormethod.vala +++ b/gobject/valacodegeneratormethod.vala @@ -311,6 +311,13 @@ public class Vala.CodeGenerator { cmain.add_parameter (new CCodeFormalParameter ("argc", "int")); cmain.add_parameter (new CCodeFormalParameter ("argv", "char **")); var main_block = new CCodeBlock (); + + if (context.thread) { + var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init")); + thread_init_call.add_argument (new CCodeConstant ("NULL")); + main_block.add_statement (new CCodeExpressionStatement (thread_init_call)); + } + main_block.add_statement (new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")))); var main_call = new CCodeFunctionCall (new CCodeIdentifier (function.name)); if (args_parameter) { diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 6d1271a7e..068c4eedc 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -74,6 +74,11 @@ public class Vala.CodeContext { */ public int optlevel { get; set; } + /** + * Enable multithreading support. + */ + public bool thread { get; set; } + /** * Specifies the optional module initialization method. */