mirror of https://github.com/deavmi/eventy.git
Added a few methods for adding to the queue, checking if it is empoty and popping from the queue
This commit is contained in:
parent
29afd37f38
commit
333ae361a8
|
@ -1,5 +1,10 @@
|
||||||
module eventy.queues;
|
module eventy.queues;
|
||||||
|
|
||||||
|
import eventy.event : Event;
|
||||||
|
import core.sync.mutex : Mutex;
|
||||||
|
import std.container.dlist;
|
||||||
|
import std.range;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue
|
* Queue
|
||||||
*
|
*
|
||||||
|
@ -8,6 +13,52 @@ module eventy.queues;
|
||||||
*/
|
*/
|
||||||
public final class Queue
|
public final class Queue
|
||||||
{
|
{
|
||||||
private ulong id;
|
public ulong id;
|
||||||
/* TODO: Add queue of Event's here */
|
/* TODO: Add queue of Event's here */
|
||||||
|
|
||||||
|
private DList!(Event) queue;
|
||||||
|
private Mutex queueLock;
|
||||||
|
|
||||||
|
|
||||||
|
public void add(Event e)
|
||||||
|
{
|
||||||
|
/* Lock the queue */
|
||||||
|
queueLock.lock();
|
||||||
|
|
||||||
|
queue.insert(e);
|
||||||
|
|
||||||
|
/* Unlock the queue */
|
||||||
|
queueLock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool hasEvents()
|
||||||
|
{
|
||||||
|
bool has;
|
||||||
|
|
||||||
|
/* Lock the queue */
|
||||||
|
queueLock.lock();
|
||||||
|
|
||||||
|
has = (queue[]).empty();
|
||||||
|
|
||||||
|
/* Unlock the queue */
|
||||||
|
queueLock.unlock();
|
||||||
|
|
||||||
|
return has;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Event popEvent()
|
||||||
|
{
|
||||||
|
Event poppedEvent;
|
||||||
|
|
||||||
|
/* Lock the queue */
|
||||||
|
queueLock.lock();
|
||||||
|
|
||||||
|
poppedEvent = (queue[]).front();
|
||||||
|
(queue[]).popFront();
|
||||||
|
|
||||||
|
/* Unlock the queue */
|
||||||
|
queueLock.unlock();
|
||||||
|
|
||||||
|
return poppedEvent;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue