Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
isolates: implement message passing
Browse files Browse the repository at this point in the history
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 dadc303
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 113 deletions.
6 changes: 6 additions & 0 deletions src/node.cc
Expand Up @@ -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());

Expand Down
58 changes: 6 additions & 52 deletions src/node_internals.h
Expand Up @@ -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

Expand Down

0 comments on commit dadc303

Please sign in to comment.