int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out) { int ret = INVALID_JOB_ID; ThreadPoolJob *temp = NULL; ListNode *tempNode = NULL; ThreadPoolJob dummy; if (!tp) return EINVAL; if (!out) out = &dummy; dummy.jobId = jobId; ithread_mutex_lock(&tp->mutex); tempNode = ListFind(&tp->highJobQ, NULL, &dummy); if (tempNode) { temp = (ThreadPoolJob *)tempNode->item; *out = *temp; ListDelNode(&tp->highJobQ, tempNode, 0); FreeThreadPoolJob(tp, temp); ret = 0; goto exit_function; } tempNode = ListFind(&tp->medJobQ, NULL, &dummy); if (tempNode) { temp = (ThreadPoolJob *)tempNode->item; *out = *temp; ListDelNode(&tp->medJobQ, tempNode, 0); FreeThreadPoolJob(tp, temp); ret = 0; goto exit_function; } tempNode = ListFind(&tp->lowJobQ, NULL, &dummy); if (tempNode) { temp = (ThreadPoolJob *)tempNode->item; *out = *temp; ListDelNode(&tp->lowJobQ, tempNode, 0); FreeThreadPoolJob(tp, temp); ret = 0; goto exit_function; } if (tp->persistentJob && tp->persistentJob->jobId == jobId) { *out = *tp->persistentJob; FreeThreadPoolJob(tp, tp->persistentJob); tp->persistentJob = NULL; ret = 0; goto exit_function; } exit_function: ithread_mutex_unlock(&tp->mutex); return ret; }
void loadSuiteSetup(ListNode_t *test_suites_list_headp, char *line,ut_configuration_t *configp) { test_suite_t *trp; trp = dlsym(configp->dynlibraryp, line); ListNode_t * listp = ListFind(test_suites_list_headp,isSuite, (char *)trp->suite_name); if (NULL == listp) { return; } test_suite_element_t *sp= NODE_TO_ENTRY(test_suite_element_t,link,listp); memcpy(&sp->setup, trp, sizeof(test_suite_t)); }
static void addTestToSuites(test_element_t *e,ListNode_t * test_suites_list_headp) { ListNode_t * listp = ListFind(test_suites_list_headp,isSuite, (char *)e->test.suite_name); if (NULL == listp) { test_suite_element_t *sp = create_test_suite_element( (char *)e->test.suite_name); ListAddEnd(test_suites_list_headp, &sp->link); listp = &sp->link; } test_suite_element_t *sp= NODE_TO_ENTRY(test_suite_element_t,link,listp); ListAddEnd(&sp->test_list_head, &e->link); }
EStatus StationSendAck(Station* pThis, const Packet* pPacket) { Packet* pAck; ListEntry* pEntry; if (!StationIsAckRequired(pThis, pPacket)) return eSTATUS_COMMON_OK; NCHECK(ListFind(pThis->pOutbox, &pEntry, (ItemComparator)&StationAckFinder, (void*)pPacket, pThis)); CHECK(PacketNewAck(&pAck, pThis->id, pPacket->header.transitSrcId)); pAck->header.sequenceNum = pPacket->header.sequenceNum; return StationSendPacket(pThis, pAck); }
static mocked_function_t * findMockedFunction(void * addr()) { ListNode_t * foundp; if (0 ==lg_initialized) { initialize_mock_api(); } foundp =ListFind(&lg_mocked_functions_list,isMatchMockedFunction ,addr); if (NULL == foundp) return NULL; return NODE_TO_ENTRY(mocked_function_t,node, foundp); }
/*deleate AddressList*/ void DelNode(LinkList head) { ListNode *p ,*q; p=ListFind(head); if(p==NULL){ printf("No such record\n"); return; } q=head; while(q && q->next!=p) q=q->next; q->next=p->next; free(p); printf("record has been deleated\n"); }
/*------------------------------------------------------------------ * find entry in hash table *------------------------------------------------------------------*/ void *HashFind( Hash *hash, void *pItem ) { int h; if (!hash) return NULL; h = hash->hashFunc(pItem,hash->buckets); if ((h < 0) || (h >= hash->buckets)) return NULL; return ListFind(hash->bucket[h],pItem); }
uint8_t fhssCentralizedBlacklistChan(Node_t *parent, List *blacklist, uint64_t asn) { uint8_t freq = 0; for (ListElem *elem = ListFirst(&parent->channels); elem != NULL; elem = ListNext(&parent->channels, elem)) { uint8_t freq_offset = (uint8_t)elem->obj; freq = fhssOpenwsnChan(freq_offset, asn); if (!ListFind(blacklist, (void *)freq)) { break; } } return (freq); }
int main() { List *l = ListCreate(); int code; int index; double item; instructions(); while ((code = getchar()) != EOF) { switch (code) { case 'p': ListPrint(l); break; case 'a': //printf("add: "); if (scanf("%d %lf", &index, &item) == 2) { ListInsert(l, index, item); } else { printf("Input error\n"); } break; case 'd': if (scanf("%lf", &item) == 1) { Node *item_ptr = ListFind(l, item); if (item_ptr) { ListDeleteNode(l, item_ptr); } else { printf("Incorrect index\n"); } } else { printf("Input error\n"); } break; case 'q': ListDestroy(&l); return 0; case 'e': ListExchange(l); break; } } ListDestroy(&l); return 0; }
void main() { for(;;){ switch(menu_select()){ case 1: printf("create AddressList LinkedList\n"); head=CreateList(); break; case 2: printf("insert AddressList LinkedList\n"); p=(ListNode *)malloc(sizeof(ListNode)); scanf("%s%s%s%s%s",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr); InsertNode(head,p); break; case 3: printf("query AddressList LinkedList\n"); p=ListFind(head); if(p!=NULL){ printf("%s,%s,%s,%s,%s\n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr); } else printf("not found this record\n"); break; case 4: printf("deleate AddressList LinkedList\n"); DelNode(head); break; case 5: printf("output AddressList LinkedList\n"); PrintList(head); break; case 0: printf("goodbye!\n"); return; defalut: printf("Input error,try again!\n"); return; } } }
bool main_modesa(List *nodesList, List *linksList, Tree_t *tree, uint8_t sink_id, uint8_t sink_interfaces, \ bool intMatrix[][MAX_NODES][NUM_CHANNELS], bool confMatrix[][MAX_NODES][NUM_CHANNELS], int8_t channel) { uint16_t n_nodes = 0; /* Number of nodes in the network */ n_nodes = ListLength(nodesList); /* Parameter iu, number of radio interfaces */ uint8_t availableInterfaces[n_nodes]; /* Set the number of interface in the sink node */ Node_t *sink_node = getNode(sink_id, nodesList); sink_node->interfaces = sink_interfaces; /* Current time slot */ uint16_t t = 0; /* In Modesa we use the parameter q of a node to keep track of how many packets the nodes * currently stores in its buffer */ while (totalTraffic(nodesList) != 0) { /* Update priority of nodes and initialize the number of available interfaces */ for (ListElem *elem = ListFirst(nodesList); elem != NULL; elem = ListNext(nodesList, elem)) { /* Get the current node */ Node_t *node = (Node_t *)elem->obj; /* Update the priority */ node->priority = node->q * calculateParentRcv(node, tree); /* Initialize the number of interfaces */ availableInterfaces[node->id] = node->interfaces; } /* Create an array of lists with conflicting nodes on channel c */ List conflictLists[NUM_CHANNELS]; for (uint8_t i = 0; i < NUM_CHANNELS; i++) { memset(&conflictLists[i], 0, sizeof(List)); ListInit(&conflictLists[i]); } /* Create N, the list of nodes having data to transmit and sorted according to their priorities */ List N; memset(&N, 0, sizeof(List)); ListInit(&N); createListNodeWithData(nodesList, &N); /* While N != 0 */ while(ListLength(&N)) { bool tx = false; bool nChannelReached = false; Node_t *selectedNode = NULL; Node_t *selectedParent = NULL; /* Remove nodes from N until we get a node with available interface and whose parent also has an interface */ do { ListElem *elem = ListFirst(&N); if (elem == NULL) { selectedNode = NULL; break; } else { selectedNode = (Node_t *)elem->obj; } ListUnlink(&N, elem); selectedParent = getParent(tree, selectedNode); } while (availableInterfaces[selectedNode->id] == 0 || availableInterfaces[selectedParent->id] == 0); if (selectedNode == NULL) { break; } uint8_t c = 0; /* Try to schedule until TX or nChannelReached */ do { /* If selectedNode is not in the conflict list of channel c */ if (!ListFind(&conflictLists[c], (void *)selectedNode)) { /* Node selectedNode transmits in slot t on channel c */ TimeSlot_t *ts = newTimeSlot(t+1, c, TS_TX, selectedParent, false); ListAppend(&selectedNode->timeslots, (void *)ts); ts = newTimeSlot(t+1, c, TS_RX, selectedNode, false); ListAppend(&selectedParent->timeslots, (void *)ts); /* Update the current traffic queue */ selectedNode->q--; if (selectedParent->id != sink_id) { selectedParent->q++; } /* Update the number of available interfaces */ availableInterfaces[selectedNode->id]--; availableInterfaces[selectedParent->id]--; /* Update the list of conflicting nodes on channel c */ ListAppend(&conflictLists[c], (void *)selectedNode); for (uint8_t i = 0; i < n_nodes; i++) { if (confMatrix[selectedNode->id][i][channel] == true) { Node_t *confNode = getNode(i, nodesList); if (!ListFind(&conflictLists[c], (void *)confNode)) { ListAppend(&conflictLists[c], (void *)confNode); } } } tx = true; } else { if (c < NUM_CHANNELS) { /* Next channel */ c++; } else { /* No more available channels */ nChannelReached = true; } } } while (!tx && !nChannelReached); } /* t = t + 1 */ t++; } return (true); }
int main(int argc, char** argv) { BinaryStr val; int i=0; ListNode* node,*end; if (argc <2) { printf("Usage : %s <existing list filename or new filename to store disk list> \n",argv[0]); return -1; } DiskList* dList = ListInit(argv[1]); printf("DiskList %p\n",dList); assert(dList); //Adding to the end while(1){ int opt; printf("<list: choose operation [1-4] 4 for help~>"); scanf("%d",&opt); if (opt > 7) { printf("Invalid option.\n"); opt = 4; } if (opt == 4) { printf("1 --> to add an element.\n"); printf("2 --> to remove an element.\n"); printf("3 --> to print list\n"); printf("4 --> to print this help message\n"); printf("5 --> Start transaction .\n"); printf("6 --> Commit transaction.\n"); printf("7 --> Abort transaction.\n"); continue; } if (opt == 1) { int fVal,val; BinaryStr s; BlockMgrDiskPtr ptr; printf("Enter element to add after, enter non-existing element to add to end of the list.\n"); printf(":~"); scanf("%d",&fVal); printf("Enter value to add.\n"); printf(":~"); scanf("%d",&val); s.data = (char*)&fVal; s.len = sizeof(fVal); if (ListFind(dList,s,&ptr)) { ptr = GetLast(dList); } assert((node = ListLoadNode(dList,ptr))); s.data = (char*) &val; s.len = sizeof(val); ListAddAfter(dList,node,s); } if (opt ==3) { ListPrint(dList); printf("\n"); } if (opt == 2) { int fVal,val; BinaryStr s; BlockMgrDiskPtr ptr; printf("Enter value to remove.\n"); printf(":~"); scanf("%d",&val); s.data = (char*)&val; s.len = sizeof(val); if (ListFind(dList,s,&ptr)) { printf("Value %d does not exists in the list.\n",val); continue; } assert((node = ListLoadNode(dList,ptr))); s.data =(char*) &val; s.len = sizeof(val); ListRemove(dList,node); } if (opt == 5) { printf("Starting transaction.\n"); BlockMgrTransactStart(dList->handle); } if (opt == 6) { printf("Committing transaction.\n"); BlockMgrTransactCommit(dList->handle); BlockMgrTransactReplay(dList->handle); } if (opt == 7) { printf("Aborting transaction.\n"); BlockMgrTransactAbort(dList->handle); } } return 0; }
void S_DeleteSource(AudioSource* source) { ListRemove(&S_sources, ListFind(&S_sources, source)); alDeleteSources(1, &source->sourceID); free(source); }
/**************************************************************************** * Function: ThreadPoolRemove * * Description: * Removes a job from the thread pool. * Can only remove jobs which are not * currently running. * Parameters: * tp - valid thread pool pointer * jobId - id of job * ThreadPoolJob *out - space for removed job. * Can be null if not needed. * * Returns: * 0 on success. INVALID_JOB_ID on failure. *****************************************************************************/ int ThreadPoolRemove( ThreadPool *tp, int jobId, ThreadPoolJob *out ) { ThreadPoolJob *temp = NULL; int ret = INVALID_JOB_ID; ListNode *tempNode = NULL; ThreadPoolJob dummy; assert( tp != NULL ); if( tp == NULL ) { return EINVAL; } if( out == NULL ) { out = &dummy; } dummy.jobId = jobId; ithread_mutex_lock( &tp->mutex ); tempNode = ListFind( &tp->highJobQ, NULL, &dummy ); if( tempNode ) { temp = (ThreadPoolJob *)tempNode->item; *out = *temp; ListDelNode( &tp->highJobQ, tempNode, 0 ); FreeThreadPoolJob( tp, temp ); ithread_mutex_unlock( &tp->mutex ); return 0; } tempNode = ListFind( &tp->medJobQ, NULL, &dummy ); if( tempNode ) { temp = (ThreadPoolJob *)tempNode->item; *out = *temp; ListDelNode( &tp->medJobQ, tempNode, 0 ); FreeThreadPoolJob( tp, temp ); ithread_mutex_unlock( &tp->mutex ); return 0; } tempNode = ListFind( &tp->lowJobQ, NULL, &dummy ); if( tempNode ) { temp = (ThreadPoolJob *)tempNode->item; *out = *temp; ListDelNode( &tp->lowJobQ, tempNode, 0 ); FreeThreadPoolJob( tp, temp ); ithread_mutex_unlock( &tp->mutex ); return 0; } if( tp->persistentJob && tp->persistentJob->jobId == jobId ) { *out = *tp->persistentJob; FreeThreadPoolJob( tp, tp->persistentJob ); tp->persistentJob = NULL; ithread_mutex_unlock( &tp->mutex ); return 0; } ithread_mutex_unlock( &tp->mutex ); return ret; }