Print this page
XXX rework to avoid changing api
XXX well, it works now...

@@ -7,10 +7,12 @@
 
 #include <sys/ccompile.h>
 #include <stdarg.h>
 #include <libnvpair.h>
 #include <v8.h>
+#include <uv.h>
+#include <queue>
 #include <unordered_map>
 #include "v8plus_glue.h"
 
 /*
  * STOP!

@@ -27,30 +29,54 @@
 
 #if NODE_MINOR_VERSION > 7 || NODE_MAJOR_VERSION > 0
 #define NODE_MAKECALLBACK_RETURN
 #endif
 
+typedef struct v8plus_async_call {
+        void *ac_cop;
+        const char *ac_name;
+        const nvlist_t *ac_lp;
+
+        pthread_cond_t ac_cv;
+        pthread_mutex_t ac_mtx;
+
+        boolean_t ac_run;
+        nvlist_t *ac_return;
+} v8plus_async_call_t;
+
+extern "C" void v8plus_async_callback(uv_async_t *, int);
+
 namespace v8plus {
 
+
 class ObjectWrap;
 
 class ObjectWrap : public node::ObjectWrap {
 public:
         static void init(v8::Handle<v8::Object>);
         static v8::Handle<v8::Value> cons(const v8::Arguments &);
         static ObjectWrap *objlookup(const void *);
         v8::Handle<v8::Value> call(const char *, int, v8::Handle<v8::Value>[]);
         void public_Ref(void);
         void public_Unref(void);
+        static v8plus_async_call_t *next_async_call(void);
+        static void post_async_call(v8plus_async_call_t *);
+        static boolean_t in_event_thread(void);
 
 private:
         static v8::Persistent<v8::Function> _constructor;
         static v8plus_method_descr_t *_mtbl;
         static v8plus_static_descr_t *_stbl;
         static std::unordered_map<void *, ObjectWrap *> _objhash;
         void *_c_impl;
 
+        static uv_async_t _uv_async;
+        static pthread_mutex_t _callq_mutex;
+        static std::queue<v8plus_async_call_t *> _callq;
+        static boolean_t _crossthread_init_done;
+        static unsigned long _uv_event_thread;
+
         ObjectWrap() : _c_impl(NULL) {};
         ~ObjectWrap();
 
         static v8::Handle<v8::Value> _new(const v8::Arguments &);
         static v8::Handle<v8::Value> _entry(const v8::Arguments &);