summaryrefslogtreecommitdiff
path: root/src/node_api_types.h
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-06-17 11:52:49 -0400
committerGabriel Schulhof <gabriel.schulhof@intel.com>2018-06-29 17:18:46 -0400
commit81f06ba7e49d9c077c209ab9c9de63bad08aa801 (patch)
tree7b7f35909237584e759a4ad9396e2e565b354b38 /src/node_api_types.h
parent1c303439846de80aaec75285ec5ce087e85b31a6 (diff)
downloadandroid-node-v8-81f06ba7e49d9c077c209ab9c9de63bad08aa801.tar.gz
android-node-v8-81f06ba7e49d9c077c209ab9c9de63bad08aa801.tar.bz2
android-node-v8-81f06ba7e49d9c077c209ab9c9de63bad08aa801.zip
n-api: add API for asynchronous functions
Bundle a `uv_async_t`, a `uv_idle_t`, a `uv_mutex_t`, a `uv_cond_t`, and a `v8::Persistent<v8::Function>` to make it possible to call into JS from another thread. The API accepts a void data pointer and a callback which will be invoked on the loop thread and which will receive the `napi_value` representing the JavaScript function to call so as to perform the call into JS. The callback is run inside a `node::CallbackScope`. A `std::queue<void*>` is used to store calls from the secondary threads, and an idle loop is started by the `uv_async_t` callback on the loop thread to drain the queue, calling into JS with each item. Items can be added to the queue blockingly or non-blockingly. The thread-safe function can be referenced or unreferenced, with the same semantics as libuv handles. Re: https://github.com/nodejs/help/issues/1035 Re: https://github.com/nodejs/node/issues/20964 Fixes: https://github.com/nodejs/node/issues/13512 PR-URL: https://github.com/nodejs/node/pull/17887 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src/node_api_types.h')
-rw-r--r--src/node_api_types.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/node_api_types.h b/src/node_api_types.h
index f7f3ee6275..af7d7c7f95 100644
--- a/src/node_api_types.h
+++ b/src/node_api_types.h
@@ -20,6 +20,9 @@ typedef struct napi_callback_info__* napi_callback_info;
typedef struct napi_async_context__* napi_async_context;
typedef struct napi_async_work__* napi_async_work;
typedef struct napi_deferred__* napi_deferred;
+#ifdef NAPI_EXPERIMENTAL
+typedef struct napi_threadsafe_function__* napi_threadsafe_function;
+#endif // NAPI_EXPERIMENTAL
typedef enum {
napi_default = 0,
@@ -72,9 +75,25 @@ typedef enum {
napi_cancelled,
napi_escape_called_twice,
napi_handle_scope_mismatch,
- napi_callback_scope_mismatch
+ napi_callback_scope_mismatch,
+#ifdef NAPI_EXPERIMENTAL
+ napi_queue_full,
+ napi_closing,
+#endif // NAPI_EXPERIMENTAL
} napi_status;
+#ifdef NAPI_EXPERIMENTAL
+typedef enum {
+ napi_tsfn_release,
+ napi_tsfn_abort
+} napi_threadsafe_function_release_mode;
+
+typedef enum {
+ napi_tsfn_nonblocking,
+ napi_tsfn_blocking
+} napi_threadsafe_function_call_mode;
+#endif // NAPI_EXPERIMENTAL
+
typedef napi_value (*napi_callback)(napi_env env,
napi_callback_info info);
typedef void (*napi_finalize)(napi_env env,
@@ -86,6 +105,13 @@ typedef void (*napi_async_complete_callback)(napi_env env,
napi_status status,
void* data);
+#ifdef NAPI_EXPERIMENTAL
+typedef void (*napi_threadsafe_function_call_js)(napi_env env,
+ napi_value js_callback,
+ void* context,
+ void* data);
+#endif // NAPI_EXPERIMENTAL
+
typedef struct {
// One of utf8name or name should be NULL.
const char* utf8name;