void exampleQueue() { // Use pooling for efficiency, if you don't want to use pooling // then comment out this line. pool_queue(16); Queue* Q = newQueue(); // A queue with strings queue_offer(Q, "First"); queue_offer(Q, "In"); queue_offer(Q, "First"); queue_offer(Q, "Out."); // Peek at the head of the queue printf("%s\n", (char*)queue_peek(Q)); // Traverse through the queue polling each string while (!queue_isEmpty(Q)) printf("%s ", (char*)queue_poll(Q)); printf("\n"); // A queue with integers, primitive data types require some trickyness queue_clear(Q); int x[] = {1, 2}; int y = 3; queue_offer(Q, &x[0]); queue_offer(Q, &x[1]); queue_offer(Q, &y); while (!queue_isEmpty(Q)) // You first need to cast it using (int*) and since its a pointer to // an integer you need to get the value of the pointer using * // You could similarly use: // int* z = queue_poll(Q); // printf("%d ", *z); printf("%d ", *((int*)queue_poll(Q))); printf("\n"); // This will clear the queue of any nodes and pool them and then free // the queue itself from memory queue_free(Q); // If you're not using pooling this can be commented out. This will // free all pooled nodes from memory. Always call this at the end // of using any Queue. unpool_queue(); }
void free_SRTN() { if (q->head == NULL) { free(q); return; } while(q->head) { Element *el = queue_poll(q); printf("freeing %d\n",el->task.id); free(el); } free(q); }
void finish_SRTN(int id) { if (queue_peek(q) == NULL || q->head->task.id != id) { printf("Queue either empty, or the process with the given id is not the current head of the Queue!\n"); return; } Element *el = queue_poll(q); free(el); if (queue_size(q)){ switch_task(q->head->task.id); }else{ switch_task(IDLE); free_SRTN(); } }
int poll_serverdata_to_send(SServerSendQueue *_this, unsigned int timeout) { return queue_poll(&(_this->genqueue),timeout); }