Skip to content

Commit

Permalink
Ensure the dispatch thread has terminated before destroying the std::…
Browse files Browse the repository at this point in the history
…thread
  • Loading branch information
stephen-webb committed Jul 21, 2024
1 parent ecc8011 commit 7ffc743
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/main/cpp/asyncappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,21 @@ typedef std::map<LogString, DiscardSummary> DiscardMap;

struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkeletonPrivate
{
AsyncAppenderPriv() :
AppenderSkeletonPrivate(),
buffer(DEFAULT_BUFFER_SIZE),
bufferSize(DEFAULT_BUFFER_SIZE),
dispatcher(),
locationInfo(false),
blocking(true)
#if LOG4CXX_EVENTS_AT_EXIT
, atExitRegistryRaii([this]{stopDispatcher();})
#endif
AsyncAppenderPriv()
: AppenderSkeletonPrivate()
, buffer(DEFAULT_BUFFER_SIZE)
, bufferSize(DEFAULT_BUFFER_SIZE)
, dispatcher()
, locationInfo(false)
, blocking(true)
, eventCount(0)
, dispatchedCount(0)
, commitCount(0)
{ }

~AsyncAppenderPriv()
{
stopDispatcher();
}

/**
Expand Down Expand Up @@ -191,10 +192,6 @@ struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkele
*/
bool blocking;

#if LOG4CXX_EVENTS_AT_EXIT
helpers::AtExitRegistry::Raii atExitRegistryRaii;
#endif

/**
* Used to calculate the buffer position at which to store the next event.
*/
Expand Down
1 change: 0 additions & 1 deletion src/test/cpp/asyncappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
LOG4CXX_INFO(root, "Message");
auto& v = vectorAppender->getVector();
LOGUNIT_ASSERT(0 < v.size());
asyncAppender->close(); // Wait for dispatch thread to complete
}

/**
Expand Down

0 comments on commit 7ffc743

Please sign in to comment.