summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/js/eval.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-08-14 21:53:15 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-08-14 21:53:15 +0000
commitc7bac19b004d7796be38db919c777c1da2b1fcf1 (patch)
tree392a2c487ae933ed697b21028f0bd89968472e42 /sca-cpp/trunk/modules/js/eval.hpp
parentd6e80180e79f9f454a6e68caa81f0b24bdd8857d (diff)
Switch from the HTTPD prefork MPM to the multi-threaded event MPM where possible. Fix multi-threading issues in the SpiderMonkey integration.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1157676 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/js/eval.hpp')
-rw-r--r--sca-cpp/trunk/modules/js/eval.hpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/sca-cpp/trunk/modules/js/eval.hpp b/sca-cpp/trunk/modules/js/eval.hpp
index b36c9e6119..f18c3e41c9 100644
--- a/sca-cpp/trunk/modules/js/eval.hpp
+++ b/sca-cpp/trunk/modules/js/eval.hpp
@@ -103,14 +103,23 @@ JSClass jsGlobalClass = { "global", JSCLASS_GLOBAL_FLAGS,
JSCLASS_NO_OPTIONAL_MEMBERS };
/**
- * Represents a JavaScript context. Create one per thread.
+ * Represents a JavaScript context. Maintains one context per thread.
*/
+#ifdef WANT_THREADS
+__thread
+#endif
+::JSContext* jsContext = NULL;
+
class JSContext {
public:
JSContext() {
- // Create JS context
+ // Create JS context if necessary
debug("js::jscontext");
- cx = JS_NewContext(jsRuntime, 8192);
+ if (jsContext != NULL) {
+ cx = jsContext;
+ return;
+ }
+ cx = JS_NewContext(jsRuntime, 32768);
if(cx == NULL)
return;
JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
@@ -129,10 +138,13 @@ public:
cleanup();
return;
}
+ jsContext = cx;
}
~JSContext() {
debug("js::~jscontext");
+ if (cx != NULL)
+ JS_GC(cx);
cleanup();
}
@@ -147,7 +159,8 @@ public:
private:
bool cleanup() {
if(cx != NULL) {
- JS_DestroyContext(cx);
+ if (cx != jsContext)
+ JS_DestroyContext(cx);
cx = NULL;
}
return true;