cdvdgigaherz:linux: Use pread instead of lseek + read

It'll make it unnecessary to use a lock when reading disc sectors.
This commit is contained in:
Jonathan Li 2016-12-07 00:54:11 +00:00
parent 5109687a31
commit 1d634f9b44
2 changed files with 2 additions and 10 deletions

View File

@ -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<toc_entry> m_toc;
mutable std::mutex m_lock;
bool ReadDVDInfo();
bool ReadCDInfo();

View File

@ -86,16 +86,8 @@ const std::vector<toc_entry> &IOCtlSrc::ReadTOC() const
bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, u8 *buffer) const
{
std::lock_guard<std::mutex> 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;