Add commandline utility to resize buffer after being initialised
This commit is contained in:
1 parent
6b80b0cfb9
commit
a03d1fbe45
3 files changed
+55
No files matched your search
@@ -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 */
|
||||
@@ -548,6 +549,7 @@ static void errlogInitPvt(void *arg)
|
||||
*/
|
||||
|
||||
pvt.errlogInitFailed = TRUE;
|
||||
pvt.bufSizeLock = epicsMutexCreate();
|
||||
pvt.bufSize = pconfig->bufsize;
|
||||
pvt.maxMsgSize = pconfig->maxMsgSize;
|
||||
ellInit(&pvt.listenerList);
|
||||
@@ -566,6 +568,7 @@ static void errlogInitPvt(void *arg)
|
||||
errSymBld(); /* Better not to do this lazily... */
|
||||
|
||||
if(pvt.waitForWork
|
||||
&& pvt.bufSizeLock
|
||||
&& pvt.listenerLock
|
||||
&& pvt.msgQueueLock
|
||||
&& pvt.waitForSeq
|
||||
@@ -612,6 +615,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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -290,6 +290,22 @@ static void errlogInit2CallFunc(const iocshArgBuf *args)
|
||||
errlogInit2(args[0].ival, args[1].ival);
|
||||
}
|
||||
|
||||
/* errlogBufResize */
|
||||
static const iocshArg errlogBufResizeArg0 = { "bufSize",iocshArgInt};
|
||||
static const iocshArg errlogBufResizeArg1 = { "maxMsgSize",iocshArgInt};
|
||||
static const iocshArg * const errlogBufResizeArgs[] =
|
||||
{&errlogBufResizeArg0, &errlogBufResizeArg1};
|
||||
static const iocshFuncDef errlogBufResizeFuncDef = {
|
||||
"errlogBufResize", 2, errlogBufResizeArgs,
|
||||
"Reinitialize error log client buffer size and maximum message size\n"
|
||||
" bufSize - size of circular buffer (default = 1280 bytes)\n"
|
||||
" maxMsgSize - maximum size of error message (default = 256 bytes)\n"
|
||||
};
|
||||
static void errlogBufResizeCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
errlogBufResize(args[0].ival, args[1].ival);
|
||||
}
|
||||
|
||||
/* errlog */
|
||||
IOCSH_STATIC_FUNC void errlog(const char *message)
|
||||
{
|
||||
@@ -500,6 +516,7 @@ void epicsStdCall libComRegister(void)
|
||||
iocshRegister(&eltcFuncDef, eltcCallFunc);
|
||||
iocshRegister(&errlogInitFuncDef,errlogInitCallFunc);
|
||||
iocshRegister(&errlogInit2FuncDef,errlogInit2CallFunc);
|
||||
iocshRegister(&errlogBufResizeFuncDef,errlogBufResizeCallFunc);
|
||||
iocshRegister(&errlogFuncDef, errlogCallFunc);
|
||||
iocshRegister(&iocLogPrefixFuncDef, iocLogPrefixCallFunc);
|
||||
|
||||
|
||||
Reference in new issue
Block a user