-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterruptController.hpp
More file actions
43 lines (32 loc) · 943 Bytes
/
Copy pathInterruptController.hpp
File metadata and controls
43 lines (32 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef _INTERRUPTCONTROLLER_HPP
#define _INTERRUPTCONTROLLER_HPP
#include <condition_variable>
#include <thread>
#include <vector>
#include <mutex>
#include <queue>
#include "util.hpp"
class CPU;
struct ProcessControlBlock;
struct IOEvent {
std::chrono::steady_clock::time_point mWhen;
ProcessControlBlock* mPcb = nullptr;
bool operator<(IOEvent const& o) const { return mWhen > o.mWhen; }
};
class InterruptController {
public:
NON_COPYABLE(InterruptController)
InterruptController();
~InterruptController();
void NotifyBlocked(ProcessControlBlock*);
private:
void IOWorker(std::stop_token);
// Synchronisation
std::jthread mIoThread;
std::mutex mMutex;
std::condition_variable mCv;
// State
std::vector<ProcessControlBlock*> mNewBlocks; // Newly blocked processes that haven't been added to pending events
std::priority_queue<IOEvent> mPendingEvents; // All pending events that are awaiting comp[letion
};
#endif