Browse Source

node: don't share state with in_tick/last_threw

There was no need to share state between C++ and JS for these two
values. So they have been moved to their respective locations. This will
help performance only a tiny bit, but it does help code complexity much
more.
v0.11.8-release
Trevor Norris 11 years ago
parent
commit
4b84e42f67
  1. 18
      src/env-inl.h
  2. 11
      src/env.h
  3. 12
      src/node.cc
  4. 19
      src/node.js

18
src/env-inl.h

@ -85,7 +85,7 @@ inline uint32_t Environment::DomainFlag::count() const {
return fields_[kCount];
}
inline Environment::TickInfo::TickInfo() {
inline Environment::TickInfo::TickInfo() : in_tick_(false), last_threw_(false) {
for (int i = 0; i < kFieldsCount; ++i) fields_[i] = 0;
}
@ -97,28 +97,32 @@ inline int Environment::TickInfo::fields_count() const {
return kFieldsCount;
}
inline uint32_t Environment::TickInfo::in_tick() const {
return fields_[kInTick];
inline bool Environment::TickInfo::in_tick() const {
return in_tick_;
}
inline uint32_t Environment::TickInfo::index() const {
return fields_[kIndex];
}
inline uint32_t Environment::TickInfo::last_threw() const {
return fields_[kLastThrew];
inline bool Environment::TickInfo::last_threw() const {
return last_threw_;
}
inline uint32_t Environment::TickInfo::length() const {
return fields_[kLength];
}
inline void Environment::TickInfo::set_in_tick(bool value) {
in_tick_ = value;
}
inline void Environment::TickInfo::set_index(uint32_t value) {
fields_[kIndex] = value;
}
inline void Environment::TickInfo::set_last_threw(uint32_t value) {
fields_[kLastThrew] = value;
inline void Environment::TickInfo::set_last_threw(bool value) {
last_threw_ = value;
}
inline Environment* Environment::New(v8::Local<v8::Context> context) {

11
src/env.h

@ -187,26 +187,27 @@ class Environment {
public:
inline uint32_t* fields();
inline int fields_count() const;
inline uint32_t in_tick() const;
inline bool in_tick() const;
inline bool last_threw() const;
inline uint32_t index() const;
inline uint32_t last_threw() const;
inline uint32_t length() const;
inline void set_in_tick(bool value);
inline void set_index(uint32_t value);
inline void set_last_threw(uint32_t value);
inline void set_last_threw(bool value);
private:
friend class Environment; // So we can call the constructor.
inline TickInfo();
enum Fields {
kInTick,
kIndex,
kLastThrew,
kLength,
kFieldsCount
};
uint32_t fields_[kFieldsCount];
bool in_tick_;
bool last_threw_;
DISALLOW_COPY_AND_ASSIGN(TickInfo);
};

12
src/node.cc

@ -948,7 +948,7 @@ Handle<Value> MakeDomainCallback(Environment* env,
return ret;
}
if (tick_info->in_tick() == 1) {
if (tick_info->in_tick()) {
return ret;
}
@ -957,12 +957,17 @@ Handle<Value> MakeDomainCallback(Environment* env,
return ret;
}
tick_info->set_in_tick(true);
// process nextTicks after call
Local<Object> process_object = env->process_object();
Local<Function> tick_callback_function = env->tick_callback_function();
tick_callback_function->Call(process_object, 0, NULL);
tick_info->set_in_tick(false);
if (try_catch.HasCaught()) {
tick_info->set_last_threw(true);
return Undefined(node_isolate);
}
@ -1004,6 +1009,8 @@ Handle<Value> MakeCallback(Environment* env,
return ret;
}
tick_info->set_in_tick(true);
// lazy load no domain next tick callbacks
Local<Function> tick_callback_function = env->tick_callback_function();
if (tick_callback_function.IsEmpty()) {
@ -1021,7 +1028,10 @@ Handle<Value> MakeCallback(Environment* env,
// process nextTicks after call
tick_callback_function->Call(process_object, 0, NULL);
tick_info->set_in_tick(false);
if (try_catch.HasCaught()) {
tick_info->set_last_threw(true);
return Undefined(node_isolate);
}

19
src/node.js

@ -278,10 +278,8 @@
var tickInfo = process._tickInfo;
// *Must* match Environment::TickInfo::Fields in src/env.h.
var kInTick = 0;
var kIndex = 1;
var kLastThrew = 2;
var kLength = 3;
var kIndex = 0;
var kLength = 1;
process.nextTick = nextTick;
// needs to be accessible from cc land
@ -298,7 +296,6 @@
tickInfo[kLength] = nextTickQueue.length;
}
}
tickInfo[kInTick] = 0;
tickInfo[kIndex] = 0;
}
@ -307,8 +304,6 @@
function _tickCallback() {
var callback, threw;
tickInfo[kInTick] = 1;
while (tickInfo[kIndex] < tickInfo[kLength]) {
callback = nextTickQueue[tickInfo[kIndex]++].callback;
threw = true;
@ -324,9 +319,7 @@
}
function _tickDomainCallback() {
var tock, callback, domain;
tickInfo[kInTick] = 1;
var tock, callback, threw, domain;
while (tickInfo[kIndex] < tickInfo[kLength]) {
tock = nextTickQueue[tickInfo[kIndex]++];
@ -336,12 +329,12 @@
if (domain._disposed) continue;
domain.enter();
}
tickInfo[kLastThrew] = 1;
threw = true;
try {
callback();
tickInfo[kLastThrew] = 0;
threw = false;
} finally {
if (tickInfo[kLastThrew] === 1) tickDone();
if (threw) tickDone();
}
if (domain)
domain.exit();

Loading…
Cancel
Save