mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Revert "n-api: detect deadlocks in thread-safe function"
This reverts commit aeb7084fe6.
The solution creates incorrect behaviour on Windows.
Re: https://github.com/nodejs/node-addon-api/pull/697#issuecomment-612993476
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
PR-URL: https://github.com/nodejs/node/pull/32880
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
1 parent
a9da65699a
commit
d3d5eca657
7 files changed
+10
-100
No files matched your search
@@ -82,15 +82,11 @@ typedef enum {
|
||||
napi_date_expected,
|
||||
napi_arraybuffer_expected,
|
||||
napi_detachable_arraybuffer_expected,
|
||||
napi_would_deadlock
|
||||
} napi_status;
|
||||
// Note: when adding a new enum value to `napi_status`, please also update
|
||||
// * `const int last_status` in the definition of `napi_get_last_error_info()'
|
||||
// in file js_native_api_v8.cc.
|
||||
// * `const char* error_messages[]` in file js_native_api_v8.cc with a brief
|
||||
// message explaining the error.
|
||||
// * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
|
||||
// added value(s).
|
||||
// `const int last_status` in `napi_get_last_error_info()' definition,
|
||||
// in file js_native_api_v8.cc. Please also update the definition of
|
||||
// `napi_status` in doc/api/n-api.md to reflect the newly added value(s).
|
||||
|
||||
typedef napi_value (*napi_callback)(napi_env env,
|
||||
napi_callback_info info);
|
||||
|
||||
@@ -740,7 +740,6 @@ const char* error_messages[] = {nullptr,
|
||||
"A date was expected",
|
||||
"An arraybuffer was expected",
|
||||
"A detachable arraybuffer was expected",
|
||||
"Main thread would deadlock",
|
||||
};
|
||||
|
||||
napi_status napi_get_last_error_info(napi_env env,
|
||||
@@ -752,7 +751,7 @@ napi_status napi_get_last_error_info(napi_env env,
|
||||
// message in the `napi_status` enum each time a new error message is added.
|
||||
// We don't have a napi_status_last as this would result in an ABI
|
||||
// change each time a message was added.
|
||||
const int last_status = napi_would_deadlock;
|
||||
const int last_status = napi_detachable_arraybuffer_expected;
|
||||
|
||||
static_assert(
|
||||
NAPI_ARRAYSIZE(error_messages) == last_status + 1,
|
||||
|
||||
@@ -129,7 +129,6 @@ class ThreadSafeFunction : public node::AsyncResource {
|
||||
is_closing(false),
|
||||
context(context_),
|
||||
max_queue_size(max_queue_size_),
|
||||
main_thread(uv_thread_self()),
|
||||
env(env_),
|
||||
finalize_data(finalize_data_),
|
||||
finalize_cb(finalize_cb_),
|
||||
@@ -149,15 +148,12 @@ class ThreadSafeFunction : public node::AsyncResource {
|
||||
|
||||
napi_status Push(void* data, napi_threadsafe_function_call_mode mode) {
|
||||
node::Mutex::ScopedLock lock(this->mutex);
|
||||
uv_thread_t current_thread = uv_thread_self();
|
||||
|
||||
while (queue.size() >= max_queue_size &&
|
||||
max_queue_size > 0 &&
|
||||
!is_closing) {
|
||||
if (mode == napi_tsfn_nonblocking) {
|
||||
return napi_queue_full;
|
||||
} else if (uv_thread_equal(¤t_thread, &main_thread)) {
|
||||
return napi_would_deadlock;
|
||||
}
|
||||
cond->Wait(lock);
|
||||
}
|
||||
@@ -438,7 +434,6 @@ class ThreadSafeFunction : public node::AsyncResource {
|
||||
// means we don't need the mutex to read them.
|
||||
void* context;
|
||||
size_t max_queue_size;
|
||||
uv_thread_t main_thread;
|
||||
|
||||
// These are variables accessed only from the loop thread.
|
||||
v8impl::Persistent<v8::Function> ref;
|
||||
|
||||
Reference in new issue
Block a user