]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Use thread-local storage for context stack
authorJürg Billeter <j@bitron.ch>
Mon, 30 Mar 2009 15:45:41 +0000 (17:45 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 30 Mar 2009 15:45:41 +0000 (17:45 +0200)
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.

vala/valacodecontext.vala

index c74097d4b8711ec333674b4d91b8dbc2810f79b6..1841528403039eb17b7e07835ad543753098529e 100644 (file)
@@ -168,7 +168,7 @@ public class Vala.CodeContext {
 
        private Gee.List<string> packages = new ArrayList<string> (str_equal);
 
-       static Gee.List<CodeContext> 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<CodeContext>* 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<CodeContext>* context_stack = context_stack_key.get ();
                if (context_stack == null) {
                        context_stack = new ArrayList<CodeContext> ();
+                       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<CodeContext>* context_stack = context_stack_key.get ();
+
+               context_stack->remove_at (context_stack->size - 1);
        }
 
        /**