/* * devCombineAdjacentBlocks() */ static long devCombineAdjacentBlocks( ELLLIST *pRangeList, rangeItem *pRange) { rangeItem *pBefore; rangeItem *pAfter; pBefore = (rangeItem *) ellPrevious (&pRange->node); pAfter = (rangeItem *) ellNext (&pRange->node); /* * combine adjacent blocks */ if (pBefore) { if (pBefore->end == pRange->begin-1) { epicsMutexMustLock(addrListLock); pRange->begin = pBefore->begin; ellDelete (pRangeList, &pBefore->node); epicsMutexUnlock(addrListLock); free ((void *)pBefore); } } if (pAfter) { if (pAfter->begin == pRange->end+1) { epicsMutexMustLock(addrListLock); pRange->end = pAfter->end; ellDelete (pRangeList, &pAfter->node); epicsMutexUnlock(addrListLock); free((void *)pAfter); } } return SUCCESS; }
epicsShareFunc int epicsShareAPI errlogRemoveListeners( errlogListener listener, void *pPrivate) { listenerNode *plistenerNode; int count = 0; errlogInit(0); if (!pvtData.atExit) epicsMutexMustLock(pvtData.listenerLock); plistenerNode = (listenerNode *)ellFirst(&pvtData.listenerList); while (plistenerNode) { listenerNode *pnext = (listenerNode *)ellNext(&plistenerNode->node); if (plistenerNode->listener == listener && plistenerNode->pPrivate == pPrivate) { ellDelete(&pvtData.listenerList, &plistenerNode->node); free(plistenerNode); ++count; } plistenerNode = pnext; } if (!pvtData.atExit) epicsMutexUnlock(pvtData.listenerLock); if (count == 0) { fprintf(pvtData.console, "errlogRemoveListeners: No listeners found\n"); } return count; }
void epicsShareAPI gphFreeMem(gphPvt *pgphPvt) { ELLLIST **paplist; int h; /* Caller must ensure that no other thread is using *pvt */ if (pgphPvt == NULL) return; paplist = pgphPvt->paplist; for (h = 0; h < pgphPvt->size; h++) { ELLLIST *plist = paplist[h]; GPHENTRY *pgphNode; GPHENTRY *next; if (plist == NULL) continue; pgphNode = (GPHENTRY *) ellFirst(plist); while (pgphNode) { next = (GPHENTRY *) ellNext((ELLNODE*)pgphNode); ellDelete(plist, (ELLNODE*)pgphNode); free(pgphNode); pgphNode = next; } free(paplist[h]); } epicsMutexDestroy(pgphPvt->lock); free(paplist); free(pgphPvt); }
int drvM6802_set_DAQstop(drvM6802_taskConfig *ptaskConfig) { drvBufferConfig_Node *pbufferNode = NULL; bufferingThreadQueueData queueData; drvM6802_controlThreadConfig *pfpdpThreadConfig = (drvM6802_controlThreadConfig*) ptaskConfig->pfpdpThreadConfig; if ( !ozSetADsFIFOreset( ptaskConfig) ) { epicsPrintf("\n>>> ozStopADC : ozSetADsFIFOreset...failed! \n"); return ERROR; } /* epicsThreadSleep(0.1); */ ozSetTriggerReset(ptaskConfig); if( stopFpdp() != OK ) printf(" can't stop FPDP \n"); /* epicsThreadSleep(0.1); */ pbufferNode = (drvBufferConfig_Node *)ellFirst(pdrvBufferConfig->pbufferList); ellDelete(pdrvBufferConfig->pbufferList, &pbufferNode->node); pbufferNode->nCnt = ptaskConfig->cnt_DMAcallback; pbufferNode->nStop = 1; printf("\nFPDP >>> DMA done count= %d\n", ptaskConfig->cnt_DMAcallback); epicsPrintf("DAQStop after :ellCnt %d \n", ellCount(pdrvBufferConfig->pbufferList) ); queueData.pNode = pbufferNode; epicsMessageQueueSend(pfpdpThreadConfig->threadQueueId, (void*) &queueData, sizeof(bufferingThreadQueueData)); /* epicsPrintf("\n>>>Last snd ID: %d, DMA cnt: %d\n", (int)pfpdpThreadConfig->threadQueueId, pbufferNode->nCnt); */ return OK; }
void epicsJobDestroy(epicsJob *job) { epicsThreadPool *pool; if (!job || !job->pool) { free(job); return; } pool = job->pool; epicsMutexMustLock(pool->guard); assert(!job->dead); epicsJobUnqueue(job); if (job->running || job->freewhendone) { job->freewhendone = 1; } else { ellDelete(&pool->owned, &job->jobnode); job->dead = 1; free(job); } epicsMutexUnlock(pool->guard); }
static void notifyInit(processNotify *ppn) { notifyPvt *pnotifyPvt; pnotifyPvt = (notifyPvt *) ellFirst(&pnotifyGlobal->freeList); if (pnotifyPvt) { ellDelete(&pnotifyGlobal->freeList, &pnotifyPvt->node); } else { pnotifyPvt = dbCalloc(1,sizeof(notifyPvt)); pnotifyPvt->cancelEvent = epicsEventCreate(epicsEventEmpty); pnotifyPvt->userCallbackEvent = epicsEventCreate(epicsEventEmpty); pnotifyPvt->magic = MAGIC; pnotifyPvt->state = notifyNotActive; } pnotifyPvt->state = notifyNotActive; callbackSetCallback(notifyCallback,&pnotifyPvt->callback); callbackSetUser(ppn,&pnotifyPvt->callback); callbackSetPriority(priorityLow,&pnotifyPvt->callback); ellInit(&pnotifyPvt->waitList); ppn->status = notifyOK; ppn->wasProcessed = 0; pnotifyPvt->state = notifyNotActive; pnotifyPvt->cancelWait = pnotifyPvt->userCallbackWait = 0; ppn->pnotifyPvt = pnotifyPvt; }
int epicsJobMove(epicsJob *job, epicsThreadPool *newpool) { epicsThreadPool *pool = job->pool; /* remove from current pool */ if (pool) { epicsMutexMustLock(pool->guard); if (job->queued || job->running) { epicsMutexUnlock(pool->guard); return S_pool_jobBusy; } ellDelete(&pool->owned, &job->jobnode); epicsMutexUnlock(pool->guard); } pool = job->pool = newpool; /* add to new pool */ if (pool) { epicsMutexMustLock(pool->guard); ellAdd(&pool->owned, &job->jobnode); epicsMutexUnlock(pool->guard); } return 0; }
void epicsShareAPI gphDelete(gphPvt *pgphPvt, const char *name, void *pvtid) { ELLLIST **paplist; ELLLIST *plist = NULL; GPHENTRY *pgphNode; int hash; if (pgphPvt == NULL) return; paplist = pgphPvt->paplist; hash = epicsMemHash((char *)&pvtid, sizeof(void *), 0); hash = epicsStrHash(name, hash) & pgphPvt->mask; epicsMutexMustLock(pgphPvt->lock); if (paplist[hash] == NULL) { pgphNode = NULL; } else { plist = paplist[hash]; pgphNode = (GPHENTRY *) ellFirst(plist); } while(pgphNode) { if (pvtid == pgphNode->pvtid && strcmp(name, pgphNode->name) == 0) { ellDelete(plist, (ELLNODE*)pgphNode); free((void *)pgphNode); break; } pgphNode = (GPHENTRY *) ellNext((ELLNODE*)pgphNode); } epicsMutexUnlock(pgphPvt->lock); return; }
int epicsJobUnqueue(epicsJob *job) { int ret = S_pool_jobIdle; epicsThreadPool *pool = job->pool; if (!pool) return S_pool_noPool; epicsMutexMustLock(pool->guard); assert(!job->dead); if (job->queued) { if (!job->running) { ellDelete(&pool->jobs, &job->jobnode); ellAdd(&pool->owned, &job->jobnode); } job->queued = 0; ret = 0; } epicsMutexUnlock(pool->guard); return ret; }
static int linuxDevPCIDisconnectInterrupt( const epicsPCIDevice *dev, void (*pFunction)(void *), void *parameter ) { int ret=S_dev_intDisconnect; ELLNODE *cur; osdISR *isr; osdPCIDevice *osd=CONTAINER((epicsPCIDevice*)dev,osdPCIDevice,dev); epicsMutexMustLock(osd->devLock); for(cur=ellFirst(&osd->isrs); cur; cur=ellNext(cur)) { isr=CONTAINER(cur,osdISR,node); if (pFunction==isr->fptr && parameter==isr->param) { stopIsrThread(isr); ellDelete(&osd->isrs,cur); epicsEventDestroy(isr->done); free(isr); ret=0; break; } } epicsMutexUnlock(osd->devLock); return ret; }
void taskwdAnyRemove(void *key) { struct mNode *pm; struct aNode *pa; taskwdInit(); epicsMutexMustLock(mLock); pm = (struct mNode *)ellFirst(&mList); while (pm) { if (pm->funcs == &anyFuncs) { pa = (struct aNode *)pm->usr; if (pa->key == key) { ellDelete(&mList, (void *)pm); freeNode((union twdNode *)pa); freeNode((union twdNode *)pm); epicsMutexUnlock(mLock); return; } } pm = (struct mNode *)ellNext(&pm->node); } epicsMutexUnlock(mLock); errlogPrintf("taskwdAnyRemove: Unregistered key %p\n", key); }
static void deleteFromList(struct dbCommon *precord, scan_list *psl) { scan_element *pse; epicsMutexMustLock(psl->lock); pse = precord->spvt; if (pse == NULL) { epicsMutexUnlock(psl->lock); errlogPrintf("dbScan: Tried to delete record from wrong scan list!\n" "\t%s.SPVT = NULL, but psl = %p\n", precord->name, (void *)psl); return; } if (pse->pscan_list != psl) { epicsMutexUnlock(psl->lock); errlogPrintf("dbScan: Tried to delete record from wrong scan list!\n" "\t%s.SPVT->pscan_list = %p but psl = %p\n", precord->name, (void *)pse, (void *)psl); return; } pse->pscan_list = NULL; ellDelete(&psl->list, (void *)pse); psl->modified = TRUE; epicsMutexUnlock(psl->lock); }
static void epicsExitCallAtExitsPvt(exitPvt *pep) { exitNode *pexitNode; while ( ( pexitNode = (exitNode *) ellLast ( & pep->list ) ) ) { pexitNode->func ( pexitNode->arg ); ellDelete ( & pep->list, & pexitNode->node ); free ( pexitNode ); } }
void freePattern(subInfo *psubInfo) { patternNode *ppatternNode; while((ppatternNode = (patternNode *)ellFirst(&psubInfo->patternList))) { ellDelete(&psubInfo->patternList,&ppatternNode->node); free(ppatternNode->var); free(ppatternNode); } psubInfo->isPattern = 0; }
static void *popFirstTemp(void) { tempListNode *ptempListNode; void *ptemp; ptempListNode = (tempListNode *)ellFirst(&tempList); ptemp = ptempListNode->item; ellDelete(&tempList,(ELLNODE *)ptempListNode); freeListFree(freeListPvt,ptempListNode); return(ptemp); }
static void inputCloseFile(inputData *pinputData) { inputFile *pinputFile; pinputFile = (inputFile *)ellFirst(&pinputData->inputFileList); if(!pinputFile) return; ellDelete(&pinputData->inputFileList,&pinputFile->node); if(fclose(pinputFile->fp)) fprintf(stderr,"fclose failed: file %s\n",pinputFile->filename); free(pinputFile->filename); free(pinputFile); }
/* * clean_addrq */ static void clean_addrq(void) { struct channel_in_use * pciu; struct channel_in_use * pnextciu; epicsTimeStamp current; double delay; double maxdelay = 0; unsigned ndelete=0; double timeout = TIMEOUT; int s; epicsTimeGetCurrent ( ¤t ); epicsMutexMustLock ( prsrv_cast_client->chanListLock ); pnextciu = (struct channel_in_use *) prsrv_cast_client->chanList.node.next; while( (pciu = pnextciu) ) { pnextciu = (struct channel_in_use *)pciu->node.next; delay = epicsTimeDiffInSeconds(¤t,&pciu->time_at_creation); if (delay > timeout) { ellDelete(&prsrv_cast_client->chanList, &pciu->node); LOCK_CLIENTQ; s = bucketRemoveItemUnsignedId ( pCaBucket, &pciu->sid); if(s){ errMessage (s, "Bad id at close"); } else { rsrvChannelCount--; } UNLOCK_CLIENTQ; if ( ! s ) { freeListFree(rsrvChanFreeList, pciu); ndelete++; } if(delay>maxdelay) maxdelay = delay; } } epicsMutexUnlock ( prsrv_cast_client->chanListLock ); # ifdef DEBUG if(ndelete){ epicsPrintf ("CAS: %d CA channels have expired after %f sec\n", ndelete, maxdelay); } # endif }
static void freeInputFileList(void) { inputFile *pinputFileNow; while((pinputFileNow=(inputFile *)ellFirst(&inputFileList))) { if(fclose(pinputFileNow->fp)) errPrintf(0,__FILE__, __LINE__, "Closing file %s",pinputFileNow->filename); free((void *)pinputFileNow->filename); ellDelete(&inputFileList,(ELLNODE *)pinputFileNow); free((void *)pinputFileNow); } }
static void msgbufFreeSend(void) { msgNode *pnextSend; epicsMutexMustLock(pvtData.msgQueueLock); pnextSend = (msgNode *)ellFirst(&pvtData.msgQueue); if (!pnextSend) { fprintf(pvtData.console, "errlog: msgbufFreeSend logic error\n"); epicsThreadSuspendSelf(); } ellDelete(&pvtData.msgQueue, &pnextSend->node); epicsMutexUnlock(pvtData.msgQueueLock); }
static void inputDestruct(void *pvt) { inputData *pinputData = (inputData *)pvt; pathNode *ppathNode; inputCloseAllFiles(pinputData); while((ppathNode = (pathNode *)ellFirst(&pinputData->pathList))) { ellDelete(&pinputData->pathList,&ppathNode->node); free((void *)ppathNode->directory); free((void *)ppathNode); } free(pvt); }
static void epicsExitCallAtExitsPvt(exitPvt *pep) { exitNode *pexitNode; while ( ( pexitNode = (exitNode *) ellLast ( & pep->list ) ) ) { if (atExitDebug && pexitNode->name[0]) fprintf(stderr, "atExit %s(%p)\n", pexitNode->name, pexitNode->arg); else if(atExitDebug) fprintf(stderr, "atExit %p(%p)\n", pexitNode->func, pexitNode->arg); pexitNode->func ( pexitNode->arg ); ellDelete ( & pep->list, & pexitNode->node ); free ( pexitNode ); } }
static void free_threadInfo(epicsThreadOSD *pthreadInfo) { int status; status = mutexLock(&listLock); checkStatusQuit(status,"pthread_mutex_lock","free_threadInfo"); if(pthreadInfo->isOnThreadList) ellDelete(&pthreadList,&pthreadInfo->node); status = pthread_mutex_unlock(&listLock); checkStatusQuit(status,"pthread_mutex_unlock","free_threadInfo"); epicsEventDestroy(pthreadInfo->suspendEvent); status = pthread_attr_destroy(&pthreadInfo->attr); checkStatusQuit(status,"pthread_attr_destroy","free_threadInfo"); free(pthreadInfo->name); free(pthreadInfo); }
/** Deletes all attributes from the list. */ int NDAttributeList::clear() { NDAttribute *pAttribute; NDAttributeListNode *pListNode; //const char *functionName = "NDAttributeList::clear"; epicsMutexLock(this->lock); pListNode = (NDAttributeListNode *)ellFirst(&this->list); while (pListNode) { pAttribute = pListNode->pNDAttribute; ellDelete(&this->list, &pListNode->node); delete pAttribute; pListNode = (NDAttributeListNode *)ellFirst(&this->list); } epicsMutexUnlock(this->lock); return(ND_SUCCESS); }
void bufRxManager::dataRxDeleteReceive(dataBufComplete fn,void* arg) { listener *l; SCOPED_LOCK(guard); for(ELLNODE *node=ellFirst(&dispatch); node; node=ellNext(node)) { l=CONTAINER(node, listener, node); if (l->fn==fn && l->fnarg==arg) { ellDelete(&dispatch, node); delete l; return; } } }
/** Removes an attribute from the list. * \param[in] pName The name of the attribute to be deleted. * \return Returns ND_SUCCESS if the attribute was found and deleted, ND_ERROR if the * attribute was not found. */ int NDAttributeList::remove(const char *pName) { NDAttribute *pAttribute; int status = ND_ERROR; //const char *functionName = "NDAttributeList::remove"; epicsMutexLock(this->lock); pAttribute = this->find(pName); if (!pAttribute) goto done; ellDelete(&this->list, &pAttribute->listNode.node); delete pAttribute; status = ND_SUCCESS; done: epicsMutexUnlock(this->lock); return(status); }
epicsShareFunc void epicsThreadPoolReleaseShared(epicsThreadPool *pool) { if (!pool) return; epicsMutexMustLock(sharedPoolsGuard); assert(pool->sharedCount > 0); pool->sharedCount--; if (pool->sharedCount == 0) { ellDelete(&sharedPools, &pool->sharedNode); epicsThreadPoolDestroy(pool); } epicsMutexUnlock(sharedPoolsGuard); }
static int db_yyinput(char *buf, int max_size) { int l,n; char *fgetsRtn; if(yyAbort) return(0); if(*my_buffer_ptr==0) { while(TRUE) { /*until we get some input*/ if(macHandle) { fgetsRtn = fgets(mac_input_buffer,MY_BUFFER_SIZE, pinputFileNow->fp); if(fgetsRtn) { n = macExpandString(macHandle,mac_input_buffer, my_buffer,MY_BUFFER_SIZE); if(n<0) { errPrintf(0,__FILE__, __LINE__, "macExpandString failed for file %s", pinputFileNow->filename); } } } else { fgetsRtn = fgets(my_buffer,MY_BUFFER_SIZE,pinputFileNow->fp); } if(fgetsRtn) break; if(fclose(pinputFileNow->fp)) errPrintf(0,__FILE__, __LINE__, "Closing file %s",pinputFileNow->filename); free((void *)pinputFileNow->filename); ellDelete(&inputFileList,(ELLNODE *)pinputFileNow); free((void *)pinputFileNow); pinputFileNow = (inputFile *)ellLast(&inputFileList); if(!pinputFileNow) return(0); } if(dbStaticDebug) fprintf(stderr,"%s",my_buffer); pinputFileNow->line_num++; my_buffer_ptr = &my_buffer[0]; } l = strlen(my_buffer_ptr); n = (l<=max_size ? l : max_size); memcpy(buf,my_buffer_ptr,n); my_buffer_ptr += n; return(n); }
static int linuxDevFinal(void) { ELLNODE *cur, *next, *isrcur, *isrnext; osdPCIDevice *curdev=NULL; osdISR *isr; epicsMutexMustLock(pciLock); for(cur=ellFirst(&devices), next=cur ? ellNext(cur) : NULL; cur; cur=next, next=next ? ellNext(next) : NULL ) { curdev=CONTAINER(cur,osdPCIDevice,node); epicsMutexMustLock(curdev->devLock); for(isrcur=ellFirst(&curdev->isrs), isrnext=isrcur ? ellNext(isrcur) : NULL; isrcur; isrcur=isrnext, isrnext=isrnext ? ellNext(isrnext) : NULL ) { isr=CONTAINER(isrcur,osdISR,node); stopIsrThread(isr); ellDelete(&curdev->isrs,cur); free(isr); } close_uio(curdev); epicsMutexUnlock(curdev->devLock); epicsMutexDestroy(curdev->devLock); free(curdev); } epicsMutexUnlock(pciLock); epicsMutexDestroy(pciLock); return 0; }
void taskwdRemove(epicsThreadId tid) { struct tNode *pt; struct mNode *pm; char tName[40]; taskwdInit(); if (tid == 0) tid = epicsThreadGetIdSelf(); epicsMutexMustLock(tLock); pt = (struct tNode *)ellFirst(&tList); while (pt != NULL) { if (tid == pt->tid) { ellDelete(&tList, (void *)pt); epicsMutexUnlock(tLock); freeNode((union twdNode *)pt); epicsMutexMustLock(mLock); pm = (struct mNode *)ellFirst(&mList); while (pm) { if (pm->funcs->remove) { pm->funcs->remove(pm->usr, tid); } pm = (struct mNode *)ellNext(&pm->node); } epicsMutexUnlock(mLock); return; } pt = (struct tNode *)ellNext(&pt->node); } epicsMutexUnlock(tLock); epicsThreadGetName(tid, tName, sizeof(tName)); errlogPrintf("taskwdRemove: Thread %s (%p) not registered!\n", tName, (void *)tid); }
void taskwdMonitorDel(const taskwdMonitor *funcs, void *usr) { struct mNode *pm; if (funcs == NULL) return; taskwdInit(); epicsMutexMustLock(mLock); pm = (struct mNode *)ellFirst(&mList); while (pm) { if (pm->funcs == funcs && pm->usr == usr) { ellDelete(&mList, (void *)pm); freeNode((union twdNode *)pm); epicsMutexUnlock(mLock); return; } pm = (struct mNode *)ellNext(&pm->node); } epicsMutexUnlock(mLock); errlogPrintf("taskwdMonitorDel: Unregistered!\n"); }