Skip to content

Commit

Permalink
Document ThreadSpecificData methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-webb committed Jul 23, 2024
1 parent 86a6661 commit 62adcb4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
10 changes: 0 additions & 10 deletions src/main/cpp/threadspecificdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ MDC::Map& ThreadSpecificData::getMap()
return m_priv->mdcMap;
}

LogString& ThreadSpecificData::getThreadIdString()
{
return getCurrentData()->m_priv->pNamePair->idString;
}

LogString& ThreadSpecificData::getThreadName()
{
return getCurrentData()->m_priv->pNamePair->threadName;
}

auto ThreadSpecificData::getNames() -> NamePairPtr
{
return getCurrentData()->m_priv->pNamePair;
Expand Down
31 changes: 27 additions & 4 deletions src/main/include/log4cxx/helpers/threadspecificdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,57 @@ class LOG4CXX_EXPORT ThreadSpecificData
* @return a pointer that is never null.
*/
static ThreadSpecificData* getCurrentData();

/**
* Release this ThreadSpecficData if empty.
* Remove current thread data from APR if the diagnostic context is empty.
*/
void recycle();

/**
* Add the \c key \c val pair to the mapped diagnostic context of the current thread
*/
static void put(const LogString& key, const LogString& val);

/**
* Add \c val to the nested diagnostic context of the current thread
*/
static void push(const LogString& val);

/**
* Use \c stack as the nested diagnostic context of the current thread
*/
static void inherit(const NDC::Stack& stack);

/**
* The nested diagnostic context of the current thread
*/
NDC::Stack& getStack();

/**
* The mapped diagnostic context of the current thread
*/
MDC::Map& getMap();

/**
* A character outpur stream only assessable to the current thread
*/
template <typename T>
static std::basic_ostringstream<T>& getStringStream()
{
return getStream(T());
}
static LogString& getThreadIdString();
static LogString& getThreadName();

/**
* The names assigned to the current thread
*/
struct NamePair
{
LogString idString;
LogString threadName;
};
using NamePairPtr = std::shared_ptr<NamePair>;
/**
* A reference counted pointer to thread specific strings.
* A reference counted pointer to the names of the current thread.
*
* String references will remain valid
* for the lifetime of this pointer (i.e. even after thread termination).
Expand Down

0 comments on commit 62adcb4

Please sign in to comment.