Print this page
joyent/v8plus#7 v8plus should not hold the event loop open forever

Split Close
Expand all
Collapse all
          --- old/./README.md
          +++ new/./README.md
↓ open down ↓ 677 lines elided ↑ open up ↑
 678  678  also be passed along to listeners as arguments to their callbacks.
 679  679  
 680  680  ### void v8plus_obj_hold(const void *op)
 681  681  
 682  682  Places a hold on the V8 representation of the specified C object.  This is
 683  683  rarely necessary; `v8plus_defer()` performs this action for you, but other
 684  684  asynchronous mechanisms may require it.  If you are returning from a method
 685  685  call but have stashed a reference to the object somewhere and are not
 686  686  calling `v8plus_defer()`, you must call this first.  Holds and releases must
 687  687  be balanced.  Use of the object within a thread after releasing is a bug.
      688 +This hold includes an implicit event loop hold, as if `v8plus_eventloop_hold()`
      689 +was called.
 688  690  
 689  691  ### void v8plus_obj_rele(const void *op)
 690  692  
 691  693  Releases a hold placed by `v8plus_obj_hold()`.  This function may be called
 692  694  safely from any thread; releases from threads other than the main event loop
 693      -are non-blocking and will occur some time in the future.
      695 +are non-blocking and will occur some time in the future.  Releases the
      696 +implicit event loop hold obtained by `v8plus_obj_hold()`.
 694  697  
 695  698  ### void v8plus_jsfunc_hold(v8plus_jsfunc_t f)
 696  699  
 697  700  Places a hold on the V8 representation of the specified JavaScript function.
 698  701  This is required when returning from a C function that has stashed a
 699  702  reference to the function, typically to use it asynchronously as a callback.
 700  703  All holds must be balanced with a release.  Because a single hold is placed
 701  704  on such objects when passed to you in an argument list (and released for you
 702  705  when you return), it is legal to reference and even to invoke such a
 703      -function without first placing an additional hold on it.
      706 +function without first placing an additional hold on it.  This hold includes
      707 +an implicit event loop hold, as if `v8plus_eventloop_hold()` was called.
 704  708  
 705  709  ### void v8plus_jsfunc_rele(v8plus_jsfunc_t f)
 706  710  
 707  711  Releases a hold placed by `v8plus_jsfunc_hold()`.  This function may be called
 708  712  safely from any thread; releases from threads other than the main event loop
 709      -thread are non-blocking and will occur some time in the future.
      713 +thread are non-blocking and will occur some time in the future.  Releases
      714 +the implicit event loop hold obtained by `v8plus_jsfunc_hold()`.
 710  715  
 711  716  ### void v8plus_defer(void *op, void *ctx, worker, completion)
 712  717  
 713  718  Enqueues work to be performed in the Node.js shared thread pool.  The object
 714  719  `op` and context `ctx` are passed as arguments to `worker` executing in a
 715  720  thread from that pool.  The same two arguments, along with the worker's
 716  721  return value, are passed to `completion` executing in the main event loop
 717  722  thread.  See example above.
      723 +
      724 +### void v8plus_eventloop_hold(void)
      725 +
      726 +Places a hold on the V8 event loop.  V8 will terminate when it detects that
      727 +there is no more work to do.  This liveliness check includes things like open
      728 +sockets or file descriptors, but only if they are tracked by the event loop
      729 +itself.  If you are using multiple threads, some of which may blocking waiting
      730 +for input (e.g. a message subscription thread) then you will need to prevent V8
      731 +from terminating prematurely.  This function must be called from within the
      732 +main event loop thread.  Each hold must be balanced with a release.  Note that
      733 +holds on objects or functions obtained via `v8plus_obj_hold()` or
      734 +`v8plus_jsfunc_hold()` will implicitly hold the event loop for you.
      735 +
      736 +### void v8plus_eventloop_rele(void)
      737 +
      738 +Release a hold on the V8 event loop.  If there are no more pending events or
      739 +input sources, then V8 will generally terminate the process shortly afterward.
      740 +This function may be called safely from any thread; releases from threads other
      741 +than the main event loop thread are non-blocking and will occur some time in
      742 +the future.
 718  743  
 719  744  ### nvlist_t *v8plus_call(v8plus_jsfunc_t f, const nvlist_t *ap)
 720  745  
 721  746  Calls the JavaScript function referred to by `f` with encoded arguments
 722  747  `ap`.  The return value is the encoded return value of the function.  The
 723  748  argument and return value encoding match the encodings that are used by C
 724  749  functions that provide methods.
 725  750  
 726  751  As JavaScript functions must be called from the event loop thread,
 727  752  `v8plus_call()` contains logic to determine whether we are in the
↓ open down ↓ 144 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX