From f8bf77d3c3b77830aedafb9ebb5cdadfea7ed07a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 20 Sep 2016 15:26:45 -0400 Subject: Remove features now provided by C++11 --- NEWS | 3 ++- raul/RingBuffer.hpp | 10 +++---- raul/ThreadVar.hpp | 75 ----------------------------------------------------- raul/barrier.hpp | 56 --------------------------------------- 4 files changed, 7 insertions(+), 137 deletions(-) delete mode 100644 raul/ThreadVar.hpp delete mode 100644 raul/barrier.hpp diff --git a/NEWS b/NEWS index 3eef2d4..3c36ddc 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ raul (0.8.5) unstable; * Remove boost dependency * Remove OSC and RDF library dependent code * Remove remaining library code, now header only + * Remove features now provided by C++11 * Improve RingBuffer * Add ThreadVar, a thread-specific variable class * Implement Semaphore for Windows @@ -12,7 +13,7 @@ raul (0.8.5) unstable; * Add INSTALL file * Update license to GPL3+ - -- David Robillard Wed, 25 Dec 2013 15:15:08 -0500 + -- David Robillard Mon, 26 Sep 2016 13:08:52 -0400 raul (0.8.0) stable; diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp index eb86036..1ec5e4e 100644 --- a/raul/RingBuffer.hpp +++ b/raul/RingBuffer.hpp @@ -18,12 +18,12 @@ #define RAUL_RING_BUFFER_HPP #include +#include #include #include #include #include "raul/Noncopyable.hpp" -#include "raul/barrier.hpp" namespace Raul { @@ -103,7 +103,7 @@ public: const uint32_t w = _write_head; if (peek_internal(r, w, size, dst)) { - Raul::barrier(); + std::atomic_thread_fence(std::memory_order_acquire); _read_head = (r + size) & _size_mask; return size; } else { @@ -121,7 +121,7 @@ public: return 0; } - Raul::barrier(); + std::atomic_thread_fence(std::memory_order_acquire); _read_head = (r + size) & _size_mask; return size; } @@ -138,7 +138,7 @@ public: if (w + size <= _size) { memcpy(&_buf[w], src, size); - Raul::barrier(); + std::atomic_thread_fence(std::memory_order_release); _write_head = (w + size) & _size_mask; } else { const uint32_t this_size = _size - w; @@ -146,7 +146,7 @@ public: assert(w + this_size <= _size); memcpy(&_buf[w], src, this_size); memcpy(&_buf[0], (const char*)src + this_size, size - this_size); - Raul::barrier(); + std::atomic_thread_fence(std::memory_order_release); _write_head = size - this_size; } diff --git a/raul/ThreadVar.hpp b/raul/ThreadVar.hpp deleted file mode 100644 index fa714bd..0000000 --- a/raul/ThreadVar.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - This file is part of Raul. - Copyright 2007-2016 David Robillard - - Raul 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. - - Raul 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 Raul. If not, see . -*/ - -#ifndef RAUL_THREADVAR_HPP -#define RAUL_THREADVAR_HPP - -#include - -#include "raul/Noncopyable.hpp" - -namespace Raul { - -/** Thread-specific variable. - * - * A ThreadVar is a variable which has a different value for each thread. - */ -template -class ThreadVar : public Noncopyable -{ -public: - explicit ThreadVar(const T& default_value) - : _default_value(default_value) - { - pthread_key_create(&_key, destroy_value); - } - - ~ThreadVar() { - T* val = (T*)pthread_getspecific(_key); - delete val; - pthread_key_delete(_key); - } - - /** Set the value for the calling thread. */ - ThreadVar& operator=(const T& value) { - T* val = (T*)pthread_getspecific(_key); - if (val) { - *val = value; - } else { - val = new T(value); - pthread_setspecific(_key, val); - } - return *this; - } - - /** Get the value for the calling thread. */ - operator T() const { - T* val = (T*)pthread_getspecific(_key); - return val ? *val : _default_value; - } - -private: - static void destroy_value(void* ptr) { - delete (T*)ptr; - } - - const T _default_value; - pthread_key_t _key; -}; - -} // namespace Raul - -#endif // RAUL_THREADVAR_HPP diff --git a/raul/barrier.hpp b/raul/barrier.hpp deleted file mode 100644 index 952278e..0000000 --- a/raul/barrier.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - This file is part of Raul. - Copyright 2012 David Robillard - - Raul 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. - - Raul 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 Raul. If not, see . -*/ - -#ifndef RAUL_BARRIER_HPP -#define RAUL_BARRIER_HPP - -#if defined(__APPLE__) -#include - -namespace Raul { -static inline void barrier() { - OSMemoryBarrier(); -} -} - -#elif defined(_WIN32) -#include - -namespace Raul { -static inline void barrier() { - MemoryBarrier(); -} -} - -#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) - -namespace Raul { -static inline void barrier() { - __sync_synchronize(); -} -} - -#else -#pragma message("warning: No memory barriers, possible SMP bugs") - -namespace Raul { -static inline void barrier() { -} -} - -#endif - -#endif // RAUL_BARRIER_HPP -- cgit v1.2.1