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 9edc74a0 Prevent AsyncAppender buffer size change while active (#616)
9edc74a0 is described below

commit 9edc74a06cd9aa01d2c0c33b8c729d08f00067fa
Author: Stephen Webb <[email protected]>
AuthorDate: Tue Mar 31 09:34:51 2026 +1100

    Prevent AsyncAppender buffer size change while active (#616)
---
 src/main/cpp/asyncappender.cpp           |  4 ++++
 src/main/include/log4cxx/asyncappender.h | 22 +++++++++++-----------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/main/cpp/asyncappender.cpp b/src/main/cpp/asyncappender.cpp
index 3ba0dd01..9703d11e 100644
--- a/src/main/cpp/asyncappender.cpp
+++ b/src/main/cpp/asyncappender.cpp
@@ -519,6 +519,10 @@ void AsyncAppender::setBufferSize(int size)
        }
 
        std::lock_guard<std::mutex> lock(priv->bufferMutex);
+       if (priv->dispatcher.joinable())
+       {
+               throw RuntimeException(LOG4CXX_STR("AsyncAppender buffer size 
cannot be changed now"));
+       }
        priv->bufferSize = (size < 1) ? 1 : size;
        priv->buffer.resize(priv->bufferSize);
        priv->bufferNotFull.notify_all();
diff --git a/src/main/include/log4cxx/asyncappender.h 
b/src/main/include/log4cxx/asyncappender.h
index fe9ff01b..f00d89ba 100644
--- a/src/main/include/log4cxx/asyncappender.h
+++ b/src/main/include/log4cxx/asyncappender.h
@@ -204,11 +204,11 @@ class LOG4CXX_EXPORT AsyncAppender :
                void setLocationInfo(bool flag);
 
                /**
-               * The <b>BufferSize</b> option takes a non-negative integer 
value.
-               * This integer value determines the maximum size of the bounded
-               * buffer.
+               * Use \c newSize (a non-negative integer value) for
+               * the number of [logging events](@ref spi::LoggingEvent) the 
ring buffer can hold.
+               * The ring buffer size cannot be changed once the appender has 
received an event.
                * */
-               void setBufferSize(int size);
+               void setBufferSize(int newSize);
 
                /**
                 * Gets the current buffer size.
@@ -217,19 +217,19 @@ class LOG4CXX_EXPORT AsyncAppender :
                int getBufferSize() const;
 
                /**
-                * Sets whether appender should wait if there is no
-                * space available in the event buffer or immediately return.
+                * Use \c newValue for whether appender should block the 
calling thread
+                * if there is no space in the ring buffer.
                 *
-                * @param value true if appender should wait until available 
space in buffer.
+                * @param newValue true if appender should wait until space is 
available in the ring buffer.
                 */
-               void setBlocking(bool value);
+               void setBlocking(bool newValue);
 
                /**
-                * Gets whether appender should block calling thread when 
buffer is full.
+                * Gets whether appender should block calling thread when ring 
buffer is full.
                 * If false, messages will be counted by logger and a summary
-                * message appended after the contents of the buffer have been 
appended.
+                * message added after the buffered events have been appended.
                 *
-                * @return true if calling thread will be blocked when buffer 
is full.
+                * @return true if calling thread will be blocked when ring 
buffer is full.
                 */
                bool getBlocking() const;
 

Reply via email to