From c7bac19b004d7796be38db919c777c1da2b1fcf1 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 14 Aug 2011 21:53:15 +0000 Subject: 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 --- sca-cpp/trunk/modules/js/eval.hpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'sca-cpp/trunk/modules/js') 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; -- cgit v1.2.3