Browse Source

isolates have globals stored in struct globals

v0.7.4-release
Ryan Dahl 13 years ago
parent
commit
9caeceef6d
  1. 7
      src/node_isolate.cc
  2. 6
      src/node_isolate.h
  3. 17
      src/node_vars.cc
  4. 5
      src/node_vars.h

7
src/node_isolate.cc

@ -46,6 +46,13 @@ Isolate::Isolate(uv_loop_t* loop) {
assert(isolate_->GetData() == NULL); assert(isolate_->GetData() == NULL);
isolate_->SetData(this); isolate_->SetData(this);
globals_init(&globals_);
}
struct globals* Isolate::Globals() {
return &globals_;
} }

6
src/node_isolate.h

@ -25,6 +25,7 @@
#include "queue.h" #include "queue.h"
#include "v8.h" #include "v8.h"
#include "uv.h" #include "uv.h"
#include "node_vars.h"
#ifdef NDEBUG #ifdef NDEBUG
# define NODE_ISOLATE_CHECK(ptr) ((void) (ptr)) # define NODE_ISOLATE_CHECK(ptr) ((void) (ptr))
@ -69,6 +70,8 @@ public:
/* Shutdown the isolate. Call this method at thread death. */ /* Shutdown the isolate. Call this method at thread death. */
void Dispose(); void Dispose();
struct globals* Globals();
private: private:
Isolate(uv_loop_t* loop); Isolate(uv_loop_t* loop);
@ -81,6 +84,9 @@ private:
SLIST_HEAD(AtExitCallbacks, AtExitCallbackInfo) at_exit_callbacks_; SLIST_HEAD(AtExitCallbacks, AtExitCallbackInfo) at_exit_callbacks_;
v8::Isolate* isolate_; v8::Isolate* isolate_;
uv_loop_t* loop_; uv_loop_t* loop_;
// Global variables for this isolate.
struct globals globals_;
}; };
} // namespace node } // namespace node

17
src/node_vars.cc

@ -1,4 +1,5 @@
#include <node_vars.h> #include <node_vars.h>
#include <node_isolate.h>
#if HAVE_OPENSSL #if HAVE_OPENSSL
# include <node_crypto.h> # include <node_crypto.h>
#endif #endif
@ -9,11 +10,7 @@ namespace node {
// For now we just statically initialize the globals structure. Later there // For now we just statically initialize the globals structure. Later there
// will be one struct globals for each isolate. // will be one struct globals for each isolate.
static struct globals g_struct; void globals_init(struct globals* g) {
static struct globals* g_ptr;
static void globals_init(struct globals* g) {
memset(g, 0, sizeof(struct globals)); memset(g, 0, sizeof(struct globals));
g->debug_port = 5858; g->debug_port = 5858;
@ -31,6 +28,15 @@ static void globals_init(struct globals* g) {
} }
#if HAVE_ISOLATES
struct globals* globals_get() {
node::Isolate* isolate = node::Isolate::GetCurrent();
return isolate->Globals();
}
#else
static struct globals g_struct;
static struct globals* g_ptr;
struct globals* globals_get() { struct globals* globals_get() {
if (!g_ptr) { if (!g_ptr) {
g_ptr = &g_struct; g_ptr = &g_struct;
@ -38,5 +44,6 @@ struct globals* globals_get() {
} }
return g_ptr; return g_ptr;
} }
#endif // HAVE_ISOLATES
} // namespace node } // namespace node

5
src/node_vars.h

@ -183,6 +183,11 @@ struct globals {
::ares_channel ares_channel; ::ares_channel ares_channel;
}; };
// Initialize globals struct.
void globals_init(struct globals*);
// Get the globals struct for the current Isolate. The returned pointer is
// already initialized.
struct globals* globals_get(); struct globals* globals_get();
} // namespace node } // namespace node

Loading…
Cancel
Save