void *ThreadedFrameSource::Entry() { while (!TestDestroy()) { double time; int frameNum; std::unique_ptr<AssFile> newSubs; std::deque<std::pair<size_t, std::unique_ptr<AssEntry>>> updates; { wxMutexLocker jobLocker(jobMutex); if (!run) return EXIT_SUCCESS; if (nextTime == -1.) { jobReady.Wait(); continue; } time = nextTime; frameNum = nextFrame; nextTime = -1.; newSubs = move(nextSubs); updates = move(changedSubs); } if (newSubs || updates.size()) { wxMutexLocker fileLocker(fileMutex); if (newSubs) subs = move(newSubs); if (updates.size()) { size_t i = 0; auto it = subs->Line.begin(); // Replace each changed line in subs with the updated version for (auto& update : updates) { advance(it, update.first - i); i = update.first; subs->Line.insert(it, *update.second.release()); delete &*it--; } } singleFrame = -1; } try { FrameReadyEvent *evt = new FrameReadyEvent(ProcFrame(frameNum, time), time); evt->SetEventType(EVT_FRAME_READY); parent->QueueEvent(evt); } catch (wxEvent const& err) { // Pass error back to parent thread parent->QueueEvent(err.Clone()); } } return EXIT_SUCCESS; }
void *ThreadedFrameSource::Entry() { while (!TestDestroy()) { double time; int frameNum; std::auto_ptr<AssFile> newSubs; { wxMutexLocker jobLocker(jobMutex); if (!run) return EXIT_SUCCESS; if (nextTime == -1.) { jobReady.Wait(); continue; } time = nextTime; frameNum = nextFrame; nextTime = -1.; newSubs = nextSubs; } if (newSubs.get()) { wxMutexLocker fileLocker(fileMutex); subs = newSubs; singleFrame = -1; } try { FrameReadyEvent *evt = new FrameReadyEvent(ProcFrame(frameNum, time), time); evt->SetEventType(EVT_FRAME_READY); parent->QueueEvent(evt); } catch (wxEvent const& err) { // Pass error back to parent thread parent->QueueEvent(err.Clone()); } } return EXIT_SUCCESS; }