Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

isolates: implement message passing

Parent and child isolates can now pass arbitrary binary messages between each
other. The messages are sent and received through a thread-safe queue that
wakes up the event loop of the receiving thread.
  • Loading branch information
bnoordhuis committed Jan 5, 2012
1 parent 075acfa commit dadc30318f812587405dd58d9a5d10ce392710b3
Showing with 382 additions and 113 deletions.
  1. +6 −0 src/node.cc
  2. +6 −52 src/node_internals.h
  3. +306 −53 src/node_isolate.cc
  4. +17 −7 src/node_isolate.h
  5. +39 −0 test/simple/test-isolates-ping-pong.js
  6. +8 −1 test/simple/test-isolates.js
@@ -2664,6 +2664,12 @@ void StartThread(node::Isolate* isolate,
process_l->Set(String::NewSymbol("tid"),
Integer::NewFromUnsigned(isolate->id_));

// TODO check (isolate->channel_ != NULL)
if (isolate->id_ > 1) {
process_l->Set(String::NewSymbol("_send"),
FunctionTemplate::New(Isolate::Send)->GetFunction());
}

// FIXME crashes with "CHECK(heap->isolate() == Isolate::Current()) failed"
//v8_typed_array::AttachBindings(v8::Context::GetCurrent()->Global());

@@ -47,59 +47,13 @@ void StartThread(Isolate* isolate, int argc, char** argv);
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#endif

//
// isolates support
//
#if HAVE_ISOLATES

# if _WIN32
# define THREAD __declspec(thread)
# else
# define THREAD __thread
# endif

# define TLS(type, name) THREAD type* __tls_##name
# define VAR(name) (*__tls_##name)
# define EMPTY(name) (__tls_##name == NULL)
# define ASSIGN(name, val) ((__tls_##name) = P(val))

# define LAZY_ASSIGN(name, val) \
do if (!__tls_##name) ((__tls_##name) = P(val)); while (0)

template <class T> inline v8::Persistent<T>* P(v8::Handle<T> v)
{
return new v8::Persistent<T>(v8::Persistent<T>::New(v));
}

inline v8::Persistent<v8::String>* P(const char* symbol)
{
return new v8::Persistent<v8::String>(
v8::Persistent<v8::String>::New(
v8::String::NewSymbol(symbol)));
}

#else // !HAVE_ISOLATES

# define THREAD /* nothing */
# define TLS(type, name) type name
# define VAR(name) (name)
# define EMPTY(name) ((name).IsEmpty())
# define ASSIGN(name, val) ((name) = P(val))

# define LAZY_ASSIGN(name, val) \
do if ((name).IsEmpty()) (name) = P(val); while (0)

template <class T> inline v8::Persistent<T> P(v8::Handle<T> v)
{
return v8::Persistent<T>(v);
}
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)

inline v8::Persistent<v8::String> P(const char* symbol)
{
return v8::Persistent<v8::String>::New(
v8::String::NewSymbol(symbol));
}
#endif // HAVE_ISOLATES
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
TypeName(); \
DISALLOW_COPY_AND_ASSIGN(TypeName)

} // namespace node

0 comments on commit dadc303

Please sign in to comment.
You can’t perform that action at this time.