~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Core/HW/AsyncIOManager.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2012- PPSSPP Project.
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
18
#include <map>
 
19
#include <set>
 
20
#include "base/mutex.h"
 
21
#include "Core/ThreadEventQueue.h"
 
22
 
 
23
class NoBase {
 
24
};
 
25
 
 
26
enum AsyncIOEventType {
 
27
        IO_EVENT_INVALID,
 
28
        IO_EVENT_SYNC,
 
29
        IO_EVENT_FINISH,
 
30
        IO_EVENT_READ,
 
31
        IO_EVENT_WRITE,
 
32
};
 
33
 
 
34
struct AsyncIOEvent {
 
35
        AsyncIOEvent(AsyncIOEventType t) : type(t) {}
 
36
        AsyncIOEventType type;
 
37
        u32 handle;
 
38
        u8 *buf;
 
39
        size_t bytes;
 
40
        u32 invalidateAddr;
 
41
 
 
42
        operator AsyncIOEventType() const {
 
43
                return type;
 
44
        }
 
45
};
 
46
 
 
47
struct AsyncIOResult {
 
48
        AsyncIOResult() : result(0), finishTicks(0), invalidateAddr(0) {
 
49
        }
 
50
 
 
51
        explicit AsyncIOResult(s64 r) : result(r), finishTicks(0), invalidateAddr(0) {
 
52
        }
 
53
 
 
54
        AsyncIOResult(s64 r, int usec, u32 addr = 0) : result(r), invalidateAddr(addr) {
 
55
                finishTicks = CoreTiming::GetTicks() + usToCycles(usec);
 
56
        }
 
57
 
 
58
        void DoState(PointerWrap &p) {
 
59
                auto s = p.Section("AsyncIOResult", 1, 2);
 
60
                if (!s)
 
61
                        return;
 
62
 
 
63
                p.Do(result);
 
64
                p.Do(finishTicks);
 
65
                if (s >= 2) {
 
66
                        p.Do(invalidateAddr);
 
67
                } else {
 
68
                        invalidateAddr = 0;
 
69
                }
 
70
        }
 
71
 
 
72
        s64 result;
 
73
        u64 finishTicks;
 
74
        u32 invalidateAddr;
 
75
};
 
76
 
 
77
typedef ThreadEventQueue<NoBase, AsyncIOEvent, AsyncIOEventType, IO_EVENT_INVALID, IO_EVENT_SYNC, IO_EVENT_FINISH> IOThreadEventQueue;
 
78
class AsyncIOManager : public IOThreadEventQueue {
 
79
public:
 
80
        void DoState(PointerWrap &p);
 
81
 
 
82
        bool HasOperation(u32 handle);
 
83
        void ScheduleOperation(AsyncIOEvent ev);
 
84
        void Shutdown();
 
85
 
 
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);
 
91
 
 
92
protected:
 
93
        void ProcessEvent(AsyncIOEvent ref) override;
 
94
        bool ShouldExitEventLoop() override {
 
95
                return coreState == CORE_ERROR || coreState == CORE_POWERDOWN;
 
96
        }
 
97
 
 
98
private:
 
99
        void Read(u32 handle, u8 *buf, size_t bytes, u32 invalidateAddr);
 
100
        void Write(u32 handle, u8 *buf, size_t bytes);
 
101
 
 
102
        void EventResult(u32 handle, AsyncIOResult result);
 
103
 
 
104
        recursive_mutex resultsLock_;
 
105
        condition_variable resultsWait_;
 
106
        std::set<u32> resultsPending_;
 
107
        std::map<u32, AsyncIOResult> results_;
 
108
};
 
 
b'\\ No newline at end of file'