voxelman/containers/voxelman_queue.h

57 lines
794 B
C
Raw Normal View History

#ifndef VOXELMAN_QUEUE_H
#define VOXELMAN_QUEUE_H
#include "core/reference.h"
#include "core/os/copymem.h"
#include "core/os/memory.h"
#include "core/os/rw_lock.h"
#include "core/variant.h"
2020-01-09 04:29:05 +01:00
template <class T>
class VMQueue {
public:
2020-01-09 04:29:05 +01:00
void enqueue(T obj);
T dequeue();
T peek();
2020-01-09 04:29:05 +01:00
void resize(int new_size);
2020-01-09 04:29:05 +01:00
VMQueue(int initial_size);
VMQueue();
~VMQueue();
protected:
2020-01-09 04:29:05 +01:00
void _resize(int new_size);
private:
2020-01-09 04:29:05 +01:00
RWLock *_lock;
2020-01-09 04:29:05 +01:00
int _head;
int _count;
int _size;
T *_items;
};
class VoxelmanQueue : public Reference {
2020-01-09 04:29:05 +01:00
GDCLASS(VoxelmanQueue, Reference);
public:
2020-01-09 04:29:05 +01:00
void enqueue(Variant obj);
Variant dequeue();
Variant peek();
2020-01-09 04:29:05 +01:00
void resize(int new_size);
2020-01-09 04:29:05 +01:00
VoxelmanQueue();
~VoxelmanQueue();
protected:
2020-01-09 04:29:05 +01:00
static void _bind_methods();
private:
2020-01-09 04:29:05 +01:00
VMQueue<Variant> _queue;
};
#endif