From: <br...@us...> - 2012-04-29 08:06:51
|
Revision: 4277 http://openvrml.svn.sourceforge.net/openvrml/?rev=4277&view=rev Author: braden Date: 2012-04-29 08:06:42 +0000 (Sun, 29 Apr 2012) Log Message: ----------- As of XULRunner 12.0, JSRuntime should now be used by a single thread. For now, at least, employ a JSRuntime for each Script node. Modified Paths: -------------- branches/0.18/ChangeLog branches/0.18/src/script/javascript.cpp Property Changed: ---------------- branches/0.18/ Property changes on: branches/0.18 ___________________________________________________________________ Modified: svn:mergeinfo - /branches/0.17:3713,3717,3719,3721,3725,3730,3732,3743,3746,3748,3750,3752,3754,3757,3759-3760,3764,3766,3824,3828,3836 /branches/local:3677-3689 /branches/node-modules:3622-3623,3632-3635,3637-3638,3640-3641,3643-3644,3646-3647,3649-3650,3654-3655,3657-3658,3661-3662,3664-3665,3667-3668,3670-3671,3673-3674,3684-3685,3687-3688,3736-3801 /trunk:3958,3965,3967,3969,3971,3973,3975-3976,3979,3981,3983,3985,3987,3989,3991,3997,3999,4001,4003,4005,4011,4013-4014,4017,4019,4021,4024,4026,4028,4030,4032,4041,4043,4045,4047,4053,4055,4057,4059,4061,4063,4065,4067,4069,4071,4073,4075,4077,4079,4081,4083,4085,4087,4089,4091,4093,4095,4097,4099,4101,4107-4108,4113,4115,4117,4119-4120,4122,4124,4129,4131,4133,4135,4137,4139,4141,4143,4145,4147-4148,4150,4156,4159-4160,4162,4164,4169,4171,4174,4178-4179,4181,4183,4186,4188,4190,4192,4194,4196,4198-4199,4201,4203,4206,4208,4210,4212,4214,4216,4218,4220,4222,4224,4226,4228,4230,4232,4236,4243,4245,4247,4249,4251,4253,4255,4257,4259,4261,4264,4266,4268,4270,4272,4274 + /branches/0.17:3713,3717,3719,3721,3725,3730,3732,3743,3746,3748,3750,3752,3754,3757,3759-3760,3764,3766,3824,3828,3836 /branches/local:3677-3689 /branches/node-modules:3622-3623,3632-3635,3637-3638,3640-3641,3643-3644,3646-3647,3649-3650,3654-3655,3657-3658,3661-3662,3664-3665,3667-3668,3670-3671,3673-3674,3684-3685,3687-3688,3736-3801 /trunk:3958,3965,3967,3969,3971,3973,3975-3976,3979,3981,3983,3985,3987,3989,3991,3997,3999,4001,4003,4005,4011,4013-4014,4017,4019,4021,4024,4026,4028,4030,4032,4041,4043,4045,4047,4053,4055,4057,4059,4061,4063,4065,4067,4069,4071,4073,4075,4077,4079,4081,4083,4085,4087,4089,4091,4093,4095,4097,4099,4101,4107-4108,4113,4115,4117,4119-4120,4122,4124,4129,4131,4133,4135,4137,4139,4141,4143,4145,4147-4148,4150,4156,4159-4160,4162,4164,4169,4171,4174,4178-4179,4181,4183,4186,4188,4190,4192,4194,4196,4198-4199,4201,4203,4206,4208,4210,4212,4214,4216,4218,4220,4222,4224,4226,4228,4230,4232,4236,4243,4245,4247,4249,4251,4253,4255,4257,4259,4261,4264,4266,4268,4270,4272,4274,4276 Modified: branches/0.18/ChangeLog =================================================================== --- branches/0.18/ChangeLog 2012-04-29 08:04:55 UTC (rev 4276) +++ branches/0.18/ChangeLog 2012-04-29 08:06:42 UTC (rev 4277) @@ -1,5 +1,11 @@ 2012-04-29 Braden McDaniel <br...@en...> + * src/script/javascript.cpp: As of XULRunner 12.0, JSRuntime + should now be used by a single thread. For now, at least, employ + a JSRuntime for each Script node. + +2012-04-29 Braden McDaniel <br...@en...> + * src/script/javascript.cpp: Fix copy/paste error. 2012-04-29 Braden McDaniel <br...@en...> Modified: branches/0.18/src/script/javascript.cpp =================================================================== --- branches/0.18/src/script/javascript.cpp 2012-04-29 08:04:55 UTC (rev 4276) +++ branches/0.18/src/script/javascript.cpp 2012-04-29 08:06:42 UTC (rev 4277) @@ -264,13 +264,15 @@ friend OPENVRML_DECLARE_MEMBER_JSNATIVE(Browser, addRoute); friend OPENVRML_DECLARE_MEMBER_JSNATIVE(Browser, deleteRoute); - static JSRuntime * rt; - static size_t nInstances; + JSRuntime * rt; double d_timeStamp; JSContext * cx; JSClass & sfnode_class; +# ifndef NDEBUG + boost::thread::id thread_id_; +# endif public: script(openvrml::script_node & node, @@ -1014,9 +1016,6 @@ VrmlMatrix(); }; - JSRuntime * script::rt = 0; // Javascript runtime singleton object - size_t script::nInstances = 0; // Number of distinct script objects - OPENVRML_JAVASCRIPT_LOCAL OPENVRML_DECLARE_JSSTRICTPROPERTYOP(eventOut_setProperty); @@ -1030,28 +1029,28 @@ script:: script(openvrml::script_node & node, const boost::shared_ptr<openvrml::resource_istream> & source) - OPENVRML_THROW1(std::bad_alloc): - openvrml::script(node), + OPENVRML_THROW1(std::bad_alloc): + openvrml::script(node), + rt(0), cx(0), sfnode_class(this->direct_output() ? SFNode::direct_output_jsclass - : SFNode::jsclass) + : SFNode::jsclass), + thread_id_(boost::this_thread::get_id()) { using std::bad_alloc; // // Initialize the runtime. // - if (!rt && !(rt = JS_NewRuntime(MAX_HEAP_BYTES))) { - throw bad_alloc(); - } + this->rt = JS_NewRuntime(MAX_HEAP_BYTES); + if (!this->rt) { throw bad_alloc(); } // // Initialize the context for this script object. // - if (!(this->cx = JS_NewContext(rt, STACK_CHUNK_BYTES))) { - throw bad_alloc(); - } + this->cx = JS_NewContext(rt, STACK_CHUNK_BYTES); + if (!this->cx) { throw bad_alloc(); } // // Store a pointer to this script object in the context. @@ -1131,17 +1130,12 @@ source_str.c_str(), source_str.length(), filename, lineno, &rval); OPENVRML_VERIFY_(ok); - - ++nInstances; } script::~script() { JS_DestroyContext(this->cx); - if (--nInstances == 0) { - JS_DestroyRuntime(rt); - rt = 0; - } + JS_DestroyRuntime(this->rt); } void script::do_initialize(const double timestamp) @@ -1187,14 +1181,8 @@ const openvrml::field_value * const argv[]) { assert(this->cx); + assert(this->thread_id_ == boost::this_thread::get_id()); -# ifdef JS_THREADSAFE - JS_SetContextThread(this->cx); - BOOST_SCOPE_EXIT((cx)) { - JS_ClearContextThread(cx); - } BOOST_SCOPE_EXIT_END -# endif - jsval fval, rval; JSObject * const globalObj = JS_GetGlobalObject(this->cx); assert(globalObj); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |