From 8513a822501175e510591ff15418022a145ddc81 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 28 Apr 2011 18:19:28 +0000 Subject: Improve RingBuffer implementation. Previous implementation was broken when written to full capacity, and this version is significantly faster as well. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@3213 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Controller.cpp | 7 +++++-- src/engine/Recorder.cpp | 17 ++++++++++++++--- src/engine/Recorder.hpp | 14 +++++++++++--- 3 files changed, 30 insertions(+), 8 deletions(-) (limited to 'src/engine') diff --git a/src/engine/Controller.cpp b/src/engine/Controller.cpp index edde2b1..1b92e5f 100644 --- a/src/engine/Controller.cpp +++ b/src/engine/Controller.cpp @@ -15,6 +15,8 @@ * along with Machina. If not, see . */ +#include "raul/log.hpp" + #include "client/ClientModel.hpp" #include "client/ClientObject.hpp" #include "machina/Controller.hpp" @@ -139,10 +141,11 @@ Controller::disconnect(uint64_t tail_id, uint64_t head_id) SharedPtr head = PtrCast(find(head_id)); SharedPtr edge = tail->remove_edge_to(head); - if (edge) + if (edge) { _client_model.erase_object(edge->id()); - else + } else { Raul::error << "Edge not found" << std::endl; + } } void diff --git a/src/engine/Recorder.cpp b/src/engine/Recorder.cpp index c03d725..0a6b5a0 100644 --- a/src/engine/Recorder.cpp +++ b/src/engine/Recorder.cpp @@ -40,9 +40,20 @@ Recorder::_whipped() size_t size; unsigned char buf[4]; - while (_record_buffer.read(&t, &size, buf)) { - _builder->set_time(t); - _builder->event(TimeStamp(_unit), size, buf); + while (true) { + bool success = _record_buffer.read(sizeof(TimeStamp), (uint8_t*)&t); + if (success) { + success = _record_buffer.read(sizeof(size_t), (uint8_t*)&size); + } + if (success) { + success = _record_buffer.read(size, buf); + } + if (success) { + _builder->set_time(t); + _builder->event(TimeStamp(_unit), size, buf); + } else { + break; + } } } diff --git a/src/engine/Recorder.hpp b/src/engine/Recorder.hpp index c7f78f4..714b2a9 100644 --- a/src/engine/Recorder.hpp +++ b/src/engine/Recorder.hpp @@ -18,9 +18,10 @@ #ifndef MACHINA_RECORDER_HPP #define MACHINA_RECORDER_HPP +#include "raul/log.hpp" #include "raul/Slave.hpp" #include "raul/SharedPtr.hpp" -#include "raul/EventRingBuffer.hpp" +#include "raul/RingBuffer.hpp" #include "machina/Machine.hpp" @@ -33,7 +34,14 @@ public: Recorder(size_t buffer_size, TimeUnit unit, double q, bool step); inline void write(Raul::TimeStamp time, size_t size, const unsigned char* buf) { - _record_buffer.write(time, size, buf); + if (_record_buffer.write_space() < (sizeof(TimeStamp) + sizeof(size_t) + size)) { + Raul::warn << "Record buffer overflow" << std::endl; + return; + } else { + _record_buffer.write(sizeof(TimeStamp), (uint8_t*)&time); + _record_buffer.write(sizeof(size_t), (uint8_t*)&size); + _record_buffer.write(size, buf); + } } SharedPtr finish(); @@ -42,7 +50,7 @@ private: virtual void _whipped(); TimeUnit _unit; - Raul::EventRingBuffer _record_buffer; + Raul::RingBuffer _record_buffer; SharedPtr _builder; }; -- cgit v1.2.1