forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunnableQueue.cpp
More file actions
31 lines (29 loc) · 804 Bytes
/
RunnableQueue.cpp
File metadata and controls
31 lines (29 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) 2011-2012, Richard Osborne, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#include "RunnableQueue.h"
void RunnableQueue::push(Runnable &thread, ticks_t time)
{
if (contains(thread)) {
remove(thread);
}
thread.wakeUpTime = time;
if (!head) {
thread.next = 0;
head = &thread;
} else if (time < head->wakeUpTime) {
head->prev = &thread;
thread.next = head;
head = &thread;
} else {
Runnable *p = head;
while (p->next && time >= p->next->wakeUpTime)
p = p->next;
thread.prev = p;
thread.next = p->next;
if (p->next)
p->next->prev = &thread;
p->next = &thread;
}
}