diff options
author | David Robillard <d@drobilla.net> | 2020-11-28 10:29:50 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-28 11:16:24 +0100 |
commit | 4988d75f19e81c58e2cfdc068c5638b95ae9e314 (patch) | |
tree | 178c2c78cac247884717a23ff8d9d8cd67099ad0 /src | |
parent | 061f4f4cd7e66f0d8add6271caf745a86b1d5c9c (diff) | |
download | patchage-4988d75f19e81c58e2cfdc068c5638b95ae9e314.tar.gz patchage-4988d75f19e81c58e2cfdc068c5638b95ae9e314.tar.bz2 patchage-4988d75f19e81c58e2cfdc068c5638b95ae9e314.zip |
Remove Queue and use std::queue in JackDriver
Jack notification handlers do not need to be realtime safe.
Diffstat (limited to 'src')
-rw-r--r-- | src/JackDriver.cpp | 2 | ||||
-rw-r--r-- | src/JackDriver.hpp | 4 | ||||
-rw-r--r-- | src/Queue.hpp | 137 |
3 files changed, 2 insertions, 141 deletions
diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 2807791..e20613c 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -22,7 +22,6 @@ #include "PatchageCanvas.hpp" #include "PatchageEvent.hpp" #include "PatchageModule.hpp" -#include "Queue.hpp" #include "patchage_config.h" #ifdef HAVE_JACK_METADATA @@ -46,7 +45,6 @@ JackDriver::JackDriver(Patchage* app, ILog& log) : _app(app) , _log(log) , _client(nullptr) - , _events(128) , _last_pos{} , _buffer_size(0) , _xruns(0) diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp index 01185b2..abf9008 100644 --- a/src/JackDriver.hpp +++ b/src/JackDriver.hpp @@ -18,12 +18,12 @@ #define PATCHAGE_JACKDRIVER_HPP #include "Driver.hpp" -#include "Queue.hpp" #include <glibmm/thread.h> #include <jack/jack.h> #include <mutex> +#include <queue> #include <string> class ILog; @@ -122,7 +122,7 @@ private: ILog& _log; jack_client_t* _client; - Queue<PatchageEvent> _events; + std::queue<PatchageEvent> _events; std::mutex _shutdown_mutex; diff --git a/src/Queue.hpp b/src/Queue.hpp deleted file mode 100644 index b951b56..0000000 --- a/src/Queue.hpp +++ /dev/null @@ -1,137 +0,0 @@ -/* This file is part of Patchage. - * Copyright 2007-2020 David Robillard <d@drobilla.net> - * - * Patchage 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 3 of the License, or any later version. - * - * Patchage 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 details. - * - * You should have received a copy of the GNU General Public License along with - * Patchage. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef PATCHAGE_QUEUE_HPP -#define PATCHAGE_QUEUE_HPP - -#include <atomic> -#include <cassert> -#include <cstddef> - -/** Realtime-safe single-reader single-writer queue */ -template<typename T> -class Queue -{ -public: - /** @param size Size in number of elements */ - explicit Queue(size_t size); - - Queue(const Queue&) = delete; - Queue& operator=(const Queue&) = delete; - - Queue(Queue&&) = delete; - Queue& operator=(Queue&&) = delete; - - ~Queue(); - - // Any thread: - - inline size_t capacity() const { return _size - 1; } - - // Write thread: - - inline bool full() const; - inline bool push(const T& elem); - - // Read thread: - - inline bool empty() const; - inline T& front() const; - inline void pop(); - -private: - std::atomic<size_t> _front; ///< Index to front of queue - std::atomic<size_t> _back; ///< Index to back of queue (one past end) - const size_t _size; ///< Size of `_objects` (at most _size-1) - T* const _objects; ///< Fixed array containing queued elements -}; - -template<typename T> -Queue<T>::Queue(size_t size) - : _front(0) - , _back(0) - , _size(size + 1) - , _objects(new T[_size]) -{ - assert(size > 1); -} - -template<typename T> -Queue<T>::~Queue() -{ - delete[] _objects; -} - -/** Return whether or not the queue is empty. - */ -template<typename T> -inline bool -Queue<T>::empty() const -{ - return (_back.load() == _front.load()); -} - -/** Return whether or not the queue is full. - */ -template<typename T> -inline bool -Queue<T>::full() const -{ - return (((_front.load() - _back.load() + _size) % _size) == 1); -} - -/** Return the element at the front of the queue without removing it - */ -template<typename T> -inline T& -Queue<T>::front() const -{ - return _objects[_front.load()]; -} - -/** Push an item onto the back of the Queue - realtime-safe, not thread-safe. - * - * @returns true if `elem` was successfully pushed onto the queue, - * false otherwise (queue is full). - */ -template<typename T> -inline bool -Queue<T>::push(const T& elem) -{ - if (full()) { - return false; - } - - const unsigned back = _back.load(); - _objects[back] = elem; - _back = (back + 1) % _size; - return true; -} - -/** Pop an item off the front of the queue - realtime-safe, not thread-safe. - * - * It is a fatal error to call pop() when the queue is empty. - */ -template<typename T> -inline void -Queue<T>::pop() -{ - assert(!empty()); - assert(_size > 0); - - _front = (_front.load() + 1) % (_size); -} - -#endif // PATCHAGE_QUEUE_HPP |