コード例 #1
0
void JSCWebWorker::terminate() {
  if (isTerminated()) {
    return;
  }
  isTerminated_.store(true, std::memory_order_release);

  if (workerMessageQueueThread_->isOnThread()) {
    terminateOnWorkerThread();
  } else {
    std::mutex signalMutex;
    std::condition_variable signalCv;
    bool terminationComplete = false;

    workerMessageQueueThread_->runOnQueue([&] () mutable {
      std::lock_guard<std::mutex> lock(signalMutex);

      terminateOnWorkerThread();
      terminationComplete = true;

      signalCv.notify_one();
    });

    std::unique_lock<std::mutex> lock(signalMutex);
    signalCv.wait(lock, [&terminationComplete] { return terminationComplete; });
  }
}
コード例 #2
0
void JSCWebWorker::terminate() {
  if (isTerminated()) {
    return;
  }
  isTerminated_.store(true, std::memory_order_release);

  workerMessageQueueThread_->runOnQueueSync([this] {
    terminateOnWorkerThread();
  });
}