threadcontext.cpp 576 Bytes
#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" )
{

}