// Notify a condition, releasing all objects waiting void WaitConditionImpl::NotifyAll() { Lock::Locker lock(&WaitQueueLoc); // Pop and signal all events // NOTE : There is no need to release the events, it's the waiters job to do so EventPoolEntry* pentry = QueuePop(); while (pentry) { ::SetEvent(pentry->hEvent); pentry = QueuePop(); } }
static void HarvestDanglingSyncpoints ( Queue *spointsQueuePtr, Queue *eventsQueuePtr) { SyncPoint *spointPtr; spointPtr = QueuePop(spointsQueuePtr); while (spointPtr != NULL) { HarvestSyncpoint(spointPtr, eventsQueuePtr); FreeSyncPoint(spointPtr); spointPtr = QueuePop(spointsQueuePtr); } }
word FindShortestPath(void) { #define PROCEED(n) if(!path_prev[n] && TilePassable(n)){path_prev[n] = m; QUEUE_PUSH(n)} word n = TILE_ENCODE(player->tilex, player->tiley); word m; byte i; _fmemset(path_prev,0,sizeof(path_prev)); QUEUE_RESET QUEUE_PUSH(n) path_prev[n] = WORD_MAX; while(!QUEUE_EMPTY) { m = QueuePop(); if(ObjectOfInterest(m)) { return m; } // add neighbours. don't worry about bounds checking, maps // should be guarded anyway n = m + 1; PROCEED(n) n = m - 1; PROCEED(n) n = m + MAPSIZE; PROCEED(n) n = m - MAPSIZE; PROCEED(n) } return 0; #undef PROCEED }
void main() { queue s; int i,j,k,m; QueueInit(&s); while(1) { printf("*****请选择操作*****\n"); printf("1、入队 2、出队 3、取队头元素 4、遍历队列 5、退出\n"); printf("选择:\n"); scanf("%d",&i); switch(i) { case 1: printf("输入要入队的个数:\n"); scanf("%d",&m); printf("输入%d个元素的值:\n",m); for(i=0; i<m; i++) { scanf("%d",&j); QueuePush(&s,j); } break; case 2: printf("输入要出队的个数:\n"); scanf("%d",&i); printf("出队的元素为:\n"); for(; i>0; i--) { k=QueuePop(&s,&j); if(k) printf("%d ",j); else { printf("该队没有足够的元素\n"); break; } } break; case 3: i=Getfront(&s); if(i!=0) printf("队头元素为%d\n",i); else printf("该队列没有元素!\n"); break; case 4: QueueTrav(s); break; case 5: break; default: printf("您的输入有误\n"); } system("pause"); system("cls"); } }
// Notify a condition, releasing the least object in a queue void WaitConditionImpl::Notify() { Lock::Locker lock(&WaitQueueLoc); // Pop last entry & signal it EventPoolEntry* pentry = QueuePop(); if (pentry) ::SetEvent(pentry->hEvent); }
void WirelessSendHandler(void *CallBackRef, unsigned int EventData) { unsigned char c; wireless.send_in_progress = 0; if(!QueueIsEmpty(&(wireless.write_queue))) { wireless.send_in_progress = 1; c = QueuePop(&(wireless.write_queue)); XUartLite_Send(&wireless.uart, &c, 1); } }
int main(int argc, char *argv[]) { void *p = NULL; long msg = 0; void *pMsg = NULL; p = QueueCreate(10); if (NULL == p) { printf("Create queue failed.\n"); return -1; } msg = 90; while (msg--) { if (QueuePush(p, (void *)msg) < 0) { printf("----------Queue is full now-----------\n"); break; } printf("Push ok. [msg: %ld, size: %d]\n", msg, QueueGetSize(p)); } msg = 15; while (msg--) { if (QueuePopPush(p, (void *)msg, &pMsg) < 0) { printf("----------QueuePopPush failed-----------\n"); break; } printf("PopPush ok. [msgPop: %ld, msgPush: %ld, size: %d]\n", (long)pMsg, msg, QueueGetSize(p)); } msg = 60; while (msg--) { if (QueuePop(p, &pMsg) < 0) { printf("----------Queue is empty now-----------\n"); break; } printf("Pop ok. [msg: %ld, size: %d]\n", (long)pMsg, QueueGetSize(p)); } QueueDestroy(p); system("pause"); return 0; }
__interrupt void TXISR() { // UART uint8_t out = 0; if(QueuePop(&UARTTXBuf, &out)) { UCA0TXBUF = out; } else { // Done transfering disable transmit interrupt IE2 &= ~UCA0TXIE; } // SPI out = 0; if(QueuePop(&SPITXBuf, &out)) { UCB0TXBUF = out; } else { // Done transfering disable transmit interrupt IE2 &= ~UCB0TXIE; } }
/** Code to test this Queue implementation This code is only included for example purposes and to ensure that this implementation works in all situations This code at present is not exhaustive. STEPS: - Test 1 -# Push some integers onto the Queue inplace of pointers. -# Pop all of the elements off the queue to make sure that they match - Test2 -# TODO \todo Write a more exhaustive test */ int QueueTest() { Queue queue; void* ary[10]; QueueInit( &queue, ary, 10 ); // Test 1 { { int i; for( i = 0 ; i < 10 ; i++ ) QueuePush( &queue, (void*) i ); } if(QueueIsFull(&queue) != TRUE) return 1; { int i; for( i = 0 ; i < 10 ; i++ ) { int val = (int) QueuePop( &queue ); if(val != i) return 2; } } if(QueueIsEmpty(&queue) != TRUE) return 3; if(QueueIsFull(&queue) != FALSE) return 4; } // Test 2 { QueuePush( &queue, (void*) 1234); if((int)QueueFront(&queue) != 1234) return 5; } return 0; }
static boolean NET_SV_RecvPacket(net_addr_t **addr, net_packet_t **packet) { net_packet_t *popped; popped = QueuePop(&server_queue); if (popped != NULL) { *packet = popped; *addr = &server_addr; server_addr.module = &net_loop_server_module; return true; } return false; }
static boolean NET_CL_RecvPacket(net_addr_t **addr, net_packet_t **packet) { net_packet_t *popped; popped = QueuePop(&client_queue); if (popped != NULL) { *packet = popped; *addr = &client_addr; client_addr.module = &net_loop_client_module; return true; } return false; }
void *ThreadWork(void *v_pObj) { CTAWQTask *pTaskPush = NULL; CTAWQTask *pTaskPop = NULL; CTAsyncWorkQueue *pAWQ = (CTAsyncWorkQueue *)v_pObj; int ret = 0; while (1) { if (NULL == pTaskPush) { ret = QueuePop(pAWQ->m_pRunQ, (void **)&pTaskPop); } else { ret = QueuePopPush(pAWQ->m_pRunQ, pTaskPush, (void **)&pTaskPop); } if (0 != ret) { usleep(100 * 1000); pTaskPush = NULL; continue; } ret = pTaskPop->OnRun(); if (0 != ret) { pTaskPush = pTaskPop; continue; } pTaskPush = NULL; do { ret = QueuePush(pAWQ->m_pEndQ, pTaskPop); } while (0 > ret); } return NULL; }
int Wireless_Send(Skaro_Wireless * w, char command, char length, char * data){ unsigned char top; CPU_MSR msr = DISABLE_INTERRUPTS(); QueuePush(&(w->write_queue), (void *)(uint32)command); QueuePush(&(w->write_queue),(void *)(uint32)length); int i; for(i = 0; i < length; i++){ QueuePush(&w->write_queue, (void *)(uint32)data[i]); } // If there is no send in progress, initiate a send if (!(w->send_in_progress)) { // We are about to send it, so pop it off top = (unsigned char)(uint32)QueuePop(&(w->write_queue)); w->send_in_progress = 1; XUartLite_Send(&(w->uart), &top, 1); } RESTORE_INTERRUPTS(msr); return 1; }
void *CarDispatch(void *vptr) { int k,j, *dptr=(int*)vptr, d=*dptr, myclk=SetVClk(9,0,0); Car437 *carptr; assert (d>=0 && d<4); for (k=0; k<timers; k++, myclk+=10) { Sem437P(&Barrier[d]); //display the waiting line every 10 mins //while ((GetTime()-starttime)*100<=(k+1) && QueueEmpty(&Q[d])==false) { for (j=0; GetTime()<=10*(k+1) && QueueEmpty(&Q[d])==false; j++) { Sem437P(&RedLight); if ((carptr=QueuePop(&Q[d]))!=NULL) CarPass(carptr,d); Sem437V(&RedLight); } //printf("k=%d Next j=%d %x sleep real %d vClk %d myclk %d\n",k,j, \ (int)pthread_self(),(int)GetTime(),vClk,myclk); } return(NULL); }
int CTAsyncWorkQueue::TryGetTask(CTAWQTask **v_ppTask) { return QueuePop(m_pEndQ, (void **)v_ppTask); }
static void ManagerThreadProc ( ClientData clientData ) { BlockAllSignals(); Tcl_MutexLock(&spointsLock); /* Notify creator thread we're ready */ threadReady = 1; Tcl_ConditionNotify(&spointsCV); while (1) { Queue eventQueue; SignalMapSearch iterator; SyncPoint *spointPtr; while (condReady == 0) { Tcl_ConditionWait(&spointsCV, &spointsLock, NULL); } condReady = 0; if (shutdownRequested) { break; } InitEventList(&eventQueue); HarvestDanglingSyncpoints(&danglingSpoints, &eventQueue); spointPtr = FirstSigMapEntry(&syncpoints, &iterator); while (spointPtr != NULL) { HarvestSyncpoint(spointPtr, &eventQueue); spointPtr = NextSigMapEntry(&iterator); } Tcl_MutexUnlock(&spointsLock); { SignalEvent *evPtr; Tcl_ThreadId lastId; evPtr = QueuePop(&eventQueue); lastId = evPtr->threadId; do { SignalEvent *nextEvPtr; Tcl_ThreadId threadId; nextEvPtr = QueuePop(&eventQueue); threadId = evPtr->threadId; Tcl_ThreadQueueEvent(threadId, (Tcl_Event*) evPtr, TCL_QUEUE_TAIL); if (threadId != lastId) { Tcl_ThreadAlert(lastId); } printf("Sent %d to %x\n", evPtr->signum, evPtr->threadId); evPtr = nextEvPtr; lastId = threadId; } while (evPtr != NULL); Tcl_ThreadAlert(lastId); } Tcl_MutexLock(&spointsLock); } /* Notify creator thread we're finished. * Note that the spointsLock is held at this point. */ threadReady = 1; Tcl_ConditionNotify(&spointsCV); Tcl_MutexUnlock(&spointsLock); }