From d03361f3e0752f244193faebbca7b5869524a1aa Mon Sep 17 00:00:00 2001 From: fgo Date: Tue, 22 Mar 2022 08:31:05 +0100 Subject: [PATCH] Remove CircularFifo It is not used anymore --- include/CMakeLists.txt | 1 - include/ableton/link/CircularFifo.hpp | 95 --------------------------- src/CMakeLists.txt | 1 - src/ableton/link/tst_CircularFifo.cpp | 82 ----------------------- 4 files changed, 179 deletions(-) delete mode 100644 include/ableton/link/CircularFifo.hpp delete mode 100644 src/ableton/link/tst_CircularFifo.cpp diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 79fe107c..1c7b5ed9 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -11,7 +11,6 @@ project(LinkCore) set(link_core_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ableton/link) set(link_core_HEADERS ${link_core_DIR}/Beats.hpp - ${link_core_DIR}/CircularFifo.hpp ${link_core_DIR}/ClientSessionTimelines.hpp ${link_core_DIR}/Controller.hpp ${link_core_DIR}/Gateway.hpp diff --git a/include/ableton/link/CircularFifo.hpp b/include/ableton/link/CircularFifo.hpp deleted file mode 100644 index 8ee8a26d..00000000 --- a/include/ableton/link/CircularFifo.hpp +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright 2016, Ableton AG, Berlin. All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * If you would like to incorporate Link into a proprietary software application, - * please contact . - */ - -#pragma once - -#include -#include -#include -#include - -#include - -namespace ableton -{ -namespace link -{ - -// Single producer, single consumer lockfree Fifo - -template -class CircularFifo -{ -public: - CircularFifo() - : tail(0) - , head(0) - { - assert(head.is_lock_free() && tail.is_lock_free()); - } - - bool push(Type item) - { - const auto currentTail = tail.load(); - const auto nextTail = nextIndex(currentTail); - if (nextTail != head.load()) - { - data[currentTail] = std::move(item); - tail.store(nextTail); - return true; - } - return false; - } - - Optional pop() - { - const auto currentHead = head.load(); - if (currentHead == tail.load()) - { - return {}; - } - - auto item = data[currentHead]; - head.store(nextIndex(currentHead)); - return Optional{std::move(item)}; - } - - bool isEmpty() const - { - return tail == head; - } - -private: - size_t nextIndex(const size_t index) const - { - return (index + 1) % (size + 1); - } - - size_t previousIndex(const size_t index) const - { - return (index + size) % (size + 1); - } - - std::atomic_size_t tail; - std::atomic_size_t head; - std::array data; -}; - -} // namespace link -} // namespace ableton diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f5625f5..170ef41d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,6 @@ set(link_discovery_test_SOURCES set(link_core_test_SOURCES ableton/link/tst_Beats.cpp - ableton/link/tst_CircularFifo.cpp ableton/link/tst_ClientSessionTimelines.cpp ableton/link/tst_Controller.cpp ableton/link/tst_HostTimeFilter.cpp diff --git a/src/ableton/link/tst_CircularFifo.cpp b/src/ableton/link/tst_CircularFifo.cpp deleted file mode 100644 index f41cd258..00000000 --- a/src/ableton/link/tst_CircularFifo.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright 2016, Ableton AG, Berlin. All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * If you would like to incorporate Link into a proprietary software application, - * please contact . - */ - -#include -#include - -namespace ableton -{ -namespace link -{ - -TEST_CASE("CircularFifo") -{ - CircularFifo cf; - - SECTION("PushNPop") - { - for (int i = 0; i < 2; ++i) - { - CHECK(cf.push(i)); - } - - CHECK(!cf.push(0)); - - for (int i = 0; i < 2; ++i) - { - auto result = cf.pop(); - CHECK(result); - CHECK(*result == i); - } - - CHECK(!cf.pop()); - } - - SECTION("Wrap") - { - for (int i = 0; i < 5; ++i) - { - CHECK(cf.push(i)); - auto result = cf.pop(); - CHECK(result); - CHECK(*result == i); - } - } - - SECTION("IsEmpty") - { - CHECK(cf.isEmpty()); - CHECK(cf.push(1)); - CHECK(!cf.isEmpty()); - CHECK(cf.push(2)); - CHECK(!cf.isEmpty()); - CHECK(!cf.push(3)); - CHECK(!cf.isEmpty()); - - CHECK(cf.pop()); - CHECK(!cf.isEmpty()); - CHECK(cf.pop()); - CHECK(cf.isEmpty()); - CHECK(!cf.pop()); - CHECK(cf.isEmpty()); - } -} - -} // namespace link -} // namespace ableton