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/23 12:08:35 UTC
(logging-log4cxx) 01/01: Keep mutex locked when changing the variable that change the condition
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch prefer_lock_guard
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit eaddaa1e5b7f3ba40517479587977c475b3654b2
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Tue Apr 23 22:08:15 2024 +1000
Keep mutex locked when changing the variable that change the condition
---
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() )
{