aboutsummaryrefslogtreecommitdiff
path: root/Src/nu/ThreadQueue.h
blob: 0fc9fb2305e5f0f634e066d7ba77f0747dd58059 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once
#include "RingBuffer.h"
#include <semaphore.h>

class ThreadQueue
{
public:
	ThreadQueue();
	~ThreadQueue();
	void Queue(const void *);
	// Get() blocks until there's something in the queue
	void *Get();
	// return value is same as sem_wait
	// delay is in nanoseconds
	int Wait(long delay, void **val);
	// kind of like sem_trywait
	int Try(void **val);
private:
	// TODO: need to use something safer than RingBuffer, preferably a lock-free linked list so we can grow unlimited
	 RingBuffer buffer;
	sem_t event;
};