mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-17 22:00:00 +00:00
clang format
This commit is contained in:
@@ -7,55 +7,51 @@
|
||||
#include <queue>
|
||||
#include <semaphore>
|
||||
|
||||
template <class T, size_t Size>
|
||||
template<class T, size_t Size>
|
||||
class atomic_queue {
|
||||
public:
|
||||
bool try_pop(T& val) {
|
||||
lock_guard guard(semaphore);
|
||||
if (queue.empty())
|
||||
return false;
|
||||
val = queue.front();
|
||||
queue.pop();
|
||||
full.release();
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
bool try_pop(T& val) {
|
||||
lock_guard guard(semaphore);
|
||||
if (queue.empty()) return false;
|
||||
val = queue.front();
|
||||
queue.pop();
|
||||
full.release();
|
||||
return true;
|
||||
}
|
||||
|
||||
void push(const T& val) {
|
||||
check_full();
|
||||
lock_guard guard(semaphore);
|
||||
queue.push(val);
|
||||
}
|
||||
void push(const T& val) {
|
||||
check_full();
|
||||
lock_guard guard(semaphore);
|
||||
queue.push(val);
|
||||
}
|
||||
|
||||
size_t size() {
|
||||
lock_guard guard(semaphore);
|
||||
return queue.size();
|
||||
}
|
||||
size_t size() {
|
||||
lock_guard guard(semaphore);
|
||||
return queue.size();
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
lock_guard guard(semaphore);
|
||||
return queue.empty();
|
||||
}
|
||||
bool empty() {
|
||||
lock_guard guard(semaphore);
|
||||
return queue.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
void check_full() {
|
||||
if (size() >= Size) {
|
||||
full.acquire();
|
||||
}
|
||||
}
|
||||
private:
|
||||
void check_full() {
|
||||
if (size() >= Size) {
|
||||
full.acquire();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
struct lock_guard {
|
||||
explicit lock_guard(std::binary_semaphore& lock)
|
||||
: lock(lock) {
|
||||
lock.acquire();
|
||||
}
|
||||
~lock_guard() {
|
||||
lock.release();
|
||||
}
|
||||
private:
|
||||
struct lock_guard {
|
||||
explicit lock_guard(std::binary_semaphore& lock) : lock(lock) {
|
||||
lock.acquire();
|
||||
}
|
||||
~lock_guard() { lock.release(); }
|
||||
|
||||
private:
|
||||
std::binary_semaphore& lock;
|
||||
};
|
||||
std::binary_semaphore semaphore { 1 }, full { 0 };
|
||||
std::queue<T> queue {};
|
||||
private:
|
||||
std::binary_semaphore& lock;
|
||||
};
|
||||
std::binary_semaphore semaphore{1}, full{0};
|
||||
std::queue<T> queue{};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user