| 180 | } |
| 181 | |
| 182 | static Value CreateThread(const CallbackInfo& info) { |
| 183 | TestData* testData = static_cast<TestData*>(info.Data()); |
| 184 | // Counting expected calls like this only works because on the JS side this |
| 185 | // binding is called from a synchronous loop. This means the main loop has no |
| 186 | // chance to run the tsfn JS callback before we've counted how many threads |
| 187 | // the JS intends to create. |
| 188 | testData->expected_calls++; |
| 189 | ThreadSafeFunction tsfn = testData->tsfn; |
| 190 | int threadId = testData->threads.size(); |
| 191 | // A copy of the ThreadSafeFunction will go to the thread entry point |
| 192 | testData->threads.push_back(std::thread(entryAcquire, tsfn, threadId)); |
| 193 | return Number::New(info.Env(), threadId); |
| 194 | } |
| 195 | |
| 196 | static Value StopThreads(const CallbackInfo& info) { |
| 197 | TestData* testData = static_cast<TestData*>(info.Data()); |