1
// Copyright (c) 2012- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
20
#include "base/mutex.h"
21
#include "Core/ThreadEventQueue.h"
26
enum AsyncIOEventType {
35
AsyncIOEvent(AsyncIOEventType t) : type(t) {}
36
AsyncIOEventType type;
42
operator AsyncIOEventType() const {
47
struct AsyncIOResult {
48
AsyncIOResult() : result(0), finishTicks(0), invalidateAddr(0) {
51
explicit AsyncIOResult(s64 r) : result(r), finishTicks(0), invalidateAddr(0) {
54
AsyncIOResult(s64 r, int usec, u32 addr = 0) : result(r), invalidateAddr(addr) {
55
finishTicks = CoreTiming::GetTicks() + usToCycles(usec);
58
void DoState(PointerWrap &p) {
59
auto s = p.Section("AsyncIOResult", 1, 2);
77
typedef ThreadEventQueue<NoBase, AsyncIOEvent, AsyncIOEventType, IO_EVENT_INVALID, IO_EVENT_SYNC, IO_EVENT_FINISH> IOThreadEventQueue;
78
class AsyncIOManager : public IOThreadEventQueue {
80
void DoState(PointerWrap &p);
82
bool HasOperation(u32 handle);
83
void ScheduleOperation(AsyncIOEvent ev);
86
bool HasResult(u32 handle);
87
bool PopResult(u32 handle, AsyncIOResult &result);
88
bool ReadResult(u32 handle, AsyncIOResult &result);
89
bool WaitResult(u32 handle, AsyncIOResult &result);
90
u64 ResultFinishTicks(u32 handle);
93
void ProcessEvent(AsyncIOEvent ref) override;
94
bool ShouldExitEventLoop() override {
95
return coreState == CORE_ERROR || coreState == CORE_POWERDOWN;
99
void Read(u32 handle, u8 *buf, size_t bytes, u32 invalidateAddr);
100
void Write(u32 handle, u8 *buf, size_t bytes);
102
void EventResult(u32 handle, AsyncIOResult result);
104
recursive_mutex resultsLock_;
105
condition_variable resultsWait_;
106
std::set<u32> resultsPending_;
107
std::map<u32, AsyncIOResult> results_;
b'\\ No newline at end of file'