static void StartReadInternal(bool copy_to_ram, u32 output_address, u64 dvd_offset, u32 length, const DiscIO::Partition& partition, DVDInterface::ReplyType reply_type, s64 ticks_until_completion) { ASSERT(Core::IsCPUThread()); ReadRequest request; request.copy_to_ram = copy_to_ram; request.output_address = output_address; request.dvd_offset = dvd_offset; request.length = length; request.partition = partition; request.reply_type = reply_type; u64 id = s_next_id++; request.id = id; request.time_started_ticks = CoreTiming::GetTicks(); request.realtime_started_us = Common::Timer::GetTimeUs(); s_request_queue.Push(std::move(request)); s_request_queue_expanded.Set(); CoreTiming::ScheduleEvent(ticks_until_completion, s_finish_read, id); }
static void DVDThread() { Common::SetCurrentThreadName("DVD thread"); while (true) { s_request_queue_expanded.Wait(); if (s_dvd_thread_exiting.IsSet()) return; ReadRequest request; while (s_request_queue.Pop(request)) { FileMonitor::Log(*s_disc, request.partition, request.dvd_offset); std::vector<u8> buffer(request.length); if (!s_disc->Read(request.dvd_offset, request.length, buffer.data(), request.partition)) buffer.resize(0); request.realtime_done_us = Common::Timer::GetTimeUs(); s_result_queue.Push(ReadResult(std::move(request), std::move(buffer))); s_result_queue_expanded.Set(); if (s_dvd_thread_exiting.IsSet()) return; } } }
void ScheduleEvent(s64 cycles_into_future, EventType* event_type, u64 userdata, FromThread from) { ASSERT_MSG(POWERPC, event_type, "Event type is nullptr, will crash now."); bool from_cpu_thread; if (from == FromThread::ANY) { from_cpu_thread = Core::IsCPUThread(); } else { from_cpu_thread = from == FromThread::CPU; ASSERT_MSG(POWERPC, from_cpu_thread == Core::IsCPUThread(), "A \"%s\" event was scheduled from the wrong thread (%s)", event_type->name->c_str(), from_cpu_thread ? "CPU" : "non-CPU"); } if (from_cpu_thread) { s64 timeout = GetTicks() + cycles_into_future; // If this event needs to be scheduled before the next advance(), force one early if (!s_is_global_timer_sane) ForceExceptionCheck(cycles_into_future); s_event_queue.emplace_back(Event{timeout, s_event_fifo_id++, userdata, event_type}); std::push_heap(s_event_queue.begin(), s_event_queue.end(), std::greater<Event>()); } else { if (Core::WantsDeterminism()) { ERROR_LOG(POWERPC, "Someone scheduled an off-thread \"%s\" event while netplay or " "movie play/record was active. This is likely to cause a desync.", event_type->name->c_str()); } std::lock_guard<std::mutex> lk(s_ts_write_lock); s_ts_queue.Push(Event{g.global_timer + cycles_into_future, 0, userdata, event_type}); } }