コード例 #1
0
ファイル: examples.c プロジェクト: ClickerMonkey/CDSL
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();
}
コード例 #2
0
ファイル: SRTN.c プロジェクト: shinroo/TUB_Programs
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);
}
コード例 #3
0
ファイル: SRTN.c プロジェクト: shinroo/TUB_Programs
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();
	}
}
コード例 #4
0
ファイル: pong_server_queue.c プロジェクト: M-a-z/aMazPong
int poll_serverdata_to_send(SServerSendQueue *_this, unsigned int timeout)
{
    return queue_poll(&(_this->genqueue),timeout);
}