async-iso: finish the linux port

Warning new dependency libaio. Cmake would need to be fixed later too.


git-svn-id: http://pcsx2.googlecode.com/svn/branches/async-iso@5476 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2012-12-07 15:53:27 +00:00
parent 401bd9201e
commit 038dbd8401
3 changed files with 44 additions and 51 deletions

View File

@ -3,6 +3,8 @@
#ifdef WIN32 #ifdef WIN32
# include <Windows.h> # include <Windows.h>
# undef Yield # undef Yield
#else
# include <libaio.h>
#endif #endif
class AsyncFileReader class AsyncFileReader
@ -49,9 +51,12 @@ class FlatFileReader : public AsyncFileReader
OVERLAPPED asyncOperationContext; OVERLAPPED asyncOperationContext;
HANDLE hEvent; HANDLE hEvent;
#else
#endif
bool asyncInProgress; bool asyncInProgress;
#else
int m_fd; // FIXME don't know if overlap as an equivalent on linux
io_context_t m_aio_context;
#endif
public: public:
FlatFileReader(void); FlatFileReader(void);

View File

@ -694,6 +694,8 @@ endif(Linux)
# link target with zlib # link target with zlib
target_link_libraries(${Output} ${ZLIB_LIBRARIES}) target_link_libraries(${Output} ${ZLIB_LIBRARIES})
target_link_libraries(${Output} "aio")
# User flags options # User flags options
if(NOT USER_CMAKE_LD_FLAGS STREQUAL "") if(NOT USER_CMAKE_LD_FLAGS STREQUAL "")
target_link_libraries(${Output} "${USER_CMAKE_LD_FLAGS}") target_link_libraries(${Output} "${USER_CMAKE_LD_FLAGS}")

View File

@ -4,9 +4,8 @@
FlatFileReader::FlatFileReader(void) FlatFileReader::FlatFileReader(void)
{ {
m_blocksize = 2048; m_blocksize = 2048;
//hOverlappedFile = INVALID_HANDLE_VALUE; m_fd = 0;
//hEvent = INVALID_HANDLE_VALUE; m_aio_context = 0;
asyncInProgress = false;
} }
FlatFileReader::~FlatFileReader(void) FlatFileReader::~FlatFileReader(void)
@ -18,19 +17,12 @@ bool FlatFileReader::Open(const wxString& fileName)
{ {
m_filename = fileName; m_filename = fileName;
//hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); int err = io_setup(64, &m_aio_context);
if (err) return false;
//hOverlappedFile = CreateFile( m_fd = wxOpen(fileName, O_RDONLY, 0);
// fileName,
// GENERIC_READ,
// FILE_SHARE_READ,
// NULL,
// OPEN_EXISTING,
// FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED,
// NULL);
//return hOverlappedFile != INVALID_HANDLE_VALUE; return (m_fd != 0);
return true;
} }
int FlatFileReader::ReadSync(void* pBuffer, uint sector, uint count) int FlatFileReader::ReadSync(void* pBuffer, uint sector, uint count)
@ -41,60 +33,54 @@ int FlatFileReader::ReadSync(void* pBuffer, uint sector, uint count)
void FlatFileReader::BeginRead(void* pBuffer, uint sector, uint count) void FlatFileReader::BeginRead(void* pBuffer, uint sector, uint count)
{ {
LARGE_INTEGER offset; u64 offset;
//offset.QuadPart = sector * (__int64)m_blocksize; offset = sector * (u64)m_blocksize;
//DWORD bytesToRead = count * m_blocksize; u32 bytesToRead = count * m_blocksize;
//ZeroMemory(&asyncOperationContext, sizeof(asyncOperationContext)); struct iocb iocb;
//asyncOperationContext.hEvent = hEvent; struct iocb* iocbs = &iocb;
//asyncOperationContext.Offset = offset.LowPart;
//asyncOperationContext.OffsetHigh = offset.HighPart;
//ReadFile(hOverlappedFile, pBuffer, bytesToRead, NULL, &asyncOperationContext); io_prep_pread(&iocb, m_fd, pBuffer, bytesToRead, offset);
asyncInProgress = true; io_submit(m_aio_context, 1, &iocbs);
} }
int FlatFileReader::FinishRead(void) int FlatFileReader::FinishRead(void)
{ {
//DWORD bytes; u32 bytes;
//
//if(!GetOverlappedResult(hOverlappedFile, &asyncOperationContext, &bytes, TRUE))
//{
// asyncInProgress = false;
// return -1;
//}
asyncInProgress = false; int min_nr = 1;
//return bytes; int max_nr = 1;
return 0; struct io_event* events = new io_event[max_nr];
int event = io_getevents(m_aio_context, min_nr, max_nr, events, NULL);
if (event < 1) {
return -1;
}
return 1;
} }
void FlatFileReader::CancelRead(void) void FlatFileReader::CancelRead(void)
{ {
//CancelIo(hOverlappedFile); // Will be done when m_aio_context context is destroyed
// Note: io_cancel exists but need the iocb structure as parameter
// int io_cancel(aio_context_t ctx_id, struct iocb *iocb,
// struct io_event *result);
} }
void FlatFileReader::Close(void) void FlatFileReader::Close(void)
{ {
//if(asyncInProgress)
// CancelRead();
//if(hOverlappedFile != INVALID_HANDLE_VALUE) if (m_fd) close(m_fd);
// CloseHandle(hOverlappedFile);
//if(hEvent != INVALID_HANDLE_VALUE) io_destroy(m_aio_context);
// CloseHandle(hEvent);
//hOverlappedFile = INVALID_HANDLE_VALUE; m_fd = 0;
//hEvent = INVALID_HANDLE_VALUE; m_aio_context = 0;
} }
int FlatFileReader::GetBlockCount(void) const uint FlatFileReader::GetBlockCount(void) const
{ {
LARGE_INTEGER fileSize; return (int)(Path::GetFileSize(m_filename) / m_blocksize);
//fileSize.LowPart = GetFileSize(hOverlappedFile, (DWORD*)&(fileSize.HighPart));
//return (int)(fileSize.QuadPart / m_blocksize);
return 0;
} }