tristanable/source/tristanable/queue.d

65 lines
1.2 KiB
D
Raw Normal View History

2020-09-29 09:57:25 +00:00
module tristanable.queue;
2023-03-27 13:41:50 +00:00
// TODO: Examine the below import which seemingly fixes stuff for libsnooze
import libsnooze.clib;
import libsnooze;
2023-03-27 13:41:50 +00:00
import tristanable.queueitem : QueueItem;
import core.sync.mutex : Mutex;
2023-02-26 19:55:13 +00:00
public class Queue
2020-09-29 09:57:25 +00:00
{
/**
* Everytime a thread calls `.dequeue()` on this queue
*
*/
private Event event;
private QueueItem queue;
private Mutex queueLock;
2023-03-27 13:41:50 +00:00
/**
* This queue's unique ID
*/
private ulong queueID;
2023-02-26 19:55:13 +00:00
private this()
{
/* Initialize the queue lock */
this.queueLock = new Mutex();
/* Initialize the event */
this.event = new Event();
}
2020-09-29 09:57:25 +00:00
public void dequeue()
{
2023-03-27 13:41:50 +00:00
try
{
// TODO: Make us wait on the event (optional with a time-out)
event.wait();
}
catch(SnoozeError snozErr)
{
// TODO: Add error handling for libsnooze exceptions here
}
// TODO: Lock queue
queueLock.lock();
// TODO: Get item off queue
// TODO: Unlock queue
queueLock.unlock();
2023-02-26 19:55:13 +00:00
}
2020-09-29 09:57:25 +00:00
2023-02-26 19:55:13 +00:00
public static Queue newQueue(ulong queueID)
{
Queue queue;
2020-09-29 09:57:25 +00:00
2023-02-26 19:55:13 +00:00
// TODO: Implement me
2020-09-29 09:57:25 +00:00
2023-02-26 19:55:13 +00:00
return queue;
}
2020-09-29 09:57:25 +00:00
}