static Term multiply_l(Term t1,Term t2) { List l1,l2,ll; ll=NewList(); l1=t1; while(!is_empty_list(l1)) { l2=t2; while(!is_empty_list(l2)) { Term q1,q2; q1=CopyTerm(ListFirst(l1)); q2=CopyTerm(ListFirst(l2)); ll=AppendLast(ll,multiply(q1,q2)); l2=ListTail(l2); } l1=ListTail(l1); } FreeAtomic(t1); FreeAtomic(t2); return ll; }
void alg1_sum_wild(Term a1) { List ww,l1,rl; List free_w; free_w=NewList(); rl=NewList(); l1=CompoundArg2(a1); while(!is_empty_list(l1)) { Term t1; t1=ListFirst(l1); if(CompoundName(t1)==OPR_WILD) free_w=AppendFirst(free_w,CompoundArg2(t1)); l1=ListTail(l1); } l1=CompoundArg1(a1); while(!is_empty_list(l1)) { Term t1; t1=ListFirst(l1); ww=alg1_w_ind(t1,free_w); /*WriteTerm(free_w);WriteTerm(ww);fflush(stdout);*/ if(is_empty_list(ww)) { /*WriteTerm(t1); puts(": pure");*/ rl=AppendLast(rl,t1); } else rl=ConcatList(rl,alg1_s_w_m(t1,ww)); l1=ListTail(l1); } RemoveList(free_w); l1=ConsumeCompoundArg(a1,1); RemoveList(l1); SetCompoundArg(a1,1,rl); }
void createListNodeWithData(List *nodesList, List *N) { for (ListElem *elem1 = ListFirst(nodesList); elem1 != NULL; elem1 = ListNext(nodesList, elem1)) { /* Get the current node */ Node_t *node1 = (Node_t *)elem1->obj; if (node1->priority != 0) { /* Insert in the right position inside list N */ ListElem *elem2 = ListFirst(N); while (elem2 != NULL) { Node_t *node2 = (Node_t *)elem2->obj; /* Checking the priority and the node id */ if ((node1->priority < node2->priority) || \ ((node1->priority == node2->priority) && (node1->id > node2->id))) { elem2 = ListNext(N, elem2); } else { ListInsertBefore(N, elem1->obj, elem2); break; } } /* If sorted_list is empty or elem1 is smaller than everyone in the sorted list */ if (elem2 == NULL) { ListAppend(N, elem1->obj); } } } }
Status ListSearchAndFreeOne(List *l, char *thing) { List *p; for (p = ListFirst (l); p; p = ListNext (p)) if (((char *) p->thing) == (char *) thing) { ListFreeOne (p); return (1); } return (0); }
void printFreeList(LIST *free_list) { BLOCK *cur_block; cur_block = ListFirst(free_list); while (cur_block != NULL) { printf("Free block start: %ld end: %ld\n", cur_block->address, cur_block->address + cur_block->size); cur_block = ListNext(free_list); } printf("\n"); }
static List alg1_w_ind(Term m1, List wf) { List l1,l2,wi,wn; wi=wn=NewList(); l2=CompoundArgN(m1,3); while(!is_empty_list(l2)) { List l3; l3=CompoundArg1(ListFirst(l2)); while(!is_empty_list(l3)) { Atomic t1,t2; t1=ListFirst(l3); t2=CompoundArg2(t1); if(CompoundName(t1)==OPR_WILD && !ListMember(wf,t2) && !ListMember(wi,t2)) { wi=AppendLast(wi,t2); wn=AppendLast(wn,CompoundArgN(t1,3)); } l3=ListTail(l3); } l2=ListTail(l2); } l1=wi; l2=wn; while(!is_empty_list(l1)) { ChangeList(l1,MakeCompound2(OPR_DIV,ListFirst(l1),ListFirst(l2))); l1=ListTail(l1); l2=ListTail(l2); } RemoveList(wn); return wi; }
void CloseSkins( void ) { DmOpenRef dbRef; if ( NULL == resourceDBList ) return; dbRef = ListFirst( resourceDBList ); while ( dbRef != NULL ) { DmCloseDatabase( dbRef ); dbRef = ListNext( resourceDBList, dbRef ); } ListDelete( resourceDBList ); }
// return void void ListConcat(LIST *list1, LIST *list2) { void *item; // add to list1 //list1->curr = list1->head->prev; //list2->curr = list2->head->next; ListLast(list1); ListFirst(list2); while (list2->curr != list2->head) { item = ListRemove(list2); ListAdd(list1, item); } // rmv list2 free_list(list2); }
//////////////////////////////////////////////////// // 功能: 检查当前有几个声音通道 // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// int GetDacChannel(void) { PLIST head, n; int chs; // 获取采样数据到临时缓冲区 kMutexWait(hDacMutex); head = &DacList; chs = 0; for(n=ListFirst(head); n!=head; n=ListNext(n)) { if(++chs == 4) break; // 最多合成4通道 } kMutexRelease(hDacMutex); return chs; }
//////////////////////////////////////////////////// // 功能: // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// int DacGetOwners(void) { PLIST head; PLIST n; int owners; // 获取打开设备数量 kMutexWait(hDacMutex); head = &DacList; owners = 0; for(n=ListFirst(head); n!=head; n=ListNext(n)) owners++; kMutexRelease(hDacMutex); return owners; }
uint16_t calculateParentRcv(Node_t *node, Tree_t *tree) { List listChildren; memset(&listChildren, 0, sizeof(List)); ListInit(&listChildren); Tree_t *subTree = getSubTree(tree, node); getListNodesInTree(subTree, &listChildren); uint16_t res = 0; for (ListElem *elem = ListFirst(&listChildren); elem != NULL; elem = ListNext(&listChildren, elem)) { Node_t *node = (Node_t *)elem->obj; res += node->q; } return (res); }
PLISTLINK *ListGetPointers(HSLIST &hList, int &iListCount) { iListCount = ListGetCount(hList); PLISTLINK *pPointers = (PLISTLINK *) SysAlloc((iListCount + 1) * sizeof(PLISTLINK)); if (pPointers != NULL) { int i; PLISTLINK lpCurr = ListFirst(hList); for (i = 0; lpCurr != INVALID_SLIST_PTR; lpCurr = ListNext(hList, lpCurr), i++) pPointers[i] = lpCurr; pPointers[i] = INVALID_SLIST_PTR; } return pPointers; }
void ListFreeAllButHead(List *l) { List *p, *next; p = ListFirst(l); while (p) { next = ListNext (p); XtFree((char *) p); p = next; } l->next = l; l->prev = l; }
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); }
VOID NEAR OutputBaseInterfaces ( ICreateTypeInfo FAR* lpdtinfo, LPENTRY pEntry, TYPEKIND tkind ) { HREFTYPE hreftype; HRESULT res; LPINTER lpinterList = pEntry->type.inter.interList; LPINTER lpinter; SHORT i; INT implTypeFlags; Assert (lpinterList); // caller should have checked this for use // point to first base interface lpinter = (LPINTER)ListFirst(lpinterList); for (i=0;;i++) { // get index of typeinfo of base interface/dispinterface if (lpinter->ptypeInter->lptinfo == NULL) ItemError(szFmtErrOutput, lpinter->ptypeInter->szName, OERR_NO_DEF); CHECKRESULT(lpdtinfo->AddRefTypeInfo(lpinter->ptypeInter->lptinfo, &hreftype)); CHECKRESULT(lpdtinfo->AddImplType(i, hreftype)); // if (tkind == TKIND_COCLASS) { // need to always set the flags for items in a coclass implTypeFlags = 0; if (lpinter->fAttr & fDEFAULT) implTypeFlags |= IMPLTYPEFLAG_FDEFAULT; if (lpinter->fAttr & fRESTRICTED) implTypeFlags |= IMPLTYPEFLAG_FRESTRICTED; if (lpinter->fAttr & fSOURCE) implTypeFlags |= IMPLTYPEFLAG_FSOURCE; CHECKRESULT(lpdtinfo->SetImplTypeFlags(i, implTypeFlags)); } // advance to next entry if not all done if (lpinter == (LPINTER)ListLast(lpinterList)) break; // exit if all done lpinter = (LPINTER)lpinter->pNext; } // WHILE }
List SetLets(List l) { List l1,lr, lre=0; lr=NewList(); slrl++; l1=l; while(!is_empty_list(l1)) { List nl=s_l_1(ListFirst(l1)); if(nl==0) {l1=ListTail(l1);continue;} if(lr==0) {lr=nl;lre=lr;} else ConcatList(lre,nl); while(ListTail(lre)) lre=ListTail(lre); /*lr=ConcatList(lr,);*/ l1=ListTail(l1); } RemoveList(l); slrl--; if(slrl==0) { for(l1=lr;l1;l1=ListTail(l1)) { List l2,sl=ConsumeCompoundArg(ListFirst(l1),3); int ch=0; for(l2=sl;l2;l2=ListTail(l2)) if(CompoundName(ListFirst(l2))==A_INFINITESIMAL) { FreeAtomic(ListFirst(l2)); ChangeList(l2,0); ch++; } if(ch) do { for(l2=sl;l2;l2=ListTail(l2)) if(ListFirst(l2)==0) { sl=CutFromList(sl,l2); break; } } while(l2); SetCompoundArg(ListFirst(l1),3,sl); } } lr=a1l_rem_inf(lr); return lr; }
static void alg1_set_cos0(Term a1) { List l; Term c0; int scno=0; for(l=CompoundArg1(a1);l;l=ListTail(l)) { List l2; for(l2=CompoundArgN(ListFirst(l),3);l2;l2=ListTail(l2)) { Term t=ListFirst(l2); if(CompoundName(t)==OPR_PARAMETER && (CompoundArg2(t)==A_SIN || CompoundArg2(t)==A_COS)) scno++; if(CompoundName(t)==OPR_WILD) { List l3; for(l3=CompoundArg2(t);l3;l3=ListTail(l3)) alg1_set_cos0(ListFirst(l3)); } } } if(scno==0) return; c0=MakeCompound3(OPR_PARAMETER,0,A_COS,NewInteger(0)); for(l=CompoundArg1(a1);l;l=ListTail(l)) { List l2; scno=0; for(l2=CompoundArgN(ListFirst(l),3);l2;l2=ListTail(l2)) { Term t=ListFirst(l2); if(CompoundName(t)==OPR_PARAMETER && (CompoundArg2(t)==A_SIN || CompoundArg2(t)==A_COS)) scno++; } if(scno) continue; l2=ConsumeCompoundArg(ListFirst(l),3); l2=AppendLast(l2,CopyTerm(c0)); SetCompoundArg(ListFirst(l),3,l2); } FreeAtomic(c0); /*WriteTerm(a1);puts("\n");*/ }
static void _XtProcessIceMsgProc(XtPointer client_data, int *source, XtInputId *id) { IceConn ice_conn = (IceConn) client_data; IceProcessMessagesStatus status; status = IceProcessMessages (ice_conn, NULL, NULL); if (status == IceProcessMessagesIOError) { List *cl; int found = 0; if (verbose) { printf ("IO error on connection (fd = %d)\n", IceConnectionNumber (ice_conn)); printf ("\n"); } for (cl = ListFirst (RunningList); cl; cl = ListNext (cl)) { ClientRec *client = (ClientRec *) cl->thing; if (client->ice_conn == ice_conn) { CloseDownClient (client); found = 1; break; } } if (!found) { /* * The client must have disconnected before it was added * to the session manager's running list (i.e. before the * NewClientProc callback was invoked). */ IceSetShutdownNegotiation (ice_conn, False); IceCloseConnection (ice_conn); } } }
uint8_t fhssDistributedBlacklistOptimalChan(Node_t *parent, Node_t *child, uint8_t prrMatrix[][MAX_NODES][NUM_CHANNELS], uint64_t asn) { uint8_t best_freq = 0, best_prr = 0; for (ListElem *elem = ListFirst(&parent->channels); elem != NULL; elem = ListNext(&parent->channels, elem)) { uint8_t freq_off = (uint8_t)elem->obj; uint8_t freq = fhssOpenwsnChan(freq_off, asn); if (prrMatrix[child->id][parent->id][freq] > best_prr) { best_freq = freq; best_prr = prrMatrix[child->id][parent->id][freq]; } } return (best_freq); }
static int should_skip(int no, Term a) { List l; int i=1; l=DefaultIndex; while(!is_empty_list(l)) { Term gg; gg=ListFirst(l); if(equal_repres(gg,a)) return 1; if(i==no) return 0; i++; l=ListTail(l); } return 0; }
uint8_t fhssDistributedBlacklistMABExplore(Node_t *parent, uint64_t asn) { uint8_t offset_to_explore = rand() % ListLength(&parent->channels); //PRINTF("FHSS exploring at %lld\n", (long long)asn); uint8_t i = 0; for (ListElem *elem = ListFirst(&parent->channels); elem != NULL; elem = ListNext(&parent->channels, elem)) { if (i++ == offset_to_explore) { uint8_t freq_off = (uint8_t)elem->obj; return (fhssOpenwsnChan(freq_off, asn)); } } return (0); }
bool mrhofRxDio(Node_t *node, List *nodesList) { /* We check if the DIO received was the first one, in this case we have to set new neighbor as prefered parent */ if (!node->synced) { for (ListElem *elem = ListFirst(&node->candidate_parents); elem != NULL; elem = ListNext(&node->candidate_parents, elem)) { RPL_Neighbor_t *neighbor = (RPL_Neighbor_t *)elem->obj; if (neighbor->stable) { mrhofSetPreferedParent(node, neighbor); return (true); } } } return (false); }
//////////////////////////////////////////////////// // 功能: 根据媒体类型,获取媒体回调函数 // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// static int MediaSrvGetCallback(int type, PMEDIA_CALLBACK callback) { PLIST n; PLIST head; PCALLBACK_LINK link; // 检查设备是否已经注册 head = &MediaCallbackList; for(n=ListFirst(head); n!=head; n=ListNext(n)) { link = ListEntry(n, CALLBACK_LINK, Link); if((link->Type & type) == type) { kmemcpy(callback, &link->Callback, sizeof(MEDIA_CALLBACK)); return 0; } } return -1; }
void TestTraverse( void ) { UInt16* item1; UInt16* item2; ASSERT( ListIsEmpty( list )); AddTwoItems(); item1 = ListFirst( list ); item2 = ListNext( list, item1 ); ASSERT_UINT16_EQUAL_MSG( "First item: ", 6, *item1 ); ASSERT_UINT16_EQUAL_MSG( "Next item: ", 10, *item2 ); item1 = ListLast( list ); ASSERT_UINT16_EQUAL_MSG( "Last item: ", 10, *item1 ); item2 = ListNext( list, item1 ); ASSERT_MSG( "Item after last in list: ", item2 == NULL ); }
bool mrhofUpdateParents(List *nodesList, uint8_t rpl_algo) { bool ret = false; /* Update the information for all nodes */ for(ListElem *elem = ListFirst(nodesList); elem != NULL; elem = ListNext(nodesList, elem)) { Node_t *node = (Node_t *)elem->obj; if (node->type != SINK && node->synced) { if (mrhofUpdateDAGRanks(node, nodesList)) { ret = true; } } } return (ret); }
uint8_t fhssDistributedBlacklistMABBestArmChan(Node_t *parent, Node_t *child, uint64_t asn) { uint8_t freq = 0; /* Every epsilon_ts_incr_n time slots we divide increment epsilon_n */ if ((epsilon_ts_incr_n != 0) && ((asn + 1) % epsilon_ts_incr_n) == 0) { if (++epsilon_n == epsilon_max_n) { epsilon_n = epsilon_init_n; PRINTF("Reseting Epsilon to %ld at %lld\n", (long)epsilon_init_n, (long long)asn); } } if ((rand() % epsilon_n) == 0) { /* We will explore all channels randomly */ return (fhssDistributedBlacklistMABExplore(parent, asn)); } else { /* We will exploit the best arm */ uint8_t best_freq = 0, best_reward = 0; for (ListElem *elem = ListFirst(&parent->channels); elem != NULL; elem = ListNext(&parent->channels, elem)) { uint8_t freq_off = (uint8_t)elem->obj; freq = fhssOpenwsnChan(freq_off, asn); if (parent->avg_reward[child->id][freq] > best_reward) { best_freq = freq; best_reward = parent->avg_reward[child->id][freq]; } } return (best_freq); } }
Term ProcKeepLets(Term t, Term ind) { Term t1; List l; if(!is_compound(t) || CompoundArity(t)!=1) { ErrorInfo(331); printf("bad syntax in 'keep_lets' statement.\n"); return 0; } t1=CommaToList(ConsumeCompoundArg(t,1)); FreeAtomic(t); for(l=t1;l;l=ListTail(l)) { Atom p; p=ListFirst(l); if(!is_atom(p)) { ErrorInfo(332); printf("unexpected '"); WriteTerm(p); printf("' in 'keep_lets' statement.\n"); continue; } if(GetAtomProperty(p,PROP_TYPE)) { ErrorInfo(333); printf("'keep_lets': object '%s' is already defined.\n", AtomValue(p)); continue; } SetAtomProperty(p,A_KEEP_LETS,MakeCompound1(A_KEEP_LETS,0)); } return 0; }
static void SaveYourselfDoneProc(SmsConn smsConn, SmPointer managerData, Bool success) { ClientRec *client = (ClientRec *) managerData; if (verbose) { printf("Client Id = %s, received SAVE YOURSELF DONE [Success = %s]\n", client->clientId, success ? "True" : "False"); } if (!ListSearchAndFreeOne (WaitForSaveDoneList, (char *) client)) { if (ListSearchAndFreeOne (InitialSaveList, (char *) client)) SmsSaveComplete (client->smsConn); return; } if (!success) { ListAddLast (FailedSaveList, (char *) client); } if (ListCount (WaitForSaveDoneList) == 0) { if (ListCount (FailedSaveList) > 0 && !checkpoint_from_signal) PopupBadSave (); else FinishUpSave (); } else if (ListCount (WaitForInteractList) > 0 && OkToEnterInteractPhase ()) { LetClientInteract (ListFirst (WaitForInteractList)); } else if (ListCount (WaitForPhase2List) > 0 && OkToEnterPhase2 ()) { StartPhase2 (); } }
//////////////////////////////////////////////////// // 功能: 得到BUF里剩余数据的时间 // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// int GetDacSpaceCount() { int i; int len; PLIST head, n; PDAC_DEVICE dac; PRESAMPLE presample; kMutexWait(hDacMutex); len = 0; head = &DacList; if( head ) { n=ListFirst(head); dac = ListEntry(n, DAC_DEVICE, Link); if( dac ) { presample = &dac->Resample; for( i = 0 ; i < MAX_PCMBUFS ; i++ ) { if( presample->BufFlag[i] == DAC_BUF_WRITE ) len +=DAC_PCMBUF_SIZE; } } } presample = &DacDevice; for( i = 0 ; i < MAX_PCMBUFS ; i++ ) { if( presample->BufFlag[i] == DAC_BUF_WRITE ) len +=DAC_PCMBUF_SIZE; } kMutexRelease(hDacMutex); len = ((long long)len * nMplayerSamplerate * nMplayerChannels * 2) / (DAC_SAMPLE_RATIO * 2 * 2); len = len & (~0x03); return len; }
static int must_skip(int realno, List ind) { int res,mustbe; List l1; mustbe=ListLength(ind); if(realno==mustbe) return 0; if(realno>mustbe) return -1; l1=DefaultIndex; res=1; while(!is_empty_list(l1)) { mustbe-=inst_in(ListFirst(l1),ind); if(realno==mustbe) return res; if(realno>mustbe) return -1; l1=ListTail(l1); res++; } return -1; }