Exemplo n.º 1
0
void
stress_test_dll(int amt)
{
	dll l1;
	dll l2;
	gendata x, y;
	int i;

	l1 = dll_create();
	l2 = dll_create();
	assert(dll_empty(l1));
	assert(dll_empty(l2));

	printf("Filling two dlls with 2 * %d items...\n", amt);
	for (i = 0; i < amt; ++i) {
		x.num = i;
		l1 = dll_prepend_head(l1, x);
		l2 = dll_prepend_head(l2, x);
		assert(!dll_empty(l1));
		assert(!dll_empty(l2));
		l1 = dll_append_head(l1, x);
		l2 = dll_append_head(l2, x);
		assert(!dll_empty(l1));
		assert(!dll_empty(l2));
	}

	/* Do some funky inserting at a `random' position. */
	dll_append_head(dll_forward(l1, 1), x);
	assert(x.num == dll_get_data(dll_forward(l1, 1)).num);
	dll_remove_head(dll_forward(l1, 2), NULL);

	l1 = dll_append(l1, l2);
	assert(dll_count(l1) == (unsigned int)(4 * amt));

	/* From now on, l2 is `invalid' */

	printf("Removing 2 * 2 * %d items from the appended dll...\n", amt);
	for (i = 0; i < (2 * amt); ++i) {
		assert(!dll_empty(l1));
		x = dll_get_data(l1);
		l1 = dll_remove_head(l1, NULL);
		assert(!dll_empty(l1));
		y = dll_get_data(l1);
		l1 = dll_remove_head(l1, NULL);

		/*
		 * We have to count backwards in this check, since we're
		 * using the list like a stack, prepending all the time.
		 */
		assert(x.num == amt - (i % amt) - 1);
		assert(x.num == y.num);
	}
	assert(dll_empty(l1));
	dll_destroy(l1, NULL);
}
Exemplo n.º 2
0
/**
 * \fn     que_Dequeue
 * \brief  Dequeue an item
 *
 * Dequeue an item from the queue's head
 *
 * \note
 * \param  h_que - The queue object
 * \return pointer to dequeued item or NULL if queue is empty
 * \sa     que_Enqueue, que_Requeue
 */
nfc_handle_t que_dequeue (nfc_handle_t h_que)
{
	struct queue   	*p_que = (struct queue *)h_que;
	nfc_handle_t 		h_item;
	struct  dll_node 	*p_node;

	if (p_que->u_count)
	{
		/* Queue is not empty, take packet from the queue head and
		 * find pointer to the node entry
		 */
		p_node = dll_remove_head (&p_que->head);
		h_item = ((struct q_item *)p_node)->h_item;
		osa_mem_free (p_node);
		p_que->u_count--;
		return (h_item);
	}

	/* Queue is empty */
	return NULL;
}