Browse Source

core: assertion not to add twice to priority_queue

cc430
Oleg Hahm 7 years ago
parent
commit
07e2505ebd
  1. 2
      core/include/priority_queue.h
  2. 3
      core/priority_queue.c

2
core/include/priority_queue.h

@ -98,6 +98,8 @@ priority_queue_node_t *priority_queue_remove_head(priority_queue_t *root);
*
* @param[in,out] root the queue's root
* @param[in] new_obj the object to prepend
*
* @pre The queue does not already contain @p new_obj.
*/
void priority_queue_add(priority_queue_t *root, priority_queue_node_t *new_obj);

3
core/priority_queue.c

@ -18,6 +18,7 @@
*/
#include <inttypes.h>
#include <assert.h>
#include "priority_queue.h"
@ -55,6 +56,8 @@ void priority_queue_add(priority_queue_t *root, priority_queue_node_t *new_obj)
priority_queue_node_t *node = (priority_queue_node_t *) root;
while (node->next != NULL) {
/* not trying to add the same node twice */
assert(node->next != new_obj);
if (node->next->priority > new_obj->priority) {
new_obj->next = node->next;
node->next = new_obj;

Loading…
Cancel
Save