CDROMAsyncReader: Support reading ahead more sectors
This commit is contained in:
@ -11,33 +11,49 @@ class CDROMAsyncReader
|
||||
public:
|
||||
using SectorBuffer = std::array<u8, CDImage::RAW_SECTOR_SIZE>;
|
||||
|
||||
struct BufferSlot
|
||||
{
|
||||
CDImage::LBA lba;
|
||||
SectorBuffer data;
|
||||
CDImage::SubChannelQ subq;
|
||||
bool result;
|
||||
};
|
||||
|
||||
CDROMAsyncReader();
|
||||
~CDROMAsyncReader();
|
||||
|
||||
const CDImage::LBA GetLastReadSector() const { return m_last_read_sector; }
|
||||
const SectorBuffer& GetSectorBuffer() const { return m_sector_buffer; }
|
||||
const CDImage::SubChannelQ& GetSectorSubQ() const { return m_subq; }
|
||||
const CDImage::LBA GetLastReadSector() const { return m_buffers[m_buffer_front.load()].lba; }
|
||||
const SectorBuffer& GetSectorBuffer() const { return m_buffers[m_buffer_front.load()].data; }
|
||||
const CDImage::SubChannelQ& GetSectorSubQ() const { return m_buffers[m_buffer_front.load()].subq; }
|
||||
const u32 GetBufferedSectorCount() const { return m_buffer_count.load(); }
|
||||
const bool HasBufferedSectors() const { return (m_buffer_count.load() > 0); }
|
||||
const u32 GetReadaheadCount() const { return static_cast<u32>(m_buffers.size()); }
|
||||
|
||||
const bool HasMedia() const { return static_cast<bool>(m_media); }
|
||||
const CDImage* GetMedia() const { return m_media.get(); }
|
||||
const std::string& GetMediaFileName() const { return m_media->GetFileName(); }
|
||||
|
||||
bool IsUsingThread() const { return m_read_thread.joinable(); }
|
||||
void StartThread();
|
||||
void StartThread(u32 readahead_count = 8);
|
||||
void StopThread();
|
||||
|
||||
void SetMedia(std::unique_ptr<CDImage> media);
|
||||
std::unique_ptr<CDImage> RemoveMedia();
|
||||
|
||||
void QueueReadSector(CDImage::LBA lba);
|
||||
void QueueReadNextSector();
|
||||
|
||||
bool WaitForReadToComplete();
|
||||
void WaitForIdle();
|
||||
|
||||
/// Bypasses the sector cache and reads directly from the image.
|
||||
bool ReadSectorUncached(CDImage::LBA lba, CDImage::SubChannelQ* subq, SectorBuffer* data);
|
||||
|
||||
private:
|
||||
void DoSectorRead();
|
||||
void EmptyBuffers();
|
||||
bool ReadSectorIntoBuffer(std::unique_lock<std::mutex>& lock);
|
||||
void ReadSectorNonThreaded(CDImage::LBA lba);
|
||||
void CancelReadahead();
|
||||
|
||||
void WorkerThreadEntryPoint();
|
||||
|
||||
std::unique_ptr<CDImage> m_media;
|
||||
@ -47,13 +63,16 @@ private:
|
||||
std::condition_variable m_do_read_cv;
|
||||
std::condition_variable m_notify_read_complete_cv;
|
||||
|
||||
CDImage::LBA m_next_position{};
|
||||
std::atomic<CDImage::LBA> m_next_position{};
|
||||
std::atomic_bool m_next_position_set{false};
|
||||
std::atomic_bool m_sector_read_pending{false};
|
||||
std::atomic_bool m_shutdown_flag{true};
|
||||
|
||||
CDImage::LBA m_last_read_sector{};
|
||||
CDImage::SubChannelQ m_subq{};
|
||||
SectorBuffer m_sector_buffer{};
|
||||
std::atomic_bool m_sector_read_result{false};
|
||||
std::atomic_bool m_is_reading{ false };
|
||||
std::atomic_bool m_can_readahead{ false };
|
||||
std::atomic_bool m_seek_error{ false };
|
||||
|
||||
std::vector<BufferSlot> m_buffers;
|
||||
std::atomic<u32> m_buffer_front{ 0 };
|
||||
std::atomic<u32> m_buffer_back{ 0 };
|
||||
std::atomic<u32> m_buffer_count{ 0 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user