master
h 51 lines 1.17 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 IORelay.h
8
9 Abstract:
10
11 Contains the definition of the IORelay class.
12
13 --*/
14
15 #pragma once
16
17 namespace wsl::windows::service::wslc {
18
19 class IORelay
20 {
21
22 public:
23 NON_COPYABLE(IORelay);
24
25 IORelay();
26 ~IORelay();
27
28 void AddHandles(std::vector<std::unique_ptr<common::io::OverlappedIOHandle>>&& Handles);
29 void AddHandle(std::unique_ptr<common::io::OverlappedIOHandle>&& Handle);
30
31 void Stop();
32
33 // Returns true if the calling thread is the IORelay's own worker thread (i.e. the call
34 // is being made from a handle callback). Destroying the IORelay from this thread would
35 // join the thread with itself and call std::terminate(), so callers that may run on the
36 // relay thread must check this before destroying the object.
37 bool IsRelayThread() const noexcept;
38
39 private:
40 void Start();
41 void Run();
42
43 std::mutex m_pendingHandlesLock;
44 wil::unique_event m_refreshEvent{wil::EventOptions::None};
45 std::vector<std::unique_ptr<common::io::OverlappedIOHandle>> m_pendingHandles;
46
47 std::thread m_thread;
48 std::atomic<bool> m_exit = false;
49 };
50
51 } // namespace wsl::windows::service::wslc