mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-12 07:03:34 +00:00
adding async chunk generation
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <ScopMaths.h>
|
||||
|
||||
@@ -42,4 +45,36 @@ namespace std
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class ThreadSafeQueue
|
||||
{
|
||||
public:
|
||||
inline void Push(T item)
|
||||
{
|
||||
const std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_queue.push(item);
|
||||
m_cond.notify_one();
|
||||
}
|
||||
|
||||
inline T Pop()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_cond.wait(lock, [this]() { return !m_queue.empty(); });
|
||||
T item = m_queue.front();
|
||||
m_queue.pop();
|
||||
return item;
|
||||
}
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
const std::unique_lock<std::mutex> lock(m_mutex);
|
||||
return m_queue.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
std::queue<T> m_queue;
|
||||
mutable std::mutex m_mutex;
|
||||
std::condition_variable m_cond;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user