From 3919a32dc3d2cb1f0d3ec845a7dffa192034a5ff Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 16 Nov 2016 22:02:00 +0000 Subject: [PATCH] cdvdgigaherz: Avoid race condition by reading from cache/disk Instead of reading from a buffer shared by multiple threads, just read the correct data from the cache or disk instead. --- plugins/cdvdGigaherz/src/ReadThread.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/plugins/cdvdGigaherz/src/ReadThread.cpp b/plugins/cdvdGigaherz/src/ReadThread.cpp index 22e64e88e6..ab3be201ed 100644 --- a/plugins/cdvdGigaherz/src/ReadThread.cpp +++ b/plugins/cdvdGigaherz/src/ReadThread.cpp @@ -37,7 +37,6 @@ static std::thread s_thread; static std::mutex s_notify_lock; static std::condition_variable s_notify_cv; static std::mutex s_request_lock; -static std::condition_variable s_request_cv; static std::mutex s_cache_lock; static std::atomic cdvd_is_open; @@ -195,7 +194,6 @@ void cdvdThread() handlingRequest = false; threadRequestPending = false; - s_request_cv.notify_one(); prefetch_last_lba = info.lsn; prefetch_last_mode = info.mode; @@ -259,19 +257,20 @@ s32 cdvdRequestComplete() u8 *cdvdGetSector(u32 sector, s32 mode) { - { - std::unique_lock guard(s_request_lock); - while (threadRequestPending) - s_request_cv.wait_for(guard, std::chrono::milliseconds(10)); - } + static u8 buffer[2352 * 16]; + u32 sector_block = sector & ~15; + + if (!cdvdCacheFetch(sector_block, mode, buffer)) + if (cdvdReadBlockOfSectors(sector_block, mode, buffer)) + cdvdCacheUpdate(sector_block, mode, buffer); if (mode == CDVD_MODE_2048) { - u32 offset = 2048 * (sector - threadRequestInfo.lsn); - return threadRequestInfo.data + offset; + u32 offset = 2048 * (sector - sector_block); + return buffer + offset; } - u32 offset = 2352 * (sector - threadRequestInfo.lsn); - u8 *data = threadRequestInfo.data + offset; + u32 offset = 2352 * (sector - sector_block); + u8 *data = buffer + offset; switch (mode) { case CDVD_MODE_2328: