forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RunnableQueue.h
58 lines (49 loc) · 1.11 KB
/
RunnableQueue.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// 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/>
#ifndef _RunnableQueue_h_
#define _RunnableQueue_h_
#include "Runnable.h"
#include <cassert>
class RunnableQueue {
private:
Runnable *head;
bool contains(Runnable &thread) const
{
return thread.prev != 0 || &thread == head;
}
public:
RunnableQueue() : head(0) {}
Runnable &front() const
{
return *head;
}
bool empty() const
{
return !head;
}
void remove(Runnable &thread)
{
assert(contains(thread));
if (&thread == head) {
head = thread.next;
} else {
thread.prev->next = thread.next;
}
if (thread.next)
thread.next->prev = thread.prev;
thread.prev = 0;
}
// Insert a thread into the queue.
void push(Runnable &thread, ticks_t time);
void pop()
{
assert(!empty());
if (head->next) {
head->next->prev = 0;
}
head = head->next;
}
};
#endif // _RunnableQueue_h_