int main() { int i = 0; int j = 0; DLLIST *item = NULL; for(i = 1; i <= 10; i++) { DLAppend(&tryList, 0, &i, sizeof(int)); } printList(); for(item = DLGetFirst(tryList); item != NULL; item = item->Next) { j = j + 1; if(j == 1 || j == 6 || j == 10) { item->Tag = 0; } else { item->Tag = 1; } printf("totalaa count = %d\r\n", DLCount(tryList)); } printf("j = %d\r\n", j); if(tryList != NULL) { for(item = DLGetFirst(tryList); item != NULL;) { DLLIST *nextItem = item->Next; if(item != NULL && item->Tag == 1) { if(item == DLGetFirst(tryList)) { printf("aaa\r\n"); tryList = item->Next; DLDelete(item); item = tryList; continue; } else { printf("bbb\r\n"); DLDelete(item); //item = nextItem; } } item = nextItem; } } printList(); }
int DelItem(DLLIST *item) { if(DLGetFirst(tryList) == item)//delete first item { tryList = item->Next; DLDelete(item); return 1; } else { DLDelete(item); return 0; } }
void addData2SendList(SendList_t *sList, sendData_t* sendData) { if(sList->eleNum < MAX_SEND_BUF) { DLAppend(&(sList->sendList), 0, sendData, sizeof(sendData_t)); sList->eleNum = sList->eleNum + 1; } else//delete the oldest one, the add new one { DLLIST *oldestItem = DLGetFirst(sList->sendList); printf("sendList full---------------------\r\n"); if(NULL == oldestItem) { return; } DLLIST *nextItem = oldestItem->Next; if(NULL == nextItem) { return; } sList->sendList = nextItem; DLDelete(oldestItem); DLAppend(&(sList->sendList), 0, sendData, sizeof(sendData_t)); } return; }
/* 解除一条生理报警 */ static int PhyAlarmLifted(B_ALM_INFO info) { int i; int res; int iListNum; DLLIST *DelAddr=NULL; //查找到的记录的地址 DLLIST *SaveList; //保存链表起始位置 B_ALM_INFO *DelData=NULL; //查找到的记录 //加锁 pthread_mutex_lock(&mtPhyAlm); //检查该记录是否存在 res = DLWalk((DLLIST *)gDListAlmPhy, &DelAddr, ProcFindAlmItem, &info); //如果存在,删除该记录,否则返回 if(res == DL_FIND_OK){ if(DelAddr != NULL){ DelData = (B_ALM_INFO *)DLGetData(DelAddr, NULL, NULL); if(DelData != NULL){ //保存链表地址 if(DelAddr->Prev !=NULL){ gDListAlmPhy = DelAddr->Prev; } else if(DelAddr->Next !=NULL) { gDListAlmPhy = DelAddr->Next; } else{ gDListAlmPhy = NULL; } //删除原有的信息 DLDelete((DLLIST *)DelAddr); } } } else{ // if(B_PRINTF) printf("%s:%d The Phy records (%d) do not exist.\n", __FILE__, __LINE__, info.bAlmID); //解锁 pthread_mutex_unlock(&mtPhyAlm); return -1; } //打印链表 // iListNum = DLCount((DLLIST *)gDListAlmPhy); // if(B_PRINTF) printf("(%s:%d)Del::List has %d Infos.\n", __FILE__, __LINE__, iListNum); // res = DLWalk((DLLIST *)gDListAlmPhy, NULL, ProcPrintAlmItems, NULL); //解锁 pthread_mutex_unlock(&mtPhyAlm); //--- 更新显示标志 --- bResetView_Phy = TRUE; // if(B_PRINTF) printf("%s:%d Del One PhyAlm Info.\n", __FILE__, __LINE__); return 0; }
void sendSendList(SendList_t *sList, int needRes) { DLLIST *item; for(item = DLGetFirst(sList->sendList); item != NULL; item = item->Next) { sendData_t *sendData = item->Object; if(1 == sendDataEle(sendData)) { item->Tag = SENDOK;//send success } else { item->Tag = SENDERR;//send fail } sendData->retryTimes = sendData->retryTimes + 1; } if(NO_NEED_RES == needRes)//if no need res, delete when it send success { for(item = DLGetFirst(sList->sendList); item != NULL;) { DLLIST *nextItem = item->Next; if(item != NULL && item->Tag == SENDOK) { if(item == DLGetFirst(sList->sendList)) { sList->sendList = item->Next; DLDelete(item); sList->eleNum = sList->eleNum - 1; item = sList->sendList; continue; } else { DLDelete(item); sList->eleNum = sList->eleNum - 1; } } item = nextItem; } } }