winget-cli

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

ThreadGlobals.h (1374B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <AppInstallerLogging.h>
      5 #include <winget/SharedThreadGlobals.h>
      6 #include <AppInstallerTelemetry.h>
      7 #include <mutex>
      8 
      9 namespace AppInstaller::ThreadLocalStorage
     10 {
     11     struct WingetThreadGlobals : public ThreadGlobals
     12     {
     13         WingetThreadGlobals() = default;
     14         virtual ~WingetThreadGlobals() = default;
     15 
     16         // Request that a sub ThreadGlobals be constructed from the given parent.
     17         struct create_sub_thread_globals_t {};
     18         WingetThreadGlobals(WingetThreadGlobals& parent, create_sub_thread_globals_t);
     19 
     20         AppInstaller::Logging::DiagnosticLogger& GetDiagnosticLogger() override;
     21 
     22         void* GetTelemetryObject() override;
     23 
     24         AppInstaller::Logging::TelemetryTraceLogger& GetTelemetryLogger();
     25 
     26         // Set Globals for Current Thread
     27         // Return RAII object with its ownership to set the AppInstaller ThreadLocalStorage back to previous state
     28         std::unique_ptr<AppInstaller::ThreadLocalStorage::PreviousThreadGlobals> SetForCurrentThread() override;
     29 
     30     private:
     31 
     32         void Initialize();
     33 
     34         std::shared_ptr<AppInstaller::Logging::DiagnosticLogger> m_pDiagnosticLogger;
     35         std::unique_ptr<AppInstaller::Logging::TelemetryTraceLogger> m_pTelemetryLogger;
     36         std::once_flag m_loggerInitOnceFlag;
     37     };
     38 }