MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / entryAcquire

Function entryAcquire

test/threadsafe_function/threadsafe_function_sum.cc:167–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void entryAcquire(ThreadSafeFunction tsfn, int threadId) {
168 tsfn.Acquire();
169 TestData* testData = tsfn.GetContext();
170 std::this_thread::sleep_for(std::chrono::milliseconds(std::rand() % 100 + 1));
171 tsfn.BlockingCall([=](Napi::Env env, Function callback) {
172 // This lambda runs on the main thread so it's OK to access the variables
173 // `expected_calls` and `mainWantsRelease`.
174 testData->expected_calls--;
175 if (testData->expected_calls == 0 && testData->mainWantsRelease)
176 testData->tsfn.Release();
177 callback.Call({Number::New(env, static_cast<double>(threadId))});
178 });
179 tsfn.Release();
180}
181
182static Value CreateThread(const CallbackInfo& info) {
183 TestData* testData = static_cast<TestData*>(info.Data());

Callers

nothing calls this directly

Calls 5

AcquireMethod · 0.80
BlockingCallMethod · 0.80
CallMethod · 0.80
GetContextMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected