ConfigurationSequencer.h (1977B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "Database/ConfigurationDatabase.h" 5 #include <winget/AsyncTokens.h> 6 #include <wil/resource.h> 7 #include <winrt/Microsoft.Management.Configuration.h> 8 9 10 namespace winrt::Microsoft::Management::Configuration::implementation 11 { 12 // Allows for sequencing of configuration set applications. 13 struct ConfigurationSequencer 14 { 15 ConfigurationSequencer(ConfigurationDatabase& database); 16 17 ConfigurationSequencer(const ConfigurationSequencer&) = delete; 18 ConfigurationSequencer& operator=(const ConfigurationSequencer&) = delete; 19 20 ConfigurationSequencer(ConfigurationSequencer&&) = delete; 21 ConfigurationSequencer& operator=(ConfigurationSequencer&&) = delete; 22 23 ~ConfigurationSequencer(); 24 25 // Enters the current sequencer into the queue of operations. 26 // Returns true to indicate that this operation has been queued and must wait. 27 // Returns false to indicate that this operation is able to proceed (queued directly to the front). 28 bool Enqueue(const Configuration::ConfigurationSet& configurationSet); 29 30 // Waits for this operation to reach the front of the queue. 31 // Registers a cancellation callback so that we can halt our waiting. 32 void Wait(AppInstaller::WinRT::AsyncCancellation& cancellation); 33 34 private: 35 // Determines the effective queue position of this operation; removing queue entries that are not longer active. 36 // 0 is the front of the queue. 37 size_t GetQueuePosition(); 38 39 using QueueObjectType = wil::unique_event; 40 41 ConfigurationDatabase& m_database; 42 guid m_setInstanceIdentifier{}; 43 std::string m_queueItemObjectName; 44 QueueObjectType m_queueItemObject; 45 wil::unique_mutex m_applyMutex; 46 wil::mutex_release_scope_exit m_applyMutexScope; 47 }; 48 }