From 1d634f9b44d2e4b7d7f14d1787041de7843f3bc6 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 7 Dec 2016 00:54:11 +0000 Subject: [PATCH] cdvdgigaherz:linux: Use pread instead of lseek + read It'll make it unnecessary to use a lock when reading disc sectors. --- plugins/cdvdGigaherz/src/CDVD.h | 2 +- plugins/cdvdGigaherz/src/Unix/LinuxIOCtlSrc.cpp | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/plugins/cdvdGigaherz/src/CDVD.h b/plugins/cdvdGigaherz/src/CDVD.h index ddc3547460..41856aeef6 100644 --- a/plugins/cdvdGigaherz/src/CDVD.h +++ b/plugins/cdvdGigaherz/src/CDVD.h @@ -63,6 +63,7 @@ class IOCtlSrc #if defined(_WIN32) HANDLE m_device = INVALID_HANDLE_VALUE; std::wstring m_filename; + mutable std::mutex m_lock; #else int m_device = -1; std::string m_filename; @@ -72,7 +73,6 @@ class IOCtlSrc u32 m_sectors = 0; u32 m_layer_break = 0; std::vector m_toc; - mutable std::mutex m_lock; bool ReadDVDInfo(); bool ReadCDInfo(); diff --git a/plugins/cdvdGigaherz/src/Unix/LinuxIOCtlSrc.cpp b/plugins/cdvdGigaherz/src/Unix/LinuxIOCtlSrc.cpp index 59b5694536..500043bec2 100644 --- a/plugins/cdvdGigaherz/src/Unix/LinuxIOCtlSrc.cpp +++ b/plugins/cdvdGigaherz/src/Unix/LinuxIOCtlSrc.cpp @@ -86,16 +86,8 @@ const std::vector &IOCtlSrc::ReadTOC() const bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, u8 *buffer) const { - std::lock_guard guard(m_lock); - - if (lseek(m_device, sector * 2048ULL, SEEK_SET) == -1) { - fprintf(stderr, " * CDVD lseek sectors %u failed: %s\n", - sector, strerror(errno)); - return false; - } - const ssize_t bytes_to_read = 2048 * count; - ssize_t bytes_read = read(m_device, buffer, bytes_to_read); + ssize_t bytes_read = pread(m_device, buffer, bytes_to_read, sector * 2048ULL); if (bytes_read == bytes_to_read) return true;