Add commandline utility to resize buffer after being initialised

This commit is contained in:
Simon Rose authored and Dirk Zimoch committed 2026-10-13 10:21:35 +02:00
1 parent 53a3e4b694
commit d3ff8dca3f
3 files changed
+55

No files matched your search

+29
View File
@@ -77,6 +77,7 @@ typedef struct {
} buffer_t;
static struct {
epicsMutexId bufSizeLock;
/* const after errlogInit() */
size_t maxMsgSize;
/* alloc size of both buffer_t::base */
@@ -570,6 +571,7 @@ static void errlogInitPvt(void *arg)
*/
pvt.errlogInitFailed = TRUE;
pvt.bufSizeLock = epicsMutexCreate();
pvt.bufSize = pconfig->bufsize;
pvt.maxMsgSize = pconfig->maxMsgSize;
ellInit(&pvt.listenerList);
@@ -594,6 +596,7 @@ static void errlogInitPvt(void *arg)
errSymBld(); /* Better not to do this lazily... */
if(pvt.waitForWork
&& pvt.bufSizeLock
&& pvt.listenerLock
&& pvt.msgQueueLock
&& pvt.waitForSeq
@@ -640,6 +643,32 @@ int errlogInit(int bufsize)
return errlogInit2(bufsize, DEFAULT_MAX_MSG_SIZE);
}
void errlogBufResize(int bufsize, int maxMsgSize)
{
if (bufsize < MIN_BUFFER_SIZE)
bufsize = MIN_BUFFER_SIZE;
if (maxMsgSize < MIN_MESSAGE_SIZE)
maxMsgSize = MIN_MESSAGE_SIZE;
else if (maxMsgSize > MAX_MESSAGE_SIZE)
maxMsgSize = MAX_MESSAGE_SIZE;
errlogFlush();
epicsMutexMustLock(pvt.bufSizeLock);
epicsMutexMustLock(pvt.msgQueueLock);
pvt.bufSize = bufsize;
pvt.maxMsgSize = maxMsgSize;
free(pvt.log->base);
pvt.log->base = callocMustSucceed(1, pvt.bufSize, "Failed to allocate memory for errorlog buffer");
free(pvt.print->base);
pvt.print->base = callocMustSucceed(1, pvt.bufSize, "Failed to allocate memory for errorlog buffer");
epicsMutexUnlock(pvt.msgQueueLock);
epicsMutexUnlock(pvt.bufSizeLock);
}
void errlogFlush(void)
{
/* wait for both buffers to be handled to know that all currently
+9
View File
@@ -224,6 +224,15 @@ LIBCOM_API int errlogInit(int bufsize);
*/
LIBCOM_API int errlogInit2(int bufsize, int maxMsgSize);
/**
* errlogBufResize can be used to reinitialize the error logging system with a larger buffer and maximum message size.
* The default buffer size is 1280 bytes, and the default maximum message size is 256.
*
* \param bufsize The desired buffer size
* \param maxMsgSize The desired max message size
*/
LIBCOM_API void errlogBufResize(int bufsize, int maxMsgSize);
/** Wakes up the errlog task and then waits until all messages are flushed from the queue. */
LIBCOM_API void errlogFlush(void);