Skip to content

Commit 9edc74a

Browse files
authored
Prevent AsyncAppender buffer size change while active (#616)
1 parent 4f3ba2b commit 9edc74a

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/main/cpp/asyncappender.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ void AsyncAppender::setBufferSize(int size)
519519
}
520520

521521
std::lock_guard<std::mutex> lock(priv->bufferMutex);
522+
if (priv->dispatcher.joinable())
523+
{
524+
throw RuntimeException(LOG4CXX_STR("AsyncAppender buffer size cannot be changed now"));
525+
}
522526
priv->bufferSize = (size < 1) ? 1 : size;
523527
priv->buffer.resize(priv->bufferSize);
524528
priv->bufferNotFull.notify_all();

src/main/include/log4cxx/asyncappender.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ class LOG4CXX_EXPORT AsyncAppender :
204204
void setLocationInfo(bool flag);
205205

206206
/**
207-
* The <b>BufferSize</b> option takes a non-negative integer value.
208-
* This integer value determines the maximum size of the bounded
209-
* buffer.
207+
* Use \c newSize (a non-negative integer value) for
208+
* the number of [logging events](@ref spi::LoggingEvent) the ring buffer can hold.
209+
* The ring buffer size cannot be changed once the appender has received an event.
210210
* */
211-
void setBufferSize(int size);
211+
void setBufferSize(int newSize);
212212

213213
/**
214214
* Gets the current buffer size.
@@ -217,19 +217,19 @@ class LOG4CXX_EXPORT AsyncAppender :
217217
int getBufferSize() const;
218218

219219
/**
220-
* Sets whether appender should wait if there is no
221-
* space available in the event buffer or immediately return.
220+
* Use \c newValue for whether appender should block the calling thread
221+
* if there is no space in the ring buffer.
222222
*
223-
* @param value true if appender should wait until available space in buffer.
223+
* @param newValue true if appender should wait until space is available in the ring buffer.
224224
*/
225-
void setBlocking(bool value);
225+
void setBlocking(bool newValue);
226226

227227
/**
228-
* Gets whether appender should block calling thread when buffer is full.
228+
* Gets whether appender should block calling thread when ring buffer is full.
229229
* If false, messages will be counted by logger and a summary
230-
* message appended after the contents of the buffer have been appended.
230+
* message added after the buffered events have been appended.
231231
*
232-
* @return true if calling thread will be blocked when buffer is full.
232+
* @return true if calling thread will be blocked when ring buffer is full.
233233
*/
234234
bool getBlocking() const;
235235

0 commit comments

Comments
 (0)