Block resizes from listener callbacks

This commit is contained in:
Simon Rose authored and Dirk Zimoch committed 2026-10-13 10:24:41 +02:00
1 parent 2bb445a992
commit ca424832a7
2 files changed
+12 -4

No files matched your search

+10 -4
View File
@@ -77,6 +77,7 @@ typedef struct {
} buffer_t;
static struct {
epicsThreadId tid;
epicsMutexId bufSizeLock;
/* guarded by bufSizeLock, allowing them to be resized after initialisation */
size_t maxMsgSize;
@@ -585,7 +586,6 @@ static void errlogInitPvt(void *arg)
{
struct initArgs *pconfig = (struct initArgs *) arg;
epicsThreadId tid = NULL;
epicsThreadOpts topts = EPICS_THREAD_OPTS_INIT;
topts.priority = epicsThreadPriorityLow;
@@ -596,6 +596,7 @@ static void errlogInitPvt(void *arg)
* cantProceed() calls us.
*/
pvt.tid = NULL;
pvt.errlogInitFailed = TRUE;
pvt.bufSizeLock = epicsMutexCreate();
pvt.bufSize = pconfig->bufsize;
@@ -629,11 +630,11 @@ static void errlogInitPvt(void *arg)
&& pvt.log->base
&& pvt.print->base
) {
tid = epicsThreadCreateOpt("errlog", (EPICSTHREADFUNC)errlogThread, 0, &topts);
pvt.tid = epicsThreadCreateOpt("errlog", (EPICSTHREADFUNC)errlogThread, 0, &topts);
}
if (tid) {
if (pvt.tid) {
pvt.errlogInitFailed = FALSE;
epicsAtExit(errlogExitHandler, tid);
epicsAtExit(errlogExitHandler, pvt.tid);
}
}
@@ -699,6 +700,11 @@ int errlogInit2(int bufsize, int maxMsgSize)
// Don't resize the buffer for any of the calls to errlogInit(0)
if (bufsize == 0) return 0;
if (epicsThreadGetIdSelf() == pvt.tid) {
fprintf(stderr, "Cannot resize buffer from callback function.\n");
return -1;
}
epicsMutexMustLock(pvt.bufSizeLock);
if (pvt.bufSize != config.bufsize || pvt.maxMsgSize != config.maxMsgSize) {
// We are resizing the buffer after initialisation
+2
View File
@@ -208,6 +208,7 @@ LIBCOM_API int errlogSetConsole(FILE *stream);
* Can be used to initialize the error logging system with a larger buffer. The default buffer size is 2560 bytes.
*
* \param bufsize The desired buffer size
* \return 0 if successful, -1 if called from callback function
*
* \since UNRELEASED the default buffer size is 2560.
*/
@@ -219,6 +220,7 @@ LIBCOM_API int errlogInit(int bufsize);
*
* \param bufsize The desired buffer size
* \param maxMsgSize The desired max message size
* \return 0 if successful, -1 if called from callback function
*
* \since UNRELEASED The default buffer size is 2560 and the default maximum message size is 512.
*/