- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 59
- 60
// https://github.com/mono/moon/blob/master/src/list.h#L87
class Queue {
protected:
MoonMutex lock;
List *list;
public:
Queue ();
~Queue ();
// convenience properties
bool IsEmpty ();
int Length ();
// convenience methods
void Clear (bool freeNodes);
void Push (List::Node *node);
List::Node *Pop ();
void Lock ();
void Unlock ();
// accessing the internal linked list directly requires manual Locking/Unlocking.
List *LinkedList ();
// copies the queue and empties the original
void MoveTo (Queue &queue);
};
// https://github.com/mono/moon/blob/master/src/list.cpp#L391
Queue::Queue ()
: lock (true)
{
list = new List ();
}
int
Queue::Length ()
{
int length;
Lock ();
length = list->Length ();
Unlock ();
return length;
}
void
Queue::MoveTo (Queue &queue)
{
List::Node *node;
while ((node = list->First ())) {
list->Unlink (node);
queue.Push (node);
}
}