Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Begin moving static vars into struct for isolates.

Only node.cc, stream_wrap.cc, and tcp_wrap.cc have been done. The rest still
need work.
  • Loading branch information...
commit e0a207c27a5e366b89133df3b60394e6cac7876b 1 parent ebe0fb6
@ry ry authored
View
2  node.gyp
@@ -72,6 +72,7 @@
'src/cares_wrap.cc',
'src/handle_wrap.cc',
'src/node.cc',
+ 'src/node_vars.cc',
'src/node_buffer.cc',
'src/node_constants.cc',
'src/node_extensions.cc',
@@ -94,6 +95,7 @@
# headers to make for a more pleasant IDE experience
'src/handle_wrap.h',
'src/node.h',
+ 'src/node_vars.h',
'src/node_buffer.h',
'src/node_constants.h',
'src/node_crypto.h',
View
99 src/node.cc
@@ -95,76 +95,51 @@ using namespace v8;
extern char **environ;
# endif
-namespace node {
-
-static Persistent<Object> process;
-
-static Persistent<String> errno_symbol;
-static Persistent<String> syscall_symbol;
-static Persistent<String> errpath_symbol;
-static Persistent<String> code_symbol;
-
-static Persistent<String> rss_symbol;
-static Persistent<String> heap_total_symbol;
-static Persistent<String> heap_used_symbol;
-
-static Persistent<String> listeners_symbol;
-static Persistent<String> uncaught_exception_symbol;
-static Persistent<String> emit_symbol;
+#include <node_vars.h>
+
+// We do the following to minimize the detal between v0.6 branch. We want to
+// use the variables as they were being used before.
+#define check_tick_watcher NODE_VAR(check_tick_watcher)
+#define code_symbol NODE_VAR(code_symbol)
+#define debug_port NODE_VAR(debug_port)
+#define debug_wait_connect NODE_VAR(debug_wait_connect)
+#define emit_symbol NODE_VAR(emit_symbol)
+#define errno_symbol NODE_VAR(errno_symbol)
+#define errpath_symbol NODE_VAR(errpath_symbol)
+#define eval_string NODE_VAR(eval_string)
+#define gc_check NODE_VAR(gc_check)
+#define gc_idle NODE_VAR(gc_idle)
+#define gc_timer NODE_VAR(gc_timer)
+#define getbuf NODE_VAR(getbuf)
+#define heap_total_symbol NODE_VAR(heap_total_symbol)
+#define heap_used_symbol NODE_VAR(heap_used_symbol)
+#define listeners_symbol NODE_VAR(listeners_symbol)
+#define max_stack_size NODE_VAR(max_stack_size)
+#define need_tick_cb NODE_VAR(need_tick_cb)
+#define option_end_index NODE_VAR(option_end_index)
+#define prepare_tick_watcher NODE_VAR(prepare_tick_watcher)
+#define print_eval NODE_VAR(print_eval)
+#define process NODE_VAR(process)
+#define rss_symbol NODE_VAR(rss_symbol)
+#define syscall_symbol NODE_VAR(syscall_symbol)
+#define tick_callback_sym NODE_VAR(tick_callback_sym)
+#define tick_spinner NODE_VAR(tick_spinner)
+#define tick_time_head NODE_VAR(tick_time_head)
+#define tick_times NODE_VAR(tick_times)
+#define uncaught_exception_symbol NODE_VAR(uncaught_exception_symbol)
+#define use_debug_agent NODE_VAR(use_debug_agent)
+#define use_npn NODE_VAR(use_npn)
+#define use_sni NODE_VAR(use_sni)
-static bool print_eval = false;
-static char *eval_string = NULL;
-static int option_end_index = 0;
-static bool use_debug_agent = false;
-static bool debug_wait_connect = false;
-static int debug_port=5858;
-static int max_stack_size = 0;
-static uv_check_t check_tick_watcher;
-static uv_prepare_t prepare_tick_watcher;
-static uv_idle_t tick_spinner;
-static bool need_tick_cb;
-static Persistent<String> tick_callback_sym;
-
-
-#ifdef OPENSSL_NPN_NEGOTIATED
-static bool use_npn = true;
-#else
-static bool use_npn = false;
-#endif
+namespace node {
-#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
-static bool use_sni = true;
-#else
-static bool use_sni = false;
-#endif
-#ifdef __POSIX__
-// Buffer for getpwnam_r(), getgrpam_r() and other misc callers; keep this
-// scoped at file-level rather than method-level to avoid excess stack usage.
-static char getbuf[PATH_MAX + 1];
-#endif
-// We need to notify V8 when we're idle so that it can run the garbage
-// collector. The interface to this is V8::IdleNotification(). It returns
-// true if the heap hasn't be fully compacted, and needs to be run again.
-// Returning false means that it doesn't have anymore work to do.
-//
-// A rather convoluted algorithm has been devised to determine when Node is
-// idle. You'll have to figure it out for yourself.
-static uv_check_t gc_check;
-static uv_idle_t gc_idle;
-static uv_timer_t gc_timer;
-bool need_gc;
+#define TICK_TIME(n) tick_times[(tick_time_head - (n)) % RPM_SAMPLES]
-#define FAST_TICK 700.
-#define GC_WAIT_TIME 5000.
-#define RPM_SAMPLES 100
-#define TICK_TIME(n) tick_times[(tick_time_head - (n)) % RPM_SAMPLES]
-static int64_t tick_times[RPM_SAMPLES];
-static int tick_time_head;
static void CheckStatus(uv_timer_t* watcher, int status);
View
42 src/node_vars.cc
@@ -0,0 +1,42 @@
+#include <node_vars.h>
+#if HAVE_OPENSSL
+# include <node_crypto.h>
+#endif
+#include <string.h>
+
+namespace node {
+
+// For now we just statically initialize the globals structure. Later there
+// will be one struct globals for each isolate.
+
+static struct globals g_struct;
+static struct globals* g_ptr;
+
+
+static void globals_init(struct globals* g) {
+ memset(g, 0, sizeof(struct globals));
+ g->debug_port = 5858;
+
+#ifdef OPENSSL_NPN_NEGOTIATED
+ g->use_npn = true;
+#else
+ g->use_npn = false;
+#endif
+
+#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
+ g->use_sni = true;
+#else
+ g->use_sni = false;
+#endif
+}
+
+
+struct globals* globals_get() {
+ if (!g_ptr) {
+ g_ptr = &g_struct;
+ globals_init(g_ptr);
+ }
+ return g_ptr;
+}
+
+} // namespace node
View
92 src/node_vars.h
@@ -0,0 +1,92 @@
+#ifndef NODE_VARS_H
+#define NODE_VARS_H
+
+// This file contains all Isolate-local variables. We allow people to
+// compile Node either with Isolates or without. In the case that they
+// compile without isolates, these will be static variables.
+
+#include <v8.h>
+#include <uv.h>
+
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+
+namespace node {
+
+
+#define NODE_VAR(x) (globals_get()->x)
+
+struct globals {
+ // node.cc
+ v8::Persistent<v8::Object> process;
+ v8::Persistent<v8::String> errno_symbol;
+ v8::Persistent<v8::String> syscall_symbol;
+ v8::Persistent<v8::String> errpath_symbol;
+ v8::Persistent<v8::String> code_symbol;
+ v8::Persistent<v8::String> rss_symbol;
+ v8::Persistent<v8::String> heap_total_symbol;
+ v8::Persistent<v8::String> heap_used_symbol;
+ v8::Persistent<v8::String> listeners_symbol;
+ v8::Persistent<v8::String> uncaught_exception_symbol;
+ v8::Persistent<v8::String> emit_symbol;
+
+ // stream_wrap.cc
+ size_t slab_used;
+ uv_stream_t* handle_that_last_alloced;
+ v8::Persistent<v8::String> slab_sym;
+ v8::Persistent<v8::String> buffer_sym;
+ v8::Persistent<v8::String> write_queue_size_sym;
+ bool stream_wrap_initialized;
+
+ // tcp_wrap.cc
+ v8::Persistent<v8::Function> tcpConstructor;
+ v8::Persistent<v8::String> family_symbol;
+ v8::Persistent<v8::String> address_symbol;
+ v8::Persistent<v8::String> port_symbol;
+
+ bool print_eval;
+ char *eval_string;
+ int option_end_index;
+ bool use_debug_agent;
+ bool debug_wait_connect;
+ int debug_port;
+ int max_stack_size;
+
+ uv_check_t check_tick_watcher;
+ uv_prepare_t prepare_tick_watcher;
+ uv_idle_t tick_spinner;
+ bool need_tick_cb;
+ v8::Persistent<v8::String> tick_callback_sym;
+
+ bool use_npn;
+ bool use_sni;
+
+ // Buffer for getpwnam_r(), getgrpam_r() and other misc callers; keep this
+ // scoped at file-level rather than method-level to avoid excess stack usage.
+ char getbuf[PATH_MAX + 1];
+
+ // We need to notify V8 when we're idle so that it can run the garbage
+ // collector. The interface to this is V8::IdleNotification(). It returns
+ // true if the heap hasn't be fully compacted, and needs to be run again.
+ // Returning false means that it doesn't have anymore work to do.
+ //
+ // A rather convoluted algorithm has been devised to determine when Node is
+ // idle. You'll have to figure it out for yourself.
+ uv_check_t gc_check;
+ uv_idle_t gc_idle;
+ uv_timer_t gc_timer;
+ bool need_gc;
+
+# define FAST_TICK 700.
+# define GC_WAIT_TIME 5000.
+# define RPM_SAMPLES 100
+
+ int64_t tick_times[RPM_SAMPLES];
+ int tick_time_head;
+};
+
+struct globals* globals_get();
+
+} // namespace node
+#endif // NODE_VARS_H
View
23 src/stream_wrap.cc
@@ -26,6 +26,17 @@
#include <tcp_wrap.h>
#include <req_wrap.h>
+#include <node_vars.h>
+
+// We do the following to minimize the detal between v0.6 branch. We want to
+// use the variables as they were being used before.
+#define slab_used NODE_VAR(slab_used)
+#define slab_sym NODE_VAR(slab_sym)
+#define handle_that_last_alloced NODE_VAR(handle_that_last_alloced)
+#define buffer_sym NODE_VAR(buffer_sym)
+#define write_queue_size_sym NODE_VAR(write_queue_size_sym)
+#define stream_wrap_initialized NODE_VAR(stream_wrap_initialized)
+
namespace node {
@@ -66,19 +77,11 @@ typedef class ReqWrap<uv_shutdown_t> ShutdownWrap;
typedef class ReqWrap<uv_write_t> WriteWrap;
-static size_t slab_used;
-static uv_stream_t* handle_that_last_alloced;
-static Persistent<String> slab_sym;
-static Persistent<String> buffer_sym;
-static Persistent<String> write_queue_size_sym;
-static bool initialized;
-
-
void StreamWrap::Initialize(Handle<Object> target) {
- if (initialized) {
+ if (stream_wrap_initialized) {
return;
} else {
- initialized = true;
+ stream_wrap_initialized = true;
}
HandleScope scope;
View
15 src/tcp_wrap.cc
@@ -55,6 +55,15 @@
return scope.Close(Integer::New(-1)); \
}
+#include <node_vars.h>
+
+// We do the following to minimize the detal between v0.6 branch. We want to
+// use the variables as they were being used before.
+#define tcpConstructor NODE_VAR(tcpConstructor)
+#define family_symbol NODE_VAR(family_symbol)
+#define address_symbol NODE_VAR(address_symbol)
+#define port_symbol NODE_VAR(port_symbol)
+
namespace node {
using v8::Object;
@@ -72,12 +81,6 @@ using v8::Arguments;
using v8::Integer;
using v8::Undefined;
-static Persistent<Function> tcpConstructor;
-static Persistent<String> family_symbol;
-static Persistent<String> address_symbol;
-static Persistent<String> port_symbol;
-
-
typedef class ReqWrap<uv_connect_t> ConnectWrap;

0 comments on commit e0a207c

Please sign in to comment.
Something went wrong with that request. Please try again.