Repository navigation
tsfn: implement TypedThreadSafeFunction #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gabrielschulhof
merged 46 commits into
nodejs:master
from
KevinEady:contexted-tsfn-api-gcc-4
Dec 7, 2020
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
78196e0
tsfn: implement ThreadSafeFunctionEx<ContextType>
KevinEady 90ebd80
fix unused parameter errors
KevinEady fc339c4
wip
KevinEady fd530b2
wip
KevinEady 561b968
make CallJS template parameter
KevinEady 630d88b
statically check CallJs; add no-Finalizer overload
KevinEady 9ff352c
add tsfn test with tsfn cb function call
KevinEady 6aeecd4
Merge remote-tracking branch 'upstream/master' into contexted-tsfn-api
KevinEady 2da3023
test: Initial commit of TSFNEx threadsafe test
KevinEady 91e8859
test: Modify TSFNEx threadsafe to use TSFNEx
KevinEady 692fbe1
src,test: Add SIGTRAP to TSFNEx::CallJS
KevinEady 0d26703
Merge remote-tracking branch 'upstream/master' into contexted-tsfn-ap…
KevinEady 89181da
test: fix TSFNEx tests
KevinEady 8fcdb4d
test: add barebones new tsfn test for use in docs
KevinEady cc8de12
implement optional function callback
KevinEady 6706f96
clean up optional callback implementation
KevinEady 89d2dea
test: wip with tsfnex tests
KevinEady d2bcc03
test: napi v4,v5 all tests pass
KevinEady 6b7a7d0
test: consolidate duplicated code
KevinEady 7467a3f
test: basic example, standardize identifier names
KevinEady a01c3c8
test: refactor the the 'empty' tsfnex test
KevinEady b0e7817
basic multi-threading
KevinEady 44adeea
test: wip with example
KevinEady c20685b
test: wip with example test
KevinEady 3b24e74
src: consolidate duplicated tsfnex code
KevinEady a7a5352
test: v4,v5+ tests pass
KevinEady d092a32
doc: wip with tsfn documentation
KevinEady 75dd422
doc,test: finish TSFNEx
KevinEady 717b602
Merge remote-tracking branch 'upstream/master' into contexted-tsfn-ap…
KevinEady 0d84cf7
Test with longer timeout
KevinEady c8eea6b
Merge remote-tracking branch 'upstream/master' into contexted-tsfn-ap…
KevinEady 807fb27
Apply suggestions from code review
KevinEady f3aa955
Merge remote-tracking branch 'upstream/master' into contexted-tsfn-ap…
KevinEady fd6a2b4
Additional changes from review
KevinEady ad9333e
test: tsfnex uses ported tsfn tests
KevinEady e223955
doc: tsfnex example uses ported tsfn example
KevinEady 3405b2b
src,doc: final cleanup
KevinEady 151a914
Apply documentation suggestions from code review
KevinEady 59f27da
Fix common.gypi
KevinEady b54f5eb
Additional changes from review
KevinEady 7ec9741
Merge remote-tracking branch 'upstream/master' into contexted-tsfn-ap…
KevinEady 7a13f86
doc: fix additional typo
KevinEady 4abe7cf
test: rename tsfnex test files
KevinEady c24c455
Rename to TypedThreadSafeFunction
KevinEady 559ad8c
Merge remote-tracking branch 'upstream/master' into contexted-tsfn-ap…
KevinEady 5e5b9ce
Apply formatting changes
KevinEady File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
implement optional function callback
- Loading branch information
commit cc8de121c0abb3994855352398c9a4647a5b1efa
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4317,7 +4317,241 @@ inline void AsyncWorker::OnWorkComplete(Napi::Env /*env*/, napi_status status) { | |
| // ThreadSafeFunctionEx<ContextType,DataType,CallJs> class | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| // static | ||
| // Starting with NAPI 4, the JavaScript function `func` parameter of | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this say starting with NAPI 5 , as that is what the #if does.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch; this has been addressed here. |
||
| // `napi_create_threadsafe_function` is optional. | ||
| #if NAPI_VERSION > 4 | ||
| // static, with Callback [missing] Resource [missing] Finalizer [missing] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, ResourceString resourceName, size_t maxQueueSize, | ||
| size_t initialThreadCount, ContextType *context) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, nullptr, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, nullptr, nullptr, context, | ||
| CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [nullptr] Resource [missing] Finalizer [missing] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, std::nullptr_t callback, ResourceString resourceName, size_t maxQueueSize, | ||
| size_t initialThreadCount, ContextType *context) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, nullptr, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, nullptr, nullptr, context, | ||
| CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [missing] Resource [passed] Finalizer [missing] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, const Object &resource, ResourceString resourceName, | ||
| size_t maxQueueSize, size_t initialThreadCount, ContextType *context) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, resource, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, nullptr, nullptr, context, CallJsInternal, | ||
| &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [nullptr] Resource [passed] Finalizer [missing] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, std::nullptr_t callback, const Object &resource, ResourceString resourceName, | ||
| size_t maxQueueSize, size_t initialThreadCount, ContextType *context) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, resource, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, nullptr, nullptr, context, CallJsInternal, | ||
| &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [missing] Resource [missing] Finalizer [passed] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString, typename Finalizer, | ||
| typename FinalizerDataType> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, ResourceString resourceName, size_t maxQueueSize, | ||
| size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, | ||
| FinalizerDataType *data) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| auto *finalizeData = new details::ThreadSafeFinalize<ContextType, Finalizer, | ||
| FinalizerDataType>( | ||
| {data, finalizeCallback}); | ||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, nullptr, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, finalizeData, | ||
| details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>:: | ||
| FinalizeFinalizeWrapperWithDataAndContext, | ||
| context, CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| delete finalizeData; | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [nullptr] Resource [missing] Finalizer [passed] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString, typename Finalizer, | ||
| typename FinalizerDataType> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, std::nullptr_t callback, ResourceString resourceName, size_t maxQueueSize, | ||
| size_t initialThreadCount, ContextType *context, Finalizer finalizeCallback, | ||
| FinalizerDataType *data) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| auto *finalizeData = new details::ThreadSafeFinalize<ContextType, Finalizer, | ||
| FinalizerDataType>( | ||
| {data, finalizeCallback}); | ||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, nullptr, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, finalizeData, | ||
| details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>:: | ||
| FinalizeFinalizeWrapperWithDataAndContext, | ||
| context, CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| delete finalizeData; | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [missing] Resource [passed] Finalizer [passed] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString, typename Finalizer, | ||
| typename FinalizerDataType> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, const Object &resource, ResourceString resourceName, | ||
| size_t maxQueueSize, size_t initialThreadCount, ContextType *context, | ||
| Finalizer finalizeCallback, FinalizerDataType *data) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| auto *finalizeData = new details::ThreadSafeFinalize<ContextType, Finalizer, | ||
| FinalizerDataType>( | ||
| {data, finalizeCallback}); | ||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, resource, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, finalizeData, | ||
| details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>:: | ||
| FinalizeFinalizeWrapperWithDataAndContext, | ||
| context, CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| delete finalizeData; | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [nullptr] Resource [passed] Finalizer [passed] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString, typename Finalizer, | ||
| typename FinalizerDataType> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, std::nullptr_t callback, const Object &resource, ResourceString resourceName, | ||
| size_t maxQueueSize, size_t initialThreadCount, ContextType *context, | ||
| Finalizer finalizeCallback, FinalizerDataType *data) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| auto *finalizeData = new details::ThreadSafeFinalize<ContextType, Finalizer, | ||
| FinalizerDataType>( | ||
| {data, finalizeCallback}); | ||
| napi_status status = napi_create_threadsafe_function( | ||
| env, nullptr, resource, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, finalizeData, | ||
| details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>:: | ||
| FinalizeFinalizeWrapperWithDataAndContext, | ||
| context, CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| delete finalizeData; | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
| #endif | ||
|
|
||
| // static, with Callback [passed] Resource [missing] Finalizer [missing] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, const Function &callback, ResourceString resourceName, | ||
| size_t maxQueueSize, size_t initialThreadCount, ContextType *context) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| napi_status status = napi_create_threadsafe_function( | ||
| env, callback, nullptr, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, nullptr, nullptr, context, CallJsInternal, | ||
| &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with Callback [x] Resource [x] Finalizer [missing] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString> | ||
|
|
@@ -4326,12 +4560,51 @@ ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | |
| napi_env env, const Function &callback, const Object &resource, | ||
| ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, | ||
| ContextType *context) { | ||
| return New( | ||
| env, callback, resource, resourceName, maxQueueSize, initialThreadCount, | ||
| context, [](Env, void *, ContextType *) {}, static_cast<void *>(nullptr)); | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| napi_status status = napi_create_threadsafe_function( | ||
| env, callback, resource, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, nullptr, nullptr, context, CallJsInternal, | ||
| &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static | ||
| // static, with Callback [x] Resource [missing ] Finalizer [x] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString, typename Finalizer, | ||
| typename FinalizerDataType> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, const Function &callback, ResourceString resourceName, | ||
| size_t maxQueueSize, size_t initialThreadCount, ContextType *context, | ||
| Finalizer finalizeCallback, FinalizerDataType *data) { | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| auto *finalizeData = new details::ThreadSafeFinalize<ContextType, Finalizer, | ||
| FinalizerDataType>( | ||
| {data, finalizeCallback}); | ||
| napi_status status = napi_create_threadsafe_function( | ||
| env, callback, nullptr, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, finalizeData, | ||
| details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>:: | ||
| FinalizeFinalizeWrapperWithDataAndContext, | ||
| context, CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| delete finalizeData; | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| // static, with: Callback [x] Resource [x] Finalizer [x] | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString, typename Finalizer, | ||
|
|
@@ -4341,11 +4614,24 @@ ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | |
| napi_env env, const Function &callback, const Object &resource, | ||
| ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, | ||
| ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data) { | ||
| return New( | ||
| env, callback, resource, resourceName, maxQueueSize, initialThreadCount, | ||
| context, finalizeCallback, data, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| auto *finalizeData = new details::ThreadSafeFinalize<ContextType, Finalizer, | ||
| FinalizerDataType>( | ||
| {data, finalizeCallback}); | ||
| napi_status status = napi_create_threadsafe_function( | ||
| env, callback, resource, String::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, finalizeData, | ||
| details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>:: | ||
| FinalizeFinalizeWrapperWithDataAndContext); | ||
| FinalizeFinalizeWrapperWithDataAndContext, | ||
| context, CallJsInternal, &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| delete finalizeData; | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| } | ||
|
|
||
| template <typename ContextType, typename DataType, | ||
|
|
@@ -4438,43 +4724,23 @@ ThreadSafeFunctionEx<ContextType, DataType, CallJs>::GetContext() const { | |
| // static | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| template <typename ResourceString, typename Finalizer, | ||
| typename FinalizerDataType> | ||
| inline ThreadSafeFunctionEx<ContextType, DataType, CallJs> | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New( | ||
| napi_env env, const Function &callback, const Object &resource, | ||
| ResourceString resourceName, size_t maxQueueSize, size_t initialThreadCount, | ||
| ContextType *context, Finalizer finalizeCallback, FinalizerDataType *data, | ||
| napi_finalize wrapper) { | ||
| static_assert(details::can_make_string<ResourceString>::value || | ||
| std::is_convertible<ResourceString, napi_value>::value, | ||
| "Resource name should be convertible to the string type"); | ||
|
|
||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs> tsfn; | ||
|
|
||
| auto *finalizeData = new details::ThreadSafeFinalize<ContextType, Finalizer, | ||
| FinalizerDataType>( | ||
| {data, finalizeCallback}); | ||
| napi_status status = napi_create_threadsafe_function( | ||
| env, callback, resource, Value::From(env, resourceName), maxQueueSize, | ||
| initialThreadCount, finalizeData, wrapper, context, CallJsInternal, | ||
| &tsfn._tsfn); | ||
| if (status != napi_ok) { | ||
| delete finalizeData; | ||
| NAPI_THROW_IF_FAILED(env, status, | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>()); | ||
| } | ||
|
|
||
| return tsfn; | ||
| void ThreadSafeFunctionEx<ContextType, DataType, CallJs>::CallJsInternal( | ||
| napi_env env, napi_value jsCallback, void *context, void *data) { | ||
| details::CallJsWrapper<ContextType, DataType, decltype(CallJs), CallJs>( | ||
| env, jsCallback, context, data); | ||
| } | ||
|
|
||
| // static | ||
| template <typename ContextType, typename DataType, | ||
| void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)> | ||
| void ThreadSafeFunctionEx<ContextType, DataType, CallJs>::CallJsInternal( | ||
| napi_env env, napi_value jsCallback, void *context, void *data) { | ||
| details::CallJsWrapper<ContextType, DataType, decltype(CallJs), CallJs>( | ||
| env, jsCallback, context, data); | ||
| typename ThreadSafeFunctionEx<ContextType, DataType, CallJs>::DefaultFunctionType | ||
| ThreadSafeFunctionEx<ContextType, DataType, CallJs>::DefaultFunctionFactory( | ||
| Napi::Env env) { | ||
| #if NAPI_VERSION > 4 | ||
| return nullptr; | ||
| #else | ||
| return Function::New(env, [](const CallbackInfo &cb) {}); | ||
| #endif | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was for testing, will remove...