1 | /* |
2 | * IXSelectInterruptPipe.h |
3 | * Author: Benjamin Sergeant |
4 | * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved. |
5 | */ |
6 | |
7 | #pragma once |
8 | |
9 | #include "IXSelectInterrupt.h" |
10 | #include <mutex> |
11 | #include <stdint.h> |
12 | #include <string> |
13 | |
14 | namespace ix |
15 | { |
16 | class SelectInterruptPipe final : public SelectInterrupt |
17 | { |
18 | public: |
19 | SelectInterruptPipe(); |
20 | virtual ~SelectInterruptPipe(); |
21 | |
22 | bool init(std::string& errorMsg) final; |
23 | |
24 | bool notify(uint64_t value) final; |
25 | bool clear() final; |
26 | uint64_t read() final; |
27 | int getFd() const final; |
28 | |
29 | private: |
30 | // Store file descriptors used by the communication pipe. Communication |
31 | // happens between a control thread and a background thread, which is |
32 | // blocked on select. |
33 | int _fildes[2]; |
34 | mutable std::mutex _fildesMutex; |
35 | |
36 | // Used to identify the read/write idx |
37 | static const int kPipeReadIndex; |
38 | static const int kPipeWriteIndex; |
39 | }; |
40 | } // namespace ix |
41 | |