1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/core/queue.c

84 lines
1.8 KiB
C
Raw Normal View History

/*
* Copyright (C) 2013 Freie Universität Berlin
*
2013-11-22 20:47:05 +01:00
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup core_util
* @{
*
* @file queue.c
* @brief A simple queue implementation
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @}
*/
#include <inttypes.h>
2013-07-24 00:44:28 +02:00
#include <stdio.h>
#include "queue.h"
2014-05-07 00:41:21 +02:00
void queue_remove(queue_t *root_, queue_node_t *node)
{
2014-05-07 00:41:21 +02:00
/* The strict aliasing rules allow this assignment. */
queue_node_t *root = (queue_node_t *) root_;
while (root->next != NULL) {
if (root->next == node) {
root->next = node->next;
node->next = NULL;
return;
}
root = root->next;
}
}
2014-05-07 00:41:21 +02:00
queue_node_t *queue_remove_head(queue_t *root)
{
2014-05-07 00:41:21 +02:00
queue_node_t *head = root->first;
if (head) {
root->first = head->next;
}
return head;
}
2014-05-07 00:41:21 +02:00
void queue_priority_add(queue_t *root, queue_node_t *new_obj)
{
2014-05-07 00:41:21 +02:00
/* The strict aliasing rules allow this assignment. */
queue_node_t *node = (queue_node_t *) root;
while (node->next != NULL) {
if (node->next->priority > new_obj->priority) {
new_obj->next = node->next;
node->next = new_obj;
return;
}
node = node->next;
}
node->next = new_obj;
new_obj->next = NULL;
}
2013-10-10 17:06:41 +02:00
#if ENABLE_DEBUG
2014-05-07 00:41:21 +02:00
void queue_print(queue_t *node)
{
printf("queue:\n");
2014-05-07 00:41:21 +02:00
for (queue_node_t *node = node->first; node; node = node->next) {
printf("Data: %u Priority: %lu\n", node->data, (unsigned long) node->priority);
}
}
void queue_print_node(queue_node_t *node)
{
printf("Data: %u Priority: %lu Next: %u\n", (unsigned int) node->data, (unsigned long) node->priority, (unsigned int)node->next);
}
2013-10-10 17:06:41 +02:00
#endif