Blame view

src/threadcontext.cpp 576 Bytes
25b0d2f8   Peter M. Groen   Setting up Loggin...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include "threadcontext.h"
  
  // std
  #include <thread>
  
  using namespace osdev::components::mqtt;
  
  ThreadContextScope::ThreadContextScope( const std::string &_context )
      : m_previousContext( ThreadContext::instance().context() )
  {
      ThreadContext::instance().setContext( _context );
  }
  
  ThreadContextScope::~ThreadContextScope()
  {
      ThreadContext::instance().setContext( m_previousContext );
  }
  
  // static
  ThreadContext& ThreadContext::instance()
  {
      static thread_local ThreadContext tc;
      return tc;
  }
  
  ThreadContext::ThreadContext()
      : m_context( "default" )
  {
  
  }