Reformat to clang-format

This commit is contained in:
Anonymous275
2022-07-26 10:43:25 +03:00
parent 54af98203f
commit b26fb43746
25 changed files with 549 additions and 475 deletions

View File

@@ -1,17 +1,19 @@
//
// Created by Anonymous275 on 24/07/22.
//
///
/// Created by Anonymous275 on 7/26/22
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
///
#pragma once
#include <semaphore>
#include <queue>
#include <semaphore>
template <class T, size_t Size>
class atomic_queue {
public:
bool try_pop(T& val) {
lock_guard guard(semaphore);
if(queue.empty())return false;
if (queue.empty())
return false;
val = queue.front();
queue.pop();
full.release();
@@ -33,24 +35,27 @@ public:
lock_guard guard(semaphore);
return queue.empty();
}
private:
void check_full() {
if(size() >= Size) {
if (size() >= Size) {
full.acquire();
}
}
private:
struct lock_guard {
explicit lock_guard(std::binary_semaphore& lock) : lock(lock){
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{};
std::binary_semaphore semaphore { 1 }, full { 0 };
std::queue<T> queue {};
};