| 165 | } |
| 166 | |
| 167 | void 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 | |
| 182 | static Value CreateThread(const CallbackInfo& info) { |
| 183 | TestData* testData = static_cast<TestData*>(info.Data()); |
nothing calls this directly
no test coverage detected