[vala] Use thread-local storage for context stack
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] Use thread-local storage for context stack
- Date: Mon, 30 Mar 2009 11:48:19 -0400 (EDT)
commit 7549e692d222110f77ad792723d26bf85b4693b3
Author: Jürg Billeter <j bitron ch>
Date: Mon Mar 30 17:45:41 2009 +0200
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.
---
vala/valacodecontext.vala | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index c74097d..1841528 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -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);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]