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

Split Close
Expand all
Collapse all
          --- old/./v8plus_impl.h
          +++ new/./v8plus_impl.h
↓ open down ↓ 1 lines elided ↑ open up ↑
   2    2   * Copyright (c) 2012 Joyent, Inc.  All rights reserved.
   3    3   */
   4    4  
   5    5  #ifndef _V8PLUS_IMPL_H
   6    6  #define _V8PLUS_IMPL_H
   7    7  
   8    8  #include <sys/ccompile.h>
   9    9  #include <stdarg.h>
  10   10  #include <libnvpair.h>
  11   11  #include <v8.h>
       12 +#include <uv.h>
       13 +#include <queue>
  12   14  #include <unordered_map>
  13   15  #include "v8plus_glue.h"
  14   16  
  15   17  /*
  16   18   * STOP!
  17   19   *
  18   20   * Do not #include this header in code that consumes v8+.  This is a private
  19   21   * implementation header for use by v8+ internal C++ code.  It cannot be
  20   22   * included from C code and contains nothing usable by consumers.
  21   23   */
  22   24  
  23   25  #define V8PLUS_THROW(_t, _e, _f, _args...) \
  24   26      v8::ThrowException(v8plus::exception((_t), (_e), (_f), ## _args))
  25   27  #define V8PLUS_THROW_DEFAULT()          V8PLUS_THROW(NULL, NULL, NULL)
  26   28  #define V8PLUS_THROW_DECORATED(_e)      V8PLUS_THROW(NULL, (_e), NULL)
  27   29  
  28   30  #if NODE_MINOR_VERSION > 7 || NODE_MAJOR_VERSION > 0
  29   31  #define NODE_MAKECALLBACK_RETURN
  30   32  #endif
  31   33  
       34 +typedef struct v8plus_async_call {
       35 +        void *ac_cop;
       36 +        const char *ac_name;
       37 +        const nvlist_t *ac_lp;
       38 +
       39 +        pthread_cond_t ac_cv;
       40 +        pthread_mutex_t ac_mtx;
       41 +
       42 +        boolean_t ac_run;
       43 +        nvlist_t *ac_return;
       44 +} v8plus_async_call_t;
       45 +
       46 +extern "C" void v8plus_async_callback(uv_async_t *, int);
       47 +
  32   48  namespace v8plus {
  33   49  
       50 +
  34   51  class ObjectWrap;
  35   52  
  36   53  class ObjectWrap : public node::ObjectWrap {
  37   54  public:
  38   55          static void init(v8::Handle<v8::Object>);
  39   56          static v8::Handle<v8::Value> cons(const v8::Arguments &);
  40   57          static ObjectWrap *objlookup(const void *);
  41   58          v8::Handle<v8::Value> call(const char *, int, v8::Handle<v8::Value>[]);
  42   59          void public_Ref(void);
  43   60          void public_Unref(void);
       61 +        static v8plus_async_call_t *next_async_call(void);
       62 +        static void post_async_call(v8plus_async_call_t *);
       63 +        static boolean_t in_event_thread(void);
  44   64  
  45   65  private:
  46   66          static v8::Persistent<v8::Function> _constructor;
  47   67          static v8plus_method_descr_t *_mtbl;
  48   68          static v8plus_static_descr_t *_stbl;
  49   69          static std::unordered_map<void *, ObjectWrap *> _objhash;
  50   70          void *_c_impl;
  51   71  
       72 +        static uv_async_t _uv_async;
       73 +        static pthread_mutex_t _callq_mutex;
       74 +        static std::queue<v8plus_async_call_t *> _callq;
       75 +        static boolean_t _crossthread_init_done;
       76 +        static unsigned long _uv_event_thread;
       77 +
  52   78          ObjectWrap() : _c_impl(NULL) {};
  53   79          ~ObjectWrap();
  54   80  
  55   81          static v8::Handle<v8::Value> _new(const v8::Arguments &);
  56   82          static v8::Handle<v8::Value> _entry(const v8::Arguments &);
  57   83          static v8::Handle<v8::Value> _static_entry(const v8::Arguments &);
  58   84  };
  59   85  
  60   86  extern nvlist_t *v8_Arguments_to_nvlist(const v8::Arguments &);
  61   87  extern v8::Handle<v8::Value> nvpair_to_v8_Value(const nvpair_t *);
  62   88  extern v8::Local<v8::Value> exception(const char *, const nvlist_t *,
  63   89      const char *, ...) __PRINTFLIKE(3);
  64   90  
  65   91  }; /* namespace v8plus */
  66   92  
  67   93  #endif  /* _V8PLUS_IMPL_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX