mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
core/queue: queue -> priority_queue
Rename queue to priority queue, because that's what it is.
This commit is contained in:
parent
d0a94945df
commit
c2b2e4554b
@ -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.
|
||||
|
85
core/include/priority_queue.h
Normal file
85
core/include/priority_queue.h
Normal file
@ -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 <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#ifndef __QUEUE_H
|
||||
#define __QUEUE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* 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 */
|
@ -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 <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#ifndef __QUEUE_H
|
||||
#define __QUEUE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* 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 */
|
@ -21,7 +21,7 @@
|
||||
#define TCB_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#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 */
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 <kaspar@schleiser.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
}
|
@ -21,7 +21,7 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#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;
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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 <errno.h>
|
||||
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -22,13 +22,12 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#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)
|
||||
|
@ -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;
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
@ -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_ */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user