From: Jürg Billeter Date: Mon, 30 Mar 2009 15:45:41 +0000 (+0200) Subject: Use thread-local storage for context stack X-Git-Tag: 0.6.0~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7549e692d222110f77ad792723d26bf85b4693b3;p=thirdparty%2Fvala.git Use thread-local storage for context stack Make it possible to use libvala from multiple threads by using a thread-local stack of CodeContext objects. Based on patch by Andrea Del Signore, fixes bug 573041. --- diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index c74097d4b..184152840 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -168,7 +168,7 @@ public class Vala.CodeContext { private Gee.List packages = new ArrayList (str_equal); - static Gee.List context_stack; + static StaticPrivate context_stack_key = StaticPrivate (); /** * The root namespace of the symbol tree. @@ -191,24 +191,31 @@ public class Vala.CodeContext { * Return the topmost context from the context stack. */ public static CodeContext get () { - return context_stack[context_stack.size - 1]; + Gee.List* context_stack = context_stack_key.get (); + + return context_stack->get (context_stack->size - 1); } /** * Push the specified context to the context stack. */ public static void push (CodeContext context) { + Gee.List* context_stack = context_stack_key.get (); if (context_stack == null) { context_stack = new ArrayList (); + context_stack_key.set (context_stack, null); } - context_stack.add (context); + + context_stack->add (context); } /** * Remove the topmost context from the context stack. */ public static void pop () { - context_stack.remove_at (context_stack.size - 1); + Gee.List* context_stack = context_stack_key.get (); + + context_stack->remove_at (context_stack->size - 1); } /**