summaryrefslogtreecommitdiffstats
path: root/src/common/fifo_queue.h
diff options
context:
space:
mode:
authorYuri Kunde Schlesner <yuriks@yuriks.net>2015-07-11 01:36:12 +0200
committerYuri Kunde Schlesner <yuriks@yuriks.net>2015-07-11 01:36:12 +0200
commit867c28ae03b3b2883713896765f3ff76eaf90a19 (patch)
tree8ff8cf3ab24d2f167c19217efb8175a8841c0359 /src/common/fifo_queue.h
parentMerge pull request #906 from aroulin/loader-format-specifier-warning (diff)
parentCore: Cleanup hw includes. (diff)
downloadyuzu-867c28ae03b3b2883713896765f3ff76eaf90a19.tar
yuzu-867c28ae03b3b2883713896765f3ff76eaf90a19.tar.gz
yuzu-867c28ae03b3b2883713896765f3ff76eaf90a19.tar.bz2
yuzu-867c28ae03b3b2883713896765f3ff76eaf90a19.tar.lz
yuzu-867c28ae03b3b2883713896765f3ff76eaf90a19.tar.xz
yuzu-867c28ae03b3b2883713896765f3ff76eaf90a19.tar.zst
yuzu-867c28ae03b3b2883713896765f3ff76eaf90a19.zip
Diffstat (limited to 'src/common/fifo_queue.h')
-rw-r--r--src/common/fifo_queue.h111
1 files changed, 0 insertions, 111 deletions
diff --git a/src/common/fifo_queue.h b/src/common/fifo_queue.h
deleted file mode 100644
index b426e6596..000000000
--- a/src/common/fifo_queue.h
+++ /dev/null
@@ -1,111 +0,0 @@
-#pragma once
-
-// a simple lockless thread-safe,
-// single reader, single writer queue
-
-#include "common/atomic.h"
-
-namespace Common
-{
-
-template <typename T>
-class FifoQueue
-{
-public:
- FifoQueue() : m_size(0)
- {
- m_write_ptr = m_read_ptr = new ElementPtr();
- }
-
- ~FifoQueue()
- {
- // this will empty out the whole queue
- delete m_read_ptr;
- }
-
- u32 Size() const
- {
- return m_size;
- }
-
- bool Empty() const
- {
- //return (m_read_ptr == m_write_ptr);
- return (0 == m_size);
- }
-
- T& Front() const
- {
- return *m_read_ptr->current;
- }
-
- template <typename Arg>
- void Push(Arg&& t)
- {
- // create the element, add it to the queue
- m_write_ptr->current = new T(std::forward<Arg>(t));
- // set the next pointer to a new element ptr
- // then advance the write pointer
- m_write_ptr = m_write_ptr->next = new ElementPtr();
- Common::AtomicIncrement(m_size);
- }
-
- void Pop()
- {
- Common::AtomicDecrement(m_size);
- ElementPtr *const tmpptr = m_read_ptr;
- // advance the read pointer
- m_read_ptr = m_read_ptr->next;
- // set the next element to NULL to stop the recursive deletion
- tmpptr->next = nullptr;
- delete tmpptr; // this also deletes the element
- }
-
- bool Pop(T& t)
- {
- if (Empty())
- return false;
-
- t = std::move(Front());
- Pop();
-
- return true;
- }
-
- // not thread-safe
- void Clear()
- {
- m_size = 0;
- delete m_read_ptr;
- m_write_ptr = m_read_ptr = new ElementPtr();
- }
-
-private:
- // stores a pointer to element
- // and a pointer to the next ElementPtr
- class ElementPtr
- {
- public:
- ElementPtr() : current(nullptr), next(nullptr) {}
-
- ~ElementPtr()
- {
- if (current)
- {
- delete current;
- // recusion ftw
- if (next)
- delete next;
- }
- }
-
- T *volatile current;
- ElementPtr *volatile next;
- };
-
- ElementPtr *volatile m_write_ptr;
- ElementPtr *volatile m_read_ptr;
- volatile u32 m_size;
-};
-
-}