static bool print_eval;
static void CheckStatus(uv_timer_t* watcher, int status);
-static unsigned long NewThreadId();
-void StartThread(unsigned long thread_id,
- Isolate* isolate,
+void StartThread(Isolate* isolate,
int argc,
char** argv);
}
-static struct {
- uv_mutex_t lock_;
- unsigned long counter_;
-} thread_id_generator_;
-
-
-static unsigned long NewThreadId() {
- unsigned long thread_id;
-
- uv_mutex_lock(&thread_id_generator_.lock_);
- thread_id = ++thread_id_generator_.counter_;
- uv_mutex_unlock(&thread_id_generator_.lock_);
-
- return thread_id;
-}
-
-
struct ThreadInfo {
- unsigned long thread_id_;
uv_thread_t thread_;
char** argv_;
int argc_;
uv_loop_t* loop = uv_loop_new();
Isolate* isolate = Isolate::New(loop);
- StartThread(ti->thread_id_, isolate, ti->argc_, ti->argv_);
+ StartThread(isolate, ti->argc_, ti->argv_);
delete ti;
}
assert(argv->Length() >= 2);
ThreadInfo* ti = new ThreadInfo(argv);
- ti->thread_id_ = NewThreadId();
if (uv_thread_create(&ti->thread_, RunIsolate, ti)) {
delete ti;
// Create a new isolate with node::Isolate::New() before you call this function
-void StartThread(unsigned long thread_id,
- Isolate* isolate,
+void StartThread(node::Isolate* isolate,
int argc,
char** argv) {
HandleScope scope;
Handle<Object> process_l = SetupProcessObject(argc, argv);
process_l->Set(String::NewSymbol("tid"),
- Integer::NewFromUnsigned(thread_id));
+ Integer::NewFromUnsigned(isolate->id_));
// FIXME crashes with "CHECK(heap->isolate() == Isolate::Current()) failed"
//v8_typed_array::AttachBindings(v8::Context::GetCurrent()->Global());
int Start(int argc, char *argv[]) {
- if (uv_mutex_init(&thread_id_generator_.lock_)) abort();
-
// This needs to run *before* V8::Initialize()
argv = ProcessInit(argc, argv);
v8::HandleScope handle_scope;
// Create the main node::Isolate object
- Isolate* isolate = Isolate::New(uv_default_loop());
- StartThread(NewThreadId(), isolate, argc, argv);
+ node::Isolate::Initialize();
+ Isolate* isolate = node::Isolate::New(uv_default_loop());
+ StartThread(isolate, argc, argv);
isolate->Dispose();
#ifndef NDEBUG
#include <assert.h>
+
namespace node {
+static volatile bool initialized;
+static volatile int id;
+static uv_mutex_t id_lock;
+
+void Isolate::Initialize() {
+ if (!initialized) {
+ initialized = true;
+ if (uv_mutex_init(&id_lock)) abort();
+ }
+}
Isolate* Isolate::New(uv_loop_t* loop) {
return new Isolate(loop);
Isolate::Isolate(uv_loop_t* loop) {
+ assert(initialized && "node::Isolate::Initialize() hasn't been called");
+
+ uv_mutex_lock(&id_lock);
+ id_ = ++id;
+ uv_mutex_unlock(&id_lock);
+
ngx_queue_init(&at_exit_callbacks_);
loop_ = loop;