diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2015-06-20 21:10:44 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2015-06-27 15:43:56 +0200 |
commit | 0aade9ad631f21b9d0e72c4896858c107f5a167a (patch) | |
tree | a18e78c22b22426730a94f383f7c08f56d79b179 /src/common | |
parent | Merge pull request #886 from zawata/Warning-Fixes (diff) | |
download | yuzu-0aade9ad631f21b9d0e72c4896858c107f5a167a.tar yuzu-0aade9ad631f21b9d0e72c4896858c107f5a167a.tar.gz yuzu-0aade9ad631f21b9d0e72c4896858c107f5a167a.tar.bz2 yuzu-0aade9ad631f21b9d0e72c4896858c107f5a167a.tar.lz yuzu-0aade9ad631f21b9d0e72c4896858c107f5a167a.tar.xz yuzu-0aade9ad631f21b9d0e72c4896858c107f5a167a.tar.zst yuzu-0aade9ad631f21b9d0e72c4896858c107f5a167a.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/fifo_queue.h | 111 |
2 files changed, 0 insertions, 112 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index e78f4f144..f025e1186 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -31,7 +31,6 @@ set(HEADERS cpu_detect.h debug_interface.h emu_window.h - fifo_queue.h file_util.h key_map.h linear_disk_cache.h 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; -}; - -} |