@@ -55,6 +55,34 @@ namespace winrt::Microsoft::Management::Configuration::implementation
5555 std::unique_ptr<AppInstaller::WinRT::AsyncCancellation> m_cancellation;
5656 };
5757
58+ struct ShutdownSynchronization
59+ {
60+ using CancellableWeakPtr = std::weak_ptr<AppInstaller::WinRT::details::AsyncCancellationTypeErasure>;
61+
62+ ShutdownSynchronization () = default ;
63+
64+ static ShutdownSynchronization& Instance ();
65+
66+ // Signals that new work should be blocked.
67+ void BlockNewWork ();
68+
69+ // Call to register the begin and end of work.
70+ void RegisterWorkBegin (CancellableWeakPtr&& ptr);
71+ void RegisterWorkEnd (CancellableWeakPtr&& ptr);
72+
73+ // Cancels all currently registered work.
74+ void CancelAllWork ();
75+
76+ // Waits for outstanding work to be completed.
77+ void Wait ();
78+
79+ private:
80+ std::atomic_bool m_disabled{ false };
81+ std::mutex m_workLock;
82+ std::set<CancellableWeakPtr, std::owner_less<CancellableWeakPtr>> m_work;
83+ wil::slim_event_manual_reset m_noActiveWork{ true };
84+ };
85+
5886 // An AsyncProgress that registers with ShutdownSynchronization.
5987 template <typename ResultT, typename ProgressT>
6088 struct ShutdownAwareAsyncProgress
@@ -142,32 +170,4 @@ namespace winrt::Microsoft::Management::Configuration::implementation
142170 std::unique_ptr<ShutdownAwareAsyncCancellationPromise> m_defaultPromise;
143171 std::unique_ptr<AppInstaller::WinRT::AsyncProgress<ResultT, ProgressT>> m_progress;
144172 };
145-
146- struct ShutdownSynchronization
147- {
148- using CancellableWeakPtr = std::weak_ptr<AppInstaller::WinRT::details::AsyncCancellationTypeErasure>;
149-
150- ShutdownSynchronization () = default ;
151-
152- static ShutdownSynchronization& Instance ();
153-
154- // Signals that new work should be blocked.
155- void BlockNewWork ();
156-
157- // Call to register the begin and end of work.
158- void RegisterWorkBegin (CancellableWeakPtr&& ptr);
159- void RegisterWorkEnd (CancellableWeakPtr&& ptr);
160-
161- // Cancels all currently registered work.
162- void CancelAllWork ();
163-
164- // Waits for outstanding work to be completed.
165- void Wait ();
166-
167- private:
168- std::atomic_bool m_disabled{ false };
169- std::mutex m_workLock;
170- std::set<CancellableWeakPtr, std::owner_less<CancellableWeakPtr>> m_work;
171- wil::slim_event_manual_reset m_noActiveWork{ true };
172- };
173173}
0 commit comments