// Return first interior element, if any QNode* const Queue_Front(Queue* const pQ){ if (Queue_Empty(pQ)){ return NULL; } return (*pQ).front.next; }
// Return last interior element, if any QNode* const Queue_Back(Queue* const pQ){ if (Queue_Empty(pQ)){ return NULL; } return (*pQ).rear.prev; }
/* 退出程序 */ static int LCUIApp_Quit(void) { LCUI_App *app; app = LCUIApp_GetSelf(); if( !app ) { printf("%s (): %s", __FUNCTION__, APP_ERROR_UNRECORDED_APP); return -1; } LCUIAppList_Delete(app->id); /* 如果程序列表为空,就退出LCUI */ if (Queue_Empty(&LCUI_Sys.app_list)) { LCUI_Quit(); } return 0; }
// Remove first interior element of Queue and return it QNode* const Queue_Pop(Queue* const pQ){ //check for empty queue if (Queue_Empty(pQ)){ return NULL; } QNode* popVal = (*pQ).front.next; //make front point to node after next QNode* afterNext = (*pQ).front.next; (*pQ).front.next = (*afterNext).next; QNode* change = (*pQ).front.next; (*change).prev = &((*pQ).front); //return front value return popVal; }
void *testMtd (void* a) { // Build a dumb serializer and queue with Appropriate APIs queue_t my_queue = (queue_t) a; printf("Queue Count: %d\n",my_serial->queue_count); printf("Queue Empty: %d\n",Queue_Empty(my_serial,my_queue)); printf("%s\n","Checking Queue Count..."); printf("%d\n",my_serial->queue_count); pthread_t tid = pthread_self(); Enqueue(my_queue,tid,&test); printf("Queue Length: %d\n",my_queue->length); sleep(1); Dequeue(my_queue); printf("Queue Length: %d\n",my_queue->length); }
void *ContextManager_Producer(void *_self) { ContextManager *self = (ContextManager*)_self; Queue *q = self->outgoing_queue; while(true) { while(Queue_Empty(q)) pthread_yield(); void *data = Queue_Dequeue(q); if(data == NULL) break; printf("%s\n", (char*)data); } printf("Producer queue shut down\n"); return NULL; }
void *ContextManager_Consumer(void *_self) { ContextManager *self = (ContextManager*)_self; Queue *q = self->incoming_queue; while(true) { while(Queue_Empty(q)) pthread_yield(); void *data = Queue_Dequeue(q); if(data == NULL) break; printf("Enqueueing data!\n"); Queue_Enqueue(self->outgoing_queue, data); } printf("Consumer queue shut down\n"); return NULL; }
void leave_serializer(serial_t* serial) { int i; for(i=2;i<serial->no_of_queues;i++) { if(Queue_Empty(serial, serial->queues[i])==0) { cond_t condition = serial->queues[i]->head->func(); if(condition == 1) { printf("condition satisfied\n"); sem_post(&serial->queues[i]->head->mutex); return; } } } sem_post(&serial->queue_lock); }
static void *inner_alarm_handler(void *ctx) { QTHREAD *qt = (QTHREAD *)ctx; time_t starttime; time_t newtime; struct timeval t; QUEUE_ITEM *item; starttime = time(NULL); newtime = qt->timeout; while (time(NULL) - starttime < newtime) { t.tv_sec = newtime < POLLSEC ? newtime : POLLSEC; t.tv_usec = 0; select(0, NULL, NULL, NULL, &t); newtime = qt->timeout - (time(NULL) - starttime); if (!Queue_Empty(qt->queue)) { item = Get_Queue_Item(qt->queue); if (!strcmp(item->action, "Terminate")) { Free_Queue_Item(item); return NULL; } Free_Queue_Item(item); } } qt->cb(qt->data); if (qt->flags & QALARM_RECUR) add_alarm(qt->parent, qt->timeout, qt->cb, qt->data, qt->flags); Add_Queue_Item(qt->parent->queue, "Destroy", &(qt->tid), sizeof(pthread_t)); return NULL; }
//Indicates if a request inside (or aimed at) the upwards queue should be next to service cond_t* ready_to_service_from_up_queue(void* request) { int requestID = ((request_data_t*)request)->id; return ( DiskIdle() && GoingUp() && (NextRequestInQueueBeingServed() == requestID || Queue_Empty(serializer, up_queue)) ); }