static long initialize() { epicsThreadId tid; unsigned long cvtRecCnt = countCvtRecords(); if (!initConversionQ && cvtRecCnt > 0) { initConversionQ = epicsMessageQueueCreate((unsigned)cvtRecCnt, REINIT_MSG_SIZE); if (!initConversionQ) { nerrmsg("", "msgQCreate failed"); goto error; } tid = epicsThreadCreate("initCvt", epicsThreadPriorityLow, 20000, (EPICSTHREADFUNC)initConversionTask, 0); if (!tid) { nerrmsg("", "taskSpawn failed"); goto error; } } return 0; error: if (initConversionQ) epicsMessageQueueDestroy(initConversionQ); return -1; }
static long doCalc(acalcoutRecord *pcalc) { calcMessage msg; int doAsync = 0; if (aCalcoutRecordDebug >= 10) printf("acalcoutRecord(%s):doCalc\n", pcalc->name); if ( acalcGetNumElements(pcalc) > aCalcAsyncThreshold ) doAsync = 1; /* if required infrastructure doesn't yet exist, create it */ if (doAsync && acalcMsgQueue == NULL) { acalcMsgQueue = epicsMessageQueueCreate(MAX_MSG, MSG_SIZE); if (acalcMsgQueue==NULL) { printf("aCalcoutRecord: Unable to create message queue\n"); return(-1); } acalcThreadId = epicsThreadCreate("acalcPerformTask", PRIORITY, epicsThreadGetStackSize(epicsThreadStackBig), (EPICSTHREADFUNC)acalcPerformTask, (void *)epicsThreadGetIdSelf()); if (acalcThreadId == NULL) { printf("aCalcoutRecord: Unable to create acalcPerformTask\n"); epicsMessageQueueDestroy(acalcMsgQueue); acalcMsgQueue = NULL; return(-1); } } /* Ideally, we should do short calculations in this thread, and queue long calculations. * But aCalcPerform is not reentrant (global value stack), so for now we queue everything. */ if (doAsync) { if (aCalcoutRecordDebug >= 2) printf("acalcoutRecord(%s):doCalc async\n", pcalc->name); pcalc->cact = 1; /* Tell caller that we went asynchronous */ msg.pcalc = pcalc; epicsMessageQueueSend(acalcMsgQueue, (void *)&msg, MSG_SIZE); return(0); } else { if (aCalcoutRecordDebug >= 2) printf("acalcoutRecord(%s):doCalc sync\n", pcalc->name); call_aCalcPerform(pcalc); } return(0); }