From c2b2e4554bd78333cea135c9da548e0dcdeb50fa Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 29 Jul 2014 09:21:11 +0200 Subject: [PATCH] core/queue: queue -> priority_queue Rename queue to priority queue, because that's what it is. --- core/include/mutex.h | 6 +- core/include/priority_queue.h | 85 ++++++++++++++++++ core/include/queue.h | 85 ------------------ core/include/tcb.h | 4 +- core/msg.c | 8 +- core/mutex.c | 8 +- core/{queue.c => priority_queue.c} | 30 ++++--- sys/include/vtimer.h | 4 +- sys/posix/include/semaphore.h | 4 +- sys/posix/pthread/include/pthread_cond.h | 2 +- sys/posix/pthread/include/pthread_rwlock.h | 6 +- sys/posix/pthread/pthread.c | 2 +- sys/posix/pthread/pthread_cond.c | 10 +-- sys/posix/pthread/pthread_rwlock.c | 10 +-- sys/posix/semaphore.c | 6 +- sys/vtimer/vtimer.c | 41 +++++---- ...re-queue.c => tests-core-priority-queue.c} | 86 +++++++++---------- tests/unittests/tests-core/tests-core.c | 2 +- tests/unittests/tests-core/tests-core.h | 4 +- 19 files changed, 202 insertions(+), 201 deletions(-) create mode 100644 core/include/priority_queue.h delete mode 100644 core/include/queue.h rename core/{queue.c => priority_queue.c} (61%) rename tests/unittests/tests-core/{tests-core-queue.c => tests-core-priority-queue.c} (50%) diff --git a/core/include/mutex.h b/core/include/mutex.h index db4c1649a5..e13068ad05 100644 --- a/core/include/mutex.h +++ b/core/include/mutex.h @@ -21,7 +21,7 @@ #ifndef __MUTEX_H_ #define __MUTEX_H_ -#include "queue.h" +#include "priority_queue.h" /** * @brief Mutex structure. Must never be modified by the user. @@ -39,14 +39,14 @@ typedef struct mutex_t { * by the user.** * @internal */ - queue_t queue; + priority_queue_t queue; } mutex_t; /** * @brief Static initializer for mutex_t. * @details This initializer is preferable to mutex_init(). */ -#define MUTEX_INIT { 0, QUEUE_INIT } +#define MUTEX_INIT { 0, PRIORITY_QUEUE_INIT } /** * @brief Initializes a mutex object. diff --git a/core/include/priority_queue.h b/core/include/priority_queue.h new file mode 100644 index 0000000000..1a4391c2a3 --- /dev/null +++ b/core/include/priority_queue.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2013, 2014 Freie Universität Berlin + * + * This file 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. + */ + +/** + * @addtogroup core_util + * @{ + * + * @file priority_queue.h + * @brief A simple priority queue + * + * @author Kaspar Schleiser + */ + +#ifndef __QUEUE_H +#define __QUEUE_H + +#include +#include + +/** + * data type for priority queue nodes + */ +typedef struct priority_queue_node_t { + struct priority_queue_node_t *next; /**< next queue node */ + unsigned int data; /**< queue node data */ + uint32_t priority; /**< queue node priority */ +} priority_queue_node_t; + +/** + * data type for priority queues + */ +typedef struct queue { + priority_queue_node_t *first; /**< first queue node */ +} priority_queue_t; + +/** + * @brief Static initializer for priority_queue_node_t. + */ +#define PRIORITY_QUEUE_NODE_INIT { NULL, 0, 0 } + +/** + * @brief Static initializer for priority_queue_t. + */ +#define PRIORITY_QUEUE_INIT { NULL } + +/** + * @brief remove the priority queue's head + * + * @param[out] root the queue's root + * + * @return the old head + */ +priority_queue_node_t *priority_queue_remove_head(priority_queue_t *root); + +/** + * @brief insert `new_obj` into `root` based on its priority + * + * @details + * The new object will be appended after objects with the same priority. + * + * @param[in,out] root the queue's root + * @param[in] new_obj the object to prepend + */ +void priority_queue_add(priority_queue_t *root, priority_queue_node_t *new_obj); + +/** + * @brief remove `node` from `root` + * + * @param[in,out] root the priority queue's root + * @param[in] node the node to remove + */ +void priority_queue_remove(priority_queue_t *root, priority_queue_node_t *node); + +#if ENABLE_DEBUG +void priority_queue_print(priority_queue_t *root); +void priority_queue_print_node(priority_queue_t *root); +#endif + +/** @} */ +#endif /* __QUEUE_H */ diff --git a/core/include/queue.h b/core/include/queue.h deleted file mode 100644 index 990ef2ab97..0000000000 --- a/core/include/queue.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2013 Freie Universität Berlin - * - * This file 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. - */ - -/** - * @addtogroup core_util - * @{ - * - * @file queue.h - * @brief A simple queue implementation - * - * @author Kaspar Schleiser - */ - -#ifndef __QUEUE_H -#define __QUEUE_H - -#include -#include - -/** - * data type for priority queue nodes - */ -typedef struct queue_node_t { - struct queue_node_t *next; /**< next queue node */ - unsigned int data; /**< queue node data */ - uint32_t priority; /**< queue node priority */ -} queue_node_t; - -/** - * data type for priority queues - */ -typedef struct queue { - queue_node_t *first; /**< first queue node */ -} queue_t; - -/** - * @brief Static initializer for queue_node_t. - */ -#define QUEUE_NODE_INIT { NULL, 0, 0 } - -/** - * @brief Static initializer for queue_t. - */ -#define QUEUE_INIT { NULL } - -/** - * @brief remove the queue's head - * - * @param[out] root the queue's root - * - * @return the old head - */ -queue_node_t *queue_remove_head(queue_t *root); - -/** - * @brief insert `new_obj` into `root` based on its priority - * - * @details - * The new object will be appended after objects with the same priority. - * - * @param[in,out] root the queue's root - * @param[in] new_obj the object to prepend - */ -void queue_priority_add(queue_t *root, queue_node_t *new_obj); - -/** - * @brief remove `node` from `root` - * - * @param[in,out] root the queue's root - * @param[in] node the node to remove - */ -void queue_remove(queue_t *root, queue_node_t *node); - -#if ENABLE_DEBUG -void queue_print(queue_t *root); -void queue_print_node(queue_t *root); -#endif - -/** @} */ -#endif /* __QUEUE_H */ diff --git a/core/include/tcb.h b/core/include/tcb.h index 027d18ad1e..c4e7fb21ff 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -21,7 +21,7 @@ #define TCB_H_ #include -#include "queue.h" +#include "priority_queue.h" #include "clist.h" #include "cib.h" #include "msg.h" @@ -65,7 +65,7 @@ typedef struct tcb_t { clist_node_t rq_entry; /**< run queue entry */ void *wait_data; /**< holding messages */ - queue_t msg_waiters; /**< threads waiting on message */ + priority_queue_t msg_waiters; /**< threads waiting on message */ cib_t msg_queue; /**< message queue */ msg_t *msg_array; /**< memory holding messages */ diff --git a/core/msg.c b/core/msg.c index c27b547f53..4077712c6e 100644 --- a/core/msg.c +++ b/core/msg.c @@ -25,7 +25,7 @@ #include "kernel.h" #include "sched.h" #include "msg.h" -#include "queue.h" +#include "priority_queue.h" #include "tcb.h" #include "irq.h" #include "cib.h" @@ -93,13 +93,13 @@ int msg_send(msg_t *m, kernel_pid_t target_pid, bool block) } DEBUG("msg_send: %s: send_blocked.\n", sched_active_thread->name); - queue_node_t n; + priority_queue_node_t n; n.priority = sched_active_thread->priority; n.data = (unsigned int) sched_active_thread; n.next = NULL; DEBUG("msg_send: %s: Adding node to msg_waiters:\n", sched_active_thread->name); - queue_priority_add(&(target->msg_waiters), &n); + priority_queue_add(&(target->msg_waiters), &n); sched_active_thread->wait_data = (void*) m; @@ -262,7 +262,7 @@ static int _msg_receive(msg_t *m, int block) me->wait_data = (void *) m; } - queue_node_t *node = queue_remove_head(&(me->msg_waiters)); + priority_queue_node_t *node = priority_queue_remove_head(&(me->msg_waiters)); if (node == NULL) { DEBUG("_msg_receive: %s: _msg_receive(): No thread in waiting list.\n", sched_active_thread->name); diff --git a/core/mutex.c b/core/mutex.c index ed63172cee..318e34be4a 100644 --- a/core/mutex.c +++ b/core/mutex.c @@ -66,14 +66,14 @@ static void mutex_wait(struct mutex_t *mutex) sched_set_status((tcb_t*) sched_active_thread, STATUS_MUTEX_BLOCKED); - queue_node_t n; + priority_queue_node_t n; n.priority = (unsigned int) sched_active_thread->priority; n.data = (unsigned int) sched_active_thread; n.next = NULL; DEBUG("%s: Adding node to mutex queue: prio: %" PRIu32 "\n", sched_active_thread->name, n.priority); - queue_priority_add(&(mutex->queue), &n); + priority_queue_add(&(mutex->queue), &n); restoreIRQ(irqstate); @@ -88,7 +88,7 @@ void mutex_unlock(struct mutex_t *mutex) int irqstate = disableIRQ(); if (mutex->val != 0) { - queue_node_t *next = queue_remove_head(&(mutex->queue)); + priority_queue_node_t *next = priority_queue_remove_head(&(mutex->queue)); if (next) { tcb_t *process = (tcb_t *) next->data; DEBUG("%s: waking up waiter.\n", process->name); @@ -110,7 +110,7 @@ void mutex_unlock_and_sleep(struct mutex_t *mutex) int irqstate = disableIRQ(); if (mutex->val != 0) { - queue_node_t *next = queue_remove_head(&(mutex->queue)); + priority_queue_node_t *next = priority_queue_remove_head(&(mutex->queue)); if (next) { tcb_t *process = (tcb_t *) next->data; DEBUG("%s: waking up waiter.\n", process->name); diff --git a/core/queue.c b/core/priority_queue.c similarity index 61% rename from core/queue.c rename to core/priority_queue.c index 7a3260d44f..6e1f2a1299 100644 --- a/core/queue.c +++ b/core/priority_queue.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Freie Universität Berlin + * Copyright (C) 2013, 2014 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -10,22 +10,24 @@ * @ingroup core_util * @{ * - * @file queue.c - * @brief A simple queue implementation + * @file priority_queue.c + * @brief A simple priority queue * * @author Kaspar Schleiser * @} */ #include -#include -#include "queue.h" +#include "priority_queue.h" -void queue_remove(queue_t *root_, queue_node_t *node) +#define ENABLE_DEBUG (0) +#include "debug.h" + +void priority_queue_remove(priority_queue_t *root_, priority_queue_node_t *node) { /* The strict aliasing rules allow this assignment. */ - queue_node_t *root = (queue_node_t *) root_; + priority_queue_node_t *root = (priority_queue_node_t *) root_; while (root->next != NULL) { if (root->next == node) { @@ -38,19 +40,19 @@ void queue_remove(queue_t *root_, queue_node_t *node) } } -queue_node_t *queue_remove_head(queue_t *root) +priority_queue_node_t *priority_queue_remove_head(priority_queue_t *root) { - queue_node_t *head = root->first; + priority_queue_node_t *head = root->first; if (head) { root->first = head->next; } return head; } -void queue_priority_add(queue_t *root, queue_node_t *new_obj) +void priority_queue_add(priority_queue_t *root, priority_queue_node_t *new_obj) { /* The strict aliasing rules allow this assignment. */ - queue_node_t *node = (queue_node_t *) root; + priority_queue_node_t *node = (priority_queue_node_t *) root; while (node->next != NULL) { if (node->next->priority > new_obj->priority) { @@ -67,16 +69,16 @@ void queue_priority_add(queue_t *root, queue_node_t *new_obj) } #if ENABLE_DEBUG -void queue_print(queue_t *node) +void priority_queue_print(priority_queue_t *node) { printf("queue:\n"); - for (queue_node_t *node = node->first; node; node = node->next) { + for (priority_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) +void priority_queue_print_node(priority_queue_node_t *node) { printf("Data: %u Priority: %lu Next: %u\n", (unsigned int) node->data, (unsigned long) node->priority, (unsigned int)node->next); } diff --git a/sys/include/vtimer.h b/sys/include/vtimer.h index 95829862c5..7b32d83f0a 100644 --- a/sys/include/vtimer.h +++ b/sys/include/vtimer.h @@ -21,7 +21,7 @@ #include #include -#include "queue.h" +#include "priority_queue.h" #include "timex.h" #include "msg.h" @@ -35,7 +35,7 @@ * \hideinitializer */ typedef struct vtimer_t { - queue_node_t queue_entry; + priority_queue_node_t priority_queue_entry; timex_t absolute; void (*action)(struct vtimer_t *timer); void *arg; diff --git a/sys/posix/include/semaphore.h b/sys/posix/include/semaphore.h index 169d7f9b3b..60e3597506 100644 --- a/sys/posix/include/semaphore.h +++ b/sys/posix/include/semaphore.h @@ -6,11 +6,11 @@ /** Value returned if `sem_open' failed. */ #define SEM_FAILED ((sem_t *) 0) -#include "queue.h" +#include "priority_queue.h" typedef struct sem { volatile unsigned int value; - queue_t queue; + priority_queue_t queue; } sem_t; /** diff --git a/sys/posix/pthread/include/pthread_cond.h b/sys/posix/pthread/include/pthread_cond.h index ea50b191c3..b3478e4bd3 100644 --- a/sys/posix/pthread/include/pthread_cond.h +++ b/sys/posix/pthread/include/pthread_cond.h @@ -33,7 +33,7 @@ typedef struct pthread_condattr_t { typedef struct pthread_cond_t { /* fields are managed by cv functions, don't touch */ - queue_t queue; /**< Threads currently waiting to be signaled. */ + priority_queue_t queue; /**< Threads currently waiting to be signaled. */ } pthread_cond_t; /** diff --git a/sys/posix/pthread/include/pthread_rwlock.h b/sys/posix/pthread/include/pthread_rwlock.h index 0408d7e295..0cb07e12ef 100644 --- a/sys/posix/pthread/include/pthread_rwlock.h +++ b/sys/posix/pthread/include/pthread_rwlock.h @@ -9,7 +9,7 @@ #ifndef __SYS__POSIX__PTHREAD_RWLOCK__H #define __SYS__POSIX__PTHREAD_RWLOCK__H -#include "queue.h" +#include "priority_queue.h" #include "tcb.h" #include @@ -36,7 +36,7 @@ typedef struct pthread_rwlock /** * @brief Queue of waiting threads. */ - queue_t queue; + priority_queue_t queue; /** * @brief Provides mutual exclusion on reading and writing on the structure. @@ -51,7 +51,7 @@ typedef struct __pthread_rwlock_waiter_node { bool is_writer; /**< `false`: reader; `true`: writer */ tcb_t *thread; /**< waiting thread */ - queue_node_t qnode; /**< Node to store in `pthread_rwlock_t::queue`. */ + priority_queue_node_t qnode; /**< Node to store in `pthread_rwlock_t::queue`. */ bool continue_; /**< This is not a spurious wakeup. */ } __pthread_rwlock_waiter_node_t; diff --git a/sys/posix/pthread/pthread.c b/sys/posix/pthread/pthread.c index 816bf5479b..fe70426ade 100644 --- a/sys/posix/pthread/pthread.c +++ b/sys/posix/pthread/pthread.c @@ -29,7 +29,7 @@ #include "kernel_internal.h" #include "msg.h" #include "mutex.h" -#include "queue.h" +#include "priority_queue.h" #include "thread.h" #include "sched.h" diff --git a/sys/posix/pthread/pthread_cond.c b/sys/posix/pthread/pthread_cond.c index 6bede33683..e2cf1c42cf 100644 --- a/sys/posix/pthread/pthread_cond.c +++ b/sys/posix/pthread/pthread_cond.c @@ -96,14 +96,14 @@ int pthread_cond_destroy(struct pthread_cond_t *cond) int pthread_cond_wait(struct pthread_cond_t *cond, struct mutex_t *mutex) { - queue_node_t n; + priority_queue_node_t n; n.priority = sched_active_thread->priority; n.data = sched_active_thread->pid; n.next = NULL; /* the signaling thread may not hold the mutex, the queue is not thread safe */ unsigned old_state = disableIRQ(); - queue_priority_add(&(cond->queue), &n); + priority_queue_add(&(cond->queue), &n); restoreIRQ(old_state); mutex_unlock_and_sleep(mutex); @@ -112,7 +112,7 @@ int pthread_cond_wait(struct pthread_cond_t *cond, struct mutex_t *mutex) /* on signaling n.data is set to -1u */ /* if it isn't set, then the wakeup is either spurious or a timer wakeup */ old_state = disableIRQ(); - queue_remove(&(cond->queue), &n); + priority_queue_remove(&(cond->queue), &n); restoreIRQ(old_state); } @@ -141,7 +141,7 @@ int pthread_cond_signal(struct pthread_cond_t *cond) { unsigned old_state = disableIRQ(); - queue_node_t *head = queue_remove_head(&(cond->queue)); + priority_queue_node_t *head = priority_queue_remove_head(&(cond->queue)); int other_prio = -1; if (head != NULL) { tcb_t *other_thread = (tcb_t *) sched_threads[head->data]; @@ -173,7 +173,7 @@ int pthread_cond_broadcast(struct pthread_cond_t *cond) int other_prio = -1; while (1) { - queue_node_t *head = queue_remove_head(&(cond->queue)); + priority_queue_node_t *head = priority_queue_remove_head(&(cond->queue)); if (head == NULL) { break; } diff --git a/sys/posix/pthread/pthread_rwlock.c b/sys/posix/pthread/pthread_rwlock.c index 88f91ef098..ed1e09d991 100644 --- a/sys/posix/pthread/pthread_rwlock.c +++ b/sys/posix/pthread/pthread_rwlock.c @@ -80,7 +80,7 @@ bool __pthread_rwlock_blocked_readingly(const pthread_rwlock_t *rwlock) return false; } - queue_node_t *qnode = rwlock->queue.first; + priority_queue_node_t *qnode = rwlock->queue.first; if (qnode->priority > sched_active_thread->priority) { /* the waiting thread has a lower priority */ return false; @@ -130,7 +130,7 @@ static int pthread_rwlock_lock(pthread_rwlock_t *rwlock, }, .continue_ = false, }; - queue_priority_add(&rwlock->queue, &waiting_node.qnode); + priority_queue_add(&rwlock->queue, &waiting_node.qnode); while (1) { /* wait to be unlocked, so this thread can try to acquire the lock again */ @@ -146,7 +146,7 @@ static int pthread_rwlock_lock(pthread_rwlock_t *rwlock, else if (allow_spurious) { DEBUG("Thread %" PRIkernel_pid ": pthread_rwlock_%s(): is_writer=%u, allow_spurious=%u %s\n", thread_pid, "lock", is_writer, allow_spurious, "is timed out"); - queue_remove(&rwlock->queue, &waiting_node.qnode); + priority_queue_remove(&rwlock->queue, &waiting_node.qnode); mutex_unlock(&rwlock->mutex); return ETIMEDOUT; } @@ -272,7 +272,7 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) } /* wake up the next thread */ - queue_node_t *qnode = queue_remove_head(&rwlock->queue); + priority_queue_node_t *qnode = priority_queue_remove_head(&rwlock->queue); __pthread_rwlock_waiter_node_t *waiting_node = (__pthread_rwlock_waiter_node_t *) qnode->data; waiting_node->continue_ = true; uint16_t prio = qnode->priority; @@ -302,7 +302,7 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) thread_pid, "unlock", "reader", waiting_node->thread->pid); /* wake up this reader */ - qnode = queue_remove_head(&rwlock->queue); + qnode = priority_queue_remove_head(&rwlock->queue); if (qnode->priority < prio) { prio = qnode->priority; } diff --git a/sys/posix/semaphore.c b/sys/posix/semaphore.c index 18630be52d..daa8f619f7 100644 --- a/sys/posix/semaphore.c +++ b/sys/posix/semaphore.c @@ -77,7 +77,7 @@ static void sem_thread_blocked(sem_t *sem) /* I'm going blocked */ sched_set_status((tcb_t*) sched_active_thread, STATUS_MUTEX_BLOCKED); - queue_node_t n; + priority_queue_node_t n; n.priority = (uint32_t) sched_active_thread->priority; n.data = (size_t) sched_active_thread; n.next = NULL; @@ -86,7 +86,7 @@ static void sem_thread_blocked(sem_t *sem) sched_active_thread->name, n.priority); /* add myself to the waiters queue */ - queue_priority_add(&sem->queue, &n); + priority_queue_add(&sem->queue, &n); /* scheduler should schedule an other thread, that unlocks the * mutex in the future, when this happens I get scheduled again @@ -142,7 +142,7 @@ int sem_post(sem_t *sem) int old_state = disableIRQ(); ++sem->value; - queue_node_t *next = queue_remove_head(&sem->queue); + priority_queue_node_t *next = priority_queue_remove_head(&sem->queue); if (next) { tcb_t *next_process = (tcb_t*) next->data; DEBUG("%s: waking up %s\n", sched_active_thread->name, next_process->name); diff --git a/sys/vtimer/vtimer.c b/sys/vtimer/vtimer.c index 93946679cd..43de93e5c4 100644 --- a/sys/vtimer/vtimer.c +++ b/sys/vtimer/vtimer.c @@ -22,13 +22,12 @@ #include #include "irq.h" -#include "queue.h" +#include "priority_queue.h" #include "timex.h" #include "hwtimer.h" #include "msg.h" #include "mutex.h" #include "thread.h" -#include "queue.h" #include "vtimer.h" @@ -50,8 +49,8 @@ static int vtimer_set(vtimer_t *timer); static int set_longterm(vtimer_t *timer); static int set_shortterm(vtimer_t *timer); -static queue_t longterm_queue_root; -static queue_t shortterm_queue_root; +static priority_queue_t longterm_priority_queue_root; +static priority_queue_t shortterm_priority_queue_root; static vtimer_t longterm_tick_timer; static uint32_t longterm_tick_start; @@ -64,21 +63,21 @@ static uint32_t seconds = 0; static int set_longterm(vtimer_t *timer) { - timer->queue_entry.priority = timer->absolute.seconds; - queue_priority_add(&longterm_queue_root, (queue_node_t *)timer); + timer->priority_queue_entry.priority = timer->absolute.seconds; + priority_queue_add(&longterm_priority_queue_root, (priority_queue_node_t *)timer); return 0; } static int update_shortterm(void) { - if (shortterm_queue_root.first == NULL) { + if (shortterm_priority_queue_root.first == NULL) { /* there is no vtimer to schedule, queue is empty */ - DEBUG("update_shortterm: shortterm_queue_root.next == NULL - dont know what to do here\n"); + DEBUG("update_shortterm: shortterm_priority_queue_root.next == NULL - dont know what to do here\n"); return 0; } if (hwtimer_id != -1) { /* there is a running hwtimer for us */ - if (hwtimer_next_absolute != shortterm_queue_root.first->priority) { + if (hwtimer_next_absolute != shortterm_priority_queue_root.first->priority) { /* the next timer in the vtimer queue is not the next hwtimer */ /* we have to remove the running hwtimer (and schedule a new one) */ hwtimer_remove(hwtimer_id); @@ -90,7 +89,7 @@ static int update_shortterm(void) } /* short term part of the next vtimer */ - hwtimer_next_absolute = shortterm_queue_root.first->priority; + hwtimer_next_absolute = shortterm_priority_queue_root.first->priority; uint32_t next = hwtimer_next_absolute; @@ -98,7 +97,7 @@ static int update_shortterm(void) uint32_t now = HWTIMER_TICKS_TO_US(hwtimer_now()); /* make sure the longterm_tick_timer does not get truncated */ - if (((vtimer_t *) shortterm_queue_root.first)->action != vtimer_callback_tick) { + if (((vtimer_t *) shortterm_priority_queue_root.first)->action != vtimer_callback_tick) { /* the next vtimer to schedule is the long term tick */ /* it has a shortterm offset of longterm_tick_start */ next += longterm_tick_start; @@ -126,11 +125,11 @@ void vtimer_callback_tick(vtimer_t *timer) longterm_tick_timer.absolute.microseconds += MICROSECONDS_PER_TICK; set_shortterm(&longterm_tick_timer); - while (longterm_queue_root.first) { - vtimer_t *timer = (vtimer_t *) longterm_queue_root.first; + while (longterm_priority_queue_root.first) { + vtimer_t *timer = (vtimer_t *) longterm_priority_queue_root.first; if (timer->absolute.seconds == seconds) { - queue_remove_head(&longterm_queue_root); + priority_queue_remove_head(&longterm_priority_queue_root); set_shortterm(timer); } else { @@ -161,8 +160,8 @@ static void vtimer_callback_unlock(vtimer_t *timer) static int set_shortterm(vtimer_t *timer) { DEBUG("set_shortterm(): Absolute: %" PRIu32 " %" PRIu32 "\n", timer->absolute.seconds, timer->absolute.microseconds); - timer->queue_entry.priority = timer->absolute.microseconds; - queue_priority_add(&shortterm_queue_root, (queue_node_t *)timer); + timer->priority_queue_entry.priority = timer->absolute.microseconds; + priority_queue_add(&shortterm_priority_queue_root, (priority_queue_node_t *)timer); return 1; } @@ -175,7 +174,7 @@ void vtimer_callback(void *ptr) hwtimer_id = -1; /* get the vtimer that fired */ - vtimer_t *timer = (vtimer_t *)queue_remove_head(&shortterm_queue_root); + vtimer_t *timer = (vtimer_t *)priority_queue_remove_head(&shortterm_priority_queue_root); if (timer) { #if ENABLE_DEBUG @@ -359,8 +358,8 @@ int vtimer_remove(vtimer_t *t) { unsigned int irq_state = disableIRQ(); - queue_remove(&shortterm_queue_root, (queue_node_t *)t); - queue_remove(&longterm_queue_root, (queue_node_t *)t); + priority_queue_remove(&shortterm_priority_queue_root, (priority_queue_node_t *)t); + priority_queue_remove(&longterm_priority_queue_root, (priority_queue_node_t *)t); update_shortterm(); restoreIRQ(irq_state); @@ -399,11 +398,11 @@ int vtimer_msg_receive_timeout(msg_t *m, timex_t timeout) { #if ENABLE_DEBUG void vtimer_print_short_queue(){ - queue_print(&shortterm_queue_root); + priority_queue_print(&shortterm_priority_queue_root); } void vtimer_print_long_queue(){ - queue_print(&longterm_queue_root); + priority_queue_print(&longterm_priority_queue_root); } void vtimer_print(vtimer_t *t) diff --git a/tests/unittests/tests-core/tests-core-queue.c b/tests/unittests/tests-core/tests-core-priority-queue.c similarity index 50% rename from tests/unittests/tests-core/tests-core-queue.c rename to tests/unittests/tests-core/tests-core-priority-queue.c index 280ca68e93..46f700f7bf 100644 --- a/tests/unittests/tests-core/tests-core-queue.c +++ b/tests/unittests/tests-core/tests-core-priority-queue.c @@ -9,14 +9,14 @@ #include "embUnit/embUnit.h" -#include "queue.h" +#include "priority_queue.h" #include "tests-core.h" #define Q_LEN (4) -static queue_t q; -static queue_node_t qe[Q_LEN]; +static priority_queue_t q; +static priority_queue_node_t qe[Q_LEN]; static void set_up(void) { @@ -24,44 +24,44 @@ static void set_up(void) memset(qe, 0, sizeof(qe)); } -static void test_queue_remove_head_empty(void) +static void test_priority_queue_remove_head_empty(void) { - queue_t *root = &q; - queue_node_t *res; + priority_queue_t *root = &q; + priority_queue_node_t *res; - res = queue_remove_head(root); + res = priority_queue_remove_head(root); TEST_ASSERT_NULL(res); } -static void test_queue_remove_head_one(void) +static void test_priority_queue_remove_head_one(void) { - queue_t *root = &q; - queue_node_t *elem = &(qe[1]), *res; + priority_queue_t *root = &q; + priority_queue_node_t *elem = &(qe[1]), *res; elem->data = 62801; - queue_priority_add(root, elem); + priority_queue_add(root, elem); - res = queue_remove_head(root); + res = priority_queue_remove_head(root); TEST_ASSERT(res == elem); TEST_ASSERT_EQUAL_INT(62801, res->data); - res = queue_remove_head(root); + res = priority_queue_remove_head(root); TEST_ASSERT_NULL(res); } -static void test_queue_priority_add_one(void) +static void test_priority_queue_add_one(void) { - queue_t *root = &q; - queue_node_t *elem = &(qe[1]); + priority_queue_t *root = &q; + priority_queue_node_t *elem = &(qe[1]); elem->data = 7317; elem->priority = 713643658; - queue_priority_add(root, elem); + priority_queue_add(root, elem); TEST_ASSERT(root->first == elem); TEST_ASSERT_EQUAL_INT(7317, root->first->data); @@ -70,10 +70,10 @@ static void test_queue_priority_add_one(void) TEST_ASSERT_NULL(root->first->next); } -static void test_queue_priority_add_two_equal(void) +static void test_priority_queue_add_two_equal(void) { - queue_t *root = &q; - queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]); + priority_queue_t *root = &q; + priority_queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]); elem1->data = 27088; elem1->priority = 14202; @@ -81,8 +81,8 @@ static void test_queue_priority_add_two_equal(void) elem2->data = 4356; elem2->priority = 14202; - queue_priority_add(root, elem1); - queue_priority_add(root, elem2); + priority_queue_add(root, elem1); + priority_queue_add(root, elem2); TEST_ASSERT(root->first == elem1); TEST_ASSERT_EQUAL_INT(27088, root->first->data); @@ -95,10 +95,10 @@ static void test_queue_priority_add_two_equal(void) TEST_ASSERT_NULL(root->first->next->next); } -static void test_queue_priority_add_two_distinct(void) +static void test_priority_queue_add_two_distinct(void) { - queue_t *root = &q; - queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]); + priority_queue_t *root = &q; + priority_queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]); elem1->data = 46421; elem1->priority = 4567; @@ -106,8 +106,8 @@ static void test_queue_priority_add_two_distinct(void) elem2->data = 43088; elem2->priority = 1234; - queue_priority_add(root, elem1); - queue_priority_add(root, elem2); + priority_queue_add(root, elem1); + priority_queue_add(root, elem2); TEST_ASSERT(root->first == elem2); TEST_ASSERT_EQUAL_INT(43088, root->first->data); @@ -120,34 +120,34 @@ static void test_queue_priority_add_two_distinct(void) TEST_ASSERT_NULL(root->first->next->next); } -static void test_queue_remove_one(void) +static void test_priority_queue_remove_one(void) { - queue_t *root = &q; - queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]), *elem3 = &(qe[3]); + priority_queue_t *root = &q; + priority_queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]), *elem3 = &(qe[3]); - queue_priority_add(root, elem1); - queue_priority_add(root, elem2); - queue_priority_add(root, elem3); - queue_remove(root, elem2); + priority_queue_add(root, elem1); + priority_queue_add(root, elem2); + priority_queue_add(root, elem3); + priority_queue_remove(root, elem2); TEST_ASSERT(root->first == elem1); TEST_ASSERT(root->first->next == elem3); TEST_ASSERT_NULL(root->first->next->next); } -Test *tests_core_queue_tests(void) +Test *tests_core_priority_queue_tests(void) { EMB_UNIT_TESTFIXTURES(fixtures) { - new_TestFixture(test_queue_remove_head_empty), - new_TestFixture(test_queue_remove_head_one), - new_TestFixture(test_queue_priority_add_one), - new_TestFixture(test_queue_priority_add_two_equal), - new_TestFixture(test_queue_priority_add_two_distinct), - new_TestFixture(test_queue_remove_one), + new_TestFixture(test_priority_queue_remove_head_empty), + new_TestFixture(test_priority_queue_remove_head_one), + new_TestFixture(test_priority_queue_add_one), + new_TestFixture(test_priority_queue_add_two_equal), + new_TestFixture(test_priority_queue_add_two_distinct), + new_TestFixture(test_priority_queue_remove_one), }; - EMB_UNIT_TESTCALLER(core_queue_tests, set_up, NULL, + EMB_UNIT_TESTCALLER(core_priority_queue_tests, set_up, NULL, fixtures); - return (Test *)&core_queue_tests; + return (Test *)&core_priority_queue_tests; } diff --git a/tests/unittests/tests-core/tests-core.c b/tests/unittests/tests-core/tests-core.c index 3682e087bd..0659925a61 100644 --- a/tests/unittests/tests-core/tests-core.c +++ b/tests/unittests/tests-core/tests-core.c @@ -15,5 +15,5 @@ void tests_core(void) TESTS_RUN(tests_core_cib_tests()); TESTS_RUN(tests_core_clist_tests()); TESTS_RUN(tests_core_lifo_tests()); - TESTS_RUN(tests_core_queue_tests()); + TESTS_RUN(tests_core_priority_queue_tests()); } diff --git a/tests/unittests/tests-core/tests-core.h b/tests/unittests/tests-core/tests-core.h index f5de0bb8bf..20805c4b9b 100644 --- a/tests/unittests/tests-core/tests-core.h +++ b/tests/unittests/tests-core/tests-core.h @@ -61,11 +61,11 @@ Test *tests_core_clist_tests(void); Test *tests_core_lifo_tests(void); /** - * @brief Generates tests queue.h + * @brief Generates tests priority_queue.h * * @return embUnit tests if successful, NULL if not. */ -Test *tests_core_queue_tests(void); +Test *tests_core_priority_queue_tests(void); #endif /* __TESTS_CORE_H_ */ /** @} */