You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2024/04/25 01:57:19 UTC
(logging-log4cxx) branch master updated: Keep mutex locked when changing the variable that change the condition (#371)
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new 691d6795 Keep mutex locked when changing the variable that change the condition (#371)
691d6795 is described below
commit 691d679568ad754d0362b85e8dce557a8a664b01
Author: Stephen Webb <st...@ieee.org>
AuthorDate: Thu Apr 25 11:57:13 2024 +1000
Keep mutex locked when changing the variable that change the condition (#371)
---
src/main/cpp/filewatchdog.cpp | 5 ++++-
src/main/cpp/socketappenderskeleton.cpp | 16 +++++++++-------
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/main/cpp/filewatchdog.cpp b/src/main/cpp/filewatchdog.cpp
index e51c5931..742423b5 100644
--- a/src/main/cpp/filewatchdog.cpp
+++ b/src/main/cpp/filewatchdog.cpp
@@ -73,7 +73,10 @@ bool FileWatchdog::is_active()
void FileWatchdog::stop()
{
LogLog::debug(LOG4CXX_STR("Stopping file watchdog"));
- m_priv->interrupted = 0xFFFF;
+ {
+ std::lock_guard<std::mutex> lock(m_priv->interrupt_mutex);
+ m_priv->interrupted = 0xFFFF;
+ }
m_priv->interrupt.notify_all();
m_priv->thread.join();
}
diff --git a/src/main/cpp/socketappenderskeleton.cpp b/src/main/cpp/socketappenderskeleton.cpp
index 76f1a423..a7e984a0 100644
--- a/src/main/cpp/socketappenderskeleton.cpp
+++ b/src/main/cpp/socketappenderskeleton.cpp
@@ -68,15 +68,17 @@ void SocketAppenderSkeleton::activateOptions(Pool& p)
void SocketAppenderSkeleton::close()
{
- std::lock_guard<std::recursive_mutex> lock(_priv->mutex);
-
- if (_priv->closed)
{
- return;
- }
+ std::lock_guard<std::mutex> lock(_priv->interrupt_mutex);
+
+ if (_priv->closed)
+ {
+ return;
+ }
- _priv->closed = true;
- cleanUp(_priv->pool);
+ _priv->closed = true;
+ cleanUp(_priv->pool);
+ }
_priv->interrupt.notify_all();
if ( _priv->thread.joinable() )
{