make archives for current stage
This commit is contained in:
@@ -7,18 +7,38 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <vector>
|
||||
#include <forward_list>
|
||||
|
||||
#include <type_traits>
|
||||
template <typename T>
|
||||
struct Message {
|
||||
struct QNode {
|
||||
std::unique_ptr<T> payload;
|
||||
volatile std::atomic<QNode*> next;
|
||||
|
||||
QNode() = default;
|
||||
|
||||
explicit QNode(T&& payload):
|
||||
payload(std::forward<T>(payload)) {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Queue {
|
||||
std::forward_list<Message<T>> queue;
|
||||
};
|
||||
class Queue {
|
||||
private:
|
||||
volatile std::atomic<QNode<T>*> head;
|
||||
volatile std::atomic<QNode<T>*> tail;
|
||||
public:
|
||||
void push(T&& payload) {
|
||||
QNode<T>* node = new QNode(std::forward<T>(payload));
|
||||
node->next = node;
|
||||
|
||||
template <typename T>
|
||||
struct Tunnel {};
|
||||
QNode<T>* _tail = tail;
|
||||
QNode<T>* _next = _tail->next;
|
||||
|
||||
do {
|
||||
node->next = _next;
|
||||
} while (!_tail->next.compare_exchange_weak(_next, node));
|
||||
|
||||
tail.compare_exchange_strong(_tail, node);
|
||||
}
|
||||
std::unique_ptr<T> pop() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user