Example #1
0
void k_queue_init(struct k_queue *queue)
{
	sys_slist_init(&queue->data_q);
	sys_dlist_init(&queue->wait_q);

	_INIT_OBJ_POLL_EVENT(queue);

	SYS_TRACING_OBJ_INIT(k_queue, queue);
}
Example #2
0
void k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list)
{
	__ASSERT(!sys_slist_is_empty(list), "list must not be empty");

	/*
	 * note: this works as long as:
	 * - the slist implementation keeps the next pointer as the first
	 *   field of the node object type
	 * - list->tail->next = NULL.
	 */
	k_queue_append_list(queue, list->head, list->tail);
	sys_slist_init(list);
}
Example #3
0
void main(void)
{
	int status = TC_FAIL;

	TC_PRINT("Starting slist test\n");

	TC_PRINT(" - Initializing the list\n");
	sys_slist_init(&test_list);

	if (!verify_emptyness(&test_list)) {
		TC_ERROR("*** test_list should be empty\n");
		goto end;
	}

	TC_PRINT(" - Appending node 1\n");
	sys_slist_append(&test_list, &test_node_1);
	if (!verify_content_amount(&test_list, 1)) {
		TC_ERROR("*** test_list has wrong content\n");
		goto end;
	}

	if (!verify_tail_head(&test_list, &test_node_1, &test_node_1, true)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	TC_PRINT(" - Finding and removing node 1\n");
	sys_slist_find_and_remove(&test_list, &test_node_1);
	if (!verify_emptyness(&test_list)) {
		TC_ERROR("*** test_list should be empty\n");
		goto end;
	}

	TC_PRINT(" - Prepending node 1\n");
	sys_slist_prepend(&test_list, &test_node_1);
	if (!verify_content_amount(&test_list, 1)) {
		TC_ERROR("*** test_list has wrong content\n");
		goto end;
	}

	if (!verify_tail_head(&test_list, &test_node_1, &test_node_1, true)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	TC_PRINT(" - Removing node 1\n");
	sys_slist_remove(&test_list, NULL, &test_node_1);
	if (!verify_emptyness(&test_list)) {
		TC_ERROR("*** test_list should be empty\n");
		goto end;
	}

	TC_PRINT(" - Appending node 1\n");
	sys_slist_append(&test_list, &test_node_1);
	TC_PRINT(" - Prepending node 2\n");
	sys_slist_prepend(&test_list, &test_node_2);

	if (!verify_content_amount(&test_list, 2)) {
		TC_ERROR("*** test_list has wrong content\n");
		goto end;
	}

	if (!verify_tail_head(&test_list, &test_node_2, &test_node_1, false)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	TC_PRINT(" - Appending node 3\n");
	sys_slist_append(&test_list, &test_node_3);

	if (!verify_content_amount(&test_list, 3)) {
		TC_ERROR("*** test_list has wrong content\n");
		goto end;
	}

	if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	if (sys_slist_peek_next(&test_node_2) != &test_node_1) {
		TC_ERROR("*** test_list node links are wrong\n");
		goto end;
	}

	TC_PRINT(" - Inserting node 4 after node 2\n");
	sys_slist_insert(&test_list, &test_node_2, &test_node_4);

	if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	if (sys_slist_peek_next(&test_node_2) != &test_node_4) {
		TC_ERROR("*** test_list node links are wrong\n");
		goto end;
	}

	TC_PRINT(" - Finding and removing node 1\n");
	sys_slist_find_and_remove(&test_list, &test_node_1);
	if (!verify_content_amount(&test_list, 3)) {
		TC_ERROR("*** test_list has wrong content\n");
		goto end;
	}

	if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	TC_PRINT(" - Removing node 3\n");
	sys_slist_remove(&test_list, &test_node_4, &test_node_3);
	if (!verify_content_amount(&test_list, 2)) {
		TC_ERROR("*** test_list has wrong content\n");
		goto end;
	}

	if (!verify_tail_head(&test_list, &test_node_2, &test_node_4, false)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	TC_PRINT(" - Removing node 4\n");
	sys_slist_remove(&test_list, &test_node_2, &test_node_4);
	if (!verify_content_amount(&test_list, 1)) {
		TC_ERROR("*** test_list has wrong content\n");
		goto end;
	}

	if (!verify_tail_head(&test_list, &test_node_2, &test_node_2, true)) {
		TC_ERROR("*** test_list head/tail are wrong\n");
		goto end;
	}

	TC_PRINT(" - Removing node 2\n");
	sys_slist_remove(&test_list, NULL, &test_node_2);
	if (!verify_emptyness(&test_list)) {
		TC_ERROR("*** test_list should be empty\n");
		goto end;
	}

	status = TC_PASS;

end:
	TC_END_RESULT(status);
	TC_END_REPORT(status);
}