diff options
author | David Robillard <d@drobilla.net> | 2013-01-11 03:35:17 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-11 03:35:17 +0000 |
commit | a90eec5c87af4dec9f8f45223cd228cb7ca674c6 (patch) | |
tree | 5363986923fc4ed2d025a975d0f890df9733269a /src/server | |
parent | 8caefa2c374ecf3af9ea455ce24784d398254ddf (diff) | |
download | ingen-a90eec5c87af4dec9f8f45223cd228cb7ca674c6.tar.gz ingen-a90eec5c87af4dec9f8f45223cd228cb7ca674c6.tar.bz2 ingen-a90eec5c87af4dec9f8f45223cd228cb7ca674c6.zip |
Use C++11 atomics.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4916 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/Buffer.hpp | 6 | ||||
-rw-r--r-- | src/server/BufferFactory.cpp | 22 | ||||
-rw-r--r-- | src/server/BufferFactory.hpp | 12 | ||||
-rw-r--r-- | src/server/Event.hpp | 7 | ||||
-rw-r--r-- | src/server/JackDriver.cpp | 6 | ||||
-rw-r--r-- | src/server/JackDriver.hpp | 4 | ||||
-rw-r--r-- | src/server/PostProcessor.cpp | 12 | ||||
-rw-r--r-- | src/server/PostProcessor.hpp | 9 | ||||
-rw-r--r-- | src/server/PreProcessor.cpp | 10 | ||||
-rw-r--r-- | src/server/PreProcessor.hpp | 15 |
10 files changed, 52 insertions, 51 deletions
diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp index aefd63da..56325f16 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -17,13 +17,13 @@ #ifndef INGEN_ENGINE_BUFFER_HPP #define INGEN_ENGINE_BUFFER_HPP +#include <atomic> #include <cassert> #include <boost/utility.hpp> #include "lv2/lv2plug.in/ns/ext/atom/atom.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" -#include "raul/AtomicInt.hpp" #include "raul/Deletable.hpp" #include "raul/SharedPtr.hpp" @@ -155,8 +155,8 @@ protected: private: void recycle(); - Buffer* _next; ///< Intrusive linked list for BufferFactory - Raul::AtomicInt _refs; ///< Intrusive reference count + Buffer* _next; ///< Intrusive linked list for BufferFactory + std::atomic<unsigned> _refs; ///< Intrusive reference count }; } // namespace Server diff --git a/src/server/BufferFactory.cpp b/src/server/BufferFactory.cpp index 064b5080..924a6f9f 100644 --- a/src/server/BufferFactory.cpp +++ b/src/server/BufferFactory.cpp @@ -36,10 +36,10 @@ BufferFactory::BufferFactory(Engine& engine, URIs& uris) BufferFactory::~BufferFactory() { _silent_buffer.reset(); - free_list(_free_audio.get()); - free_list(_free_control.get()); - free_list(_free_sequence.get()); - free_list(_free_object.get()); + free_list(_free_audio.load()); + free_list(_free_control.load()); + free_list(_free_sequence.load()); + free_list(_free_object.load()); } Forge& @@ -97,17 +97,17 @@ BufferFactory::get(LV2_URID type, bool real_time, bool force_create) { - Raul::AtomicPtr<Buffer>& head_ptr = free_list(type); - Buffer* try_head = NULL; + std::atomic<Buffer*>& head_ptr = free_list(type); + Buffer* try_head = NULL; if (!force_create) { Buffer* next; do { - try_head = head_ptr.get(); + try_head = head_ptr.load(); if (!try_head) break; next = try_head->_next; - } while (!head_ptr.compare_and_exchange(try_head, next)); + } while (!head_ptr.compare_exchange_weak(try_head, next)); } if (!try_head) { @@ -147,12 +147,12 @@ BufferFactory::create(LV2_URID type, uint32_t capacity) void BufferFactory::recycle(Buffer* buf) { - Raul::AtomicPtr<Buffer>& head_ptr = free_list(buf->type()); + std::atomic<Buffer*>& head_ptr = free_list(buf->type()); Buffer* try_head; do { - try_head = head_ptr.get(); + try_head = head_ptr.load(); buf->_next = try_head; - } while (!head_ptr.compare_and_exchange(try_head, buf)); + } while (!head_ptr.compare_exchange_weak(try_head, buf)); } } // namespace Server diff --git a/src/server/BufferFactory.hpp b/src/server/BufferFactory.hpp index 1fe3a91e..82180308 100644 --- a/src/server/BufferFactory.hpp +++ b/src/server/BufferFactory.hpp @@ -17,13 +17,13 @@ #ifndef INGEN_ENGINE_BUFFERFACTORY_HPP #define INGEN_ENGINE_BUFFERFACTORY_HPP +#include <atomic> #include <map> #undef nil #include <glibmm/thread.h> #include "raul/Atom.hpp" -#include "raul/AtomicPtr.hpp" #include "raul/RingBuffer.hpp" #include "raul/SharedPtr.hpp" #include "ingen/Forge.hpp" @@ -69,7 +69,7 @@ private: BufferRef create(LV2_URID type, uint32_t capacity=0); - inline Raul::AtomicPtr<Buffer>& free_list(LV2_URID type) { + inline std::atomic<Buffer*>& free_list(LV2_URID type) { if (type == _uris.atom_Float) { return _free_control; } else if (type == _uris.atom_Sound) { @@ -83,10 +83,10 @@ private: void free_list(Buffer* head); - Raul::AtomicPtr<Buffer> _free_audio; - Raul::AtomicPtr<Buffer> _free_control; - Raul::AtomicPtr<Buffer> _free_sequence; - Raul::AtomicPtr<Buffer> _free_object; + std::atomic<Buffer*> _free_audio; + std::atomic<Buffer*> _free_control; + std::atomic<Buffer*> _free_sequence; + std::atomic<Buffer*> _free_object; Glib::Mutex _mutex; Engine& _engine; diff --git a/src/server/Event.hpp b/src/server/Event.hpp index 7e4a1cc1..f984b675 100644 --- a/src/server/Event.hpp +++ b/src/server/Event.hpp @@ -17,7 +17,8 @@ #ifndef INGEN_ENGINE_EVENT_HPP #define INGEN_ENGINE_EVENT_HPP -#include "raul/AtomicPtr.hpp" +#include <atomic> + #include "raul/Deletable.hpp" #include "raul/Noncopyable.hpp" #include "raul/Path.hpp" @@ -71,7 +72,7 @@ public: inline void set_time(SampleCount time) { _time = time; } /** Get the next event to be processed after this one. */ - Event* next() const { return _next.get(); } + Event* next() const { return _next.load(); } /** Set the next event to be processed after this one. */ void next(Event* ev) { _next = ev; } @@ -120,7 +121,7 @@ protected: } Engine& _engine; - Raul::AtomicPtr<Event> _next; + std::atomic<Event*> _next; SharedPtr<Interface> _request_client; int32_t _request_id; FrameTime _time; diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp index 21f2656f..3afbd51c 100644 --- a/src/server/JackDriver.cpp +++ b/src/server/JackDriver.cpp @@ -52,7 +52,7 @@ namespace Server { JackDriver::JackDriver(Engine& engine) : _engine(engine) , _sem(0) - , _flag(0) + , _flag(false) , _client(NULL) , _block_length(0) , _sample_rate(0) @@ -172,7 +172,7 @@ void JackDriver::deactivate() { if (_is_activated) { - _flag = 1; + _flag = true; _is_activated = false; _sem.wait(); @@ -402,7 +402,7 @@ REALTIME int JackDriver::_process_cb(jack_nframes_t nframes) { if (nframes == 0 || ! _is_activated) { - if (_flag == 1) { + if (_flag) { _sem.post(); } return 0; diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp index 0369be05..59a62ad6 100644 --- a/src/server/JackDriver.hpp +++ b/src/server/JackDriver.hpp @@ -20,6 +20,7 @@ #include "ingen_config.h" #include <string> +#include <atomic> #include <jack/jack.h> #include <jack/transport.h> @@ -27,7 +28,6 @@ #include <jack/session.h> #endif -#include "raul/AtomicInt.hpp" #include "raul/Semaphore.hpp" #include "lv2/lv2plug.in/ns/ext/atom/forge.h" @@ -137,7 +137,7 @@ protected: Ports _ports; LV2_Atom_Forge _forge; Raul::Semaphore _sem; - Raul::AtomicInt _flag; + std::atomic<bool> _flag; jack_client_t* _client; jack_nframes_t _block_length; jack_nframes_t _sample_rate; diff --git a/src/server/PostProcessor.cpp b/src/server/PostProcessor.cpp index 603a3e0b..b94e149c 100644 --- a/src/server/PostProcessor.cpp +++ b/src/server/PostProcessor.cpp @@ -41,8 +41,8 @@ PostProcessor::append(ProcessContext& context, Event* first, Event* last) { assert(first); assert(last); - if (_head.get()) { - _tail.get()->next(first); + if (_head) { + _tail.load()->next(first); _tail = last; } else { _tail = last; @@ -53,18 +53,18 @@ PostProcessor::append(ProcessContext& context, Event* first, Event* last) bool PostProcessor::pending() const { - return _head.get() || _engine.process_context().pending_notifications(); + return _head.load() || _engine.process_context().pending_notifications(); } void PostProcessor::process() { - const FrameTime end_time = _max_time.get(); + const FrameTime end_time = _max_time; // To avoid a race, we only process up to tail and never write to _tail - Event* const tail = _tail.get(); + Event* const tail = _tail.load(); - Event* ev = _head.get(); + Event* ev = _head.load(); if (!ev) { // Process audio thread notifications up until end _engine.process_context().emit_notifications(end_time); diff --git a/src/server/PostProcessor.hpp b/src/server/PostProcessor.hpp index 2bd6036f..f4301f46 100644 --- a/src/server/PostProcessor.hpp +++ b/src/server/PostProcessor.hpp @@ -17,8 +17,7 @@ #ifndef INGEN_ENGINE_POSTPROCESSOR_HPP #define INGEN_ENGINE_POSTPROCESSOR_HPP -#include "raul/AtomicInt.hpp" -#include "raul/AtomicPtr.hpp" +#include <atomic> #include "types.hpp" @@ -62,9 +61,9 @@ public: private: Engine& _engine; - Raul::AtomicPtr<Event> _head; - Raul::AtomicPtr<Event> _tail; - Raul::AtomicInt _max_time; + std::atomic<Event*> _head; + std::atomic<Event*> _tail; + std::atomic<FrameTime> _max_time; }; } // namespace Server diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp index 34ae48e7..15ca6cd0 100644 --- a/src/server/PreProcessor.cpp +++ b/src/server/PreProcessor.cpp @@ -45,16 +45,16 @@ PreProcessor::event(Event* const ev) assert(!ev->is_prepared()); assert(!ev->next()); - Event* const head = _head.get(); + Event* const head = _head.load(); if (!head) { _head = ev; _tail = ev; } else { - _tail.get()->next(ev); + _tail.load()->next(ev); _tail = ev; } - if (!_prepared_back.get()) { + if (!_prepared_back.load()) { _prepared_back = ev; } @@ -64,7 +64,7 @@ PreProcessor::event(Event* const ev) unsigned PreProcessor::process(ProcessContext& context, PostProcessor& dest, bool limit) { - Event* const head = _head.get(); + Event* const head = _head.load(); if (!head) { return 0; } @@ -112,7 +112,7 @@ PreProcessor::_run() { ThreadManager::set_flag(THREAD_PRE_PROCESS); while (_sem.wait() && !_exit_flag) { - Event* const ev = _prepared_back.get(); + Event* const ev = _prepared_back.load(); if (!ev) { return; } diff --git a/src/server/PreProcessor.hpp b/src/server/PreProcessor.hpp index 9b7fbd44..10563ee9 100644 --- a/src/server/PreProcessor.hpp +++ b/src/server/PreProcessor.hpp @@ -17,9 +17,10 @@ #ifndef INGEN_ENGINE_PREPROCESSOR_HPP #define INGEN_ENGINE_PREPROCESSOR_HPP +#include <atomic> + #include <glibmm/thread.h> -#include "raul/AtomicPtr.hpp" #include "raul/Semaphore.hpp" #include "raul/Thread.hpp" @@ -43,7 +44,7 @@ public: } /** Return true iff no events are enqueued. */ - inline bool empty() const { return !_head.get(); } + inline bool empty() const { return !_head.load(); } /** Enqueue an event. * This is safe to call from any non-realtime thread (it locks). @@ -61,11 +62,11 @@ protected: virtual void _run(); private: - Glib::Mutex _mutex; - Raul::Semaphore _sem; - Raul::AtomicPtr<Event> _head; - Raul::AtomicPtr<Event> _prepared_back; - Raul::AtomicPtr<Event> _tail; + Glib::Mutex _mutex; + Raul::Semaphore _sem; + std::atomic<Event*> _head; + std::atomic<Event*> _prepared_back; + std::atomic<Event*> _tail; }; } // namespace Server |