CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/HW/AsyncIOManager.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <map>20#include <set>21#include <mutex>2223#include "Core/ThreadEventQueue.h"2425class NoBase {26};2728enum AsyncIOEventType {29IO_EVENT_INVALID,30IO_EVENT_SYNC,31IO_EVENT_FINISH,32IO_EVENT_READ,33IO_EVENT_WRITE,34};3536struct AsyncIOEvent {37AsyncIOEvent(AsyncIOEventType t) : type(t) {}38AsyncIOEventType type;39u32 handle;40u8 *buf;41size_t bytes;42u32 invalidateAddr;4344operator AsyncIOEventType() const {45return type;46}47};4849struct AsyncIOResult {50AsyncIOResult() : result(0), finishTicks(0), invalidateAddr(0) {51}5253explicit AsyncIOResult(s64 r) : result(r), finishTicks(0), invalidateAddr(0) {54}5556AsyncIOResult(s64 r, int usec, u32 addr = 0) : result(r), invalidateAddr(addr) {57finishTicks = CoreTiming::GetTicks() + usToCycles(usec);58}5960void DoState(PointerWrap &p) {61auto s = p.Section("AsyncIOResult", 1, 2);62if (!s)63return;6465Do(p, result);66Do(p, finishTicks);67if (s >= 2) {68Do(p, invalidateAddr);69} else {70invalidateAddr = 0;71}72}7374s64 result;75u64 finishTicks;76u32 invalidateAddr;77};7879typedef ThreadEventQueue<NoBase, AsyncIOEvent, AsyncIOEventType, IO_EVENT_INVALID, IO_EVENT_SYNC, IO_EVENT_FINISH> IOThreadEventQueue;80class AsyncIOManager : public IOThreadEventQueue {81public:82void DoState(PointerWrap &p);8384bool HasOperation(u32 handle);85void ScheduleOperation(const AsyncIOEvent &ev);86void Shutdown();8788bool HasResult(u32 handle);89bool WaitResult(u32 handle, AsyncIOResult &result);90u64 ResultFinishTicks(u32 handle);9192protected:93void ProcessEvent(AsyncIOEvent ref) override;94bool ShouldExitEventLoop() override {95return coreState == CORE_BOOT_ERROR || coreState == CORE_RUNTIME_ERROR || coreState == CORE_POWERDOWN;96}9798private:99bool PopResult(u32 handle, AsyncIOResult &result);100bool ReadResult(u32 handle, AsyncIOResult &result);101void Read(u32 handle, u8 *buf, size_t bytes, u32 invalidateAddr);102void Write(u32 handle, const u8 *buf, size_t bytes);103104void EventResult(u32 handle, const AsyncIOResult &result);105106std::mutex resultsLock_;107std::condition_variable resultsWait_;108std::set<u32> resultsPending_;109std::map<u32, AsyncIOResult> results_;110};111112113