winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

SharedThreadGlobals.h (1203B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <AppInstallerLogging.h>
      5 
      6 namespace AppInstaller::ThreadLocalStorage
      7 {
      8     struct PreviousThreadGlobals;
      9 
     10     // Interface for access to values that are stored on a per-thread object.
     11     struct ThreadGlobals
     12     {
     13         ThreadGlobals() = default;
     14         virtual ~ThreadGlobals() = default;
     15 
     16         virtual AppInstaller::Logging::DiagnosticLogger& GetDiagnosticLogger() = 0;
     17 
     18         virtual void* GetTelemetryObject() = 0;
     19 
     20         // Set Globals for Current Thread
     21         // Return RAII object with its ownership to set the AppInstaller ThreadLocalStorage back to previous state
     22         virtual std::unique_ptr<AppInstaller::ThreadLocalStorage::PreviousThreadGlobals> SetForCurrentThread();
     23 
     24         // Return Globals for Current Thread
     25         static ThreadGlobals* GetForCurrentThread();
     26     };
     27 
     28     // RAII object used to enable reverting back to the previous thread globals object.
     29     struct PreviousThreadGlobals
     30     {
     31         ~PreviousThreadGlobals();
     32 
     33         PreviousThreadGlobals(ThreadGlobals* previous);
     34 
     35     private:
     36         ThreadGlobals* m_previous;
     37         DWORD m_threadId;
     38     };
     39 }