| 2910 | std::lock_guard<Mutex> guard(_jsWorkersMutex); |
| 2911 | std::vector<Ref<JavaScriptRuntime>> out; |
| 2912 | out.reserve(_jsWorkers.size()); |
| 2913 | |
| 2914 | auto it = _jsWorkers.begin(); |
| 2915 | while (it != _jsWorkers.end()) { |
| 2916 | auto jsWorker = it->lock(); |
| 2917 | if (jsWorker != nullptr && !jsWorker->isDisposed()) { |
| 2918 | out.emplace_back(std::move(jsWorker)); |
| 2919 | it++; |
| 2920 | } else { |
| 2921 | it = _jsWorkers.erase(it); |
| 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | return out; |
| 2926 | } |
| 2927 | |
| 2928 | void JavaScriptRuntime::markWorkersHostTornDown() { |
| 2929 | if (!_stopWorkersOnHostTeardown) { |
| 2930 | return; |
| 2931 | } |
| 2932 | |
| 2933 | // Not getAllWorkers(): it skips and forgets disposed workers, and a disposed worker can still have work |
| 2934 | // queued that reaches into this runtime's state. Mark outside the lock: dropping the last ref to a worker |
| 2935 | // runs its destructor, which joins its JS thread. |
| 2936 | std::vector<Ref<JavaScriptRuntime>> workers; |
| 2937 | { |
| 2938 | std::lock_guard<Mutex> guard(_jsWorkersMutex); |
| 2939 | workers.reserve(_jsWorkers.size()); |
| 2940 | for (const auto& weakWorker : _jsWorkers) { |
| 2941 | auto jsWorker = weakWorker.lock(); |
| 2942 | if (jsWorker != nullptr) { |
| 2943 | workers.emplace_back(std::move(jsWorker)); |
| 2944 | } |
| 2945 | } |
| 2946 | } |
| 2947 | for (const auto& jsWorker : workers) { |
| 2948 | jsWorker->markHostTornDown(); |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | void JavaScriptRuntime::dispatchPerformGcToWorkers() { |
| 2953 | for (const auto& jsWorker : getAllWorkers()) { |
| 2954 | jsWorker->performGc(); |
| 2955 | } |
nothing calls this directly
no test coverage detected