summaryrefslogtreecommitdiffstats
path: root/src/engine/Buffer.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-01-05 03:51:50 +0000
committerDavid Robillard <d@drobilla.net>2010-01-05 03:51:50 +0000
commitc67392abf59b500fe405101d7ad896d9da869e47 (patch)
tree53b5d5b27d4389caa123c5deb2a1e0aadf180ec7 /src/engine/Buffer.hpp
parent4c32f20699db0ede850a9485271dfda779761fac (diff)
downloadingen-c67392abf59b500fe405101d7ad896d9da869e47.tar.gz
ingen-c67392abf59b500fe405101d7ad896d9da869e47.tar.bz2
ingen-c67392abf59b500fe405101d7ad896d9da869e47.zip
Realtime safe buffer reference handling.
Turns out that dropping a shared_ptr is not realtime safe, even if you use a realtime safe deleter. Instead, instrusive_ptr is used for buffer references, so a buffer reference may safely be dropped in the audio thread (in which case it will be recycled by the BufferFactory). Faster, cleaner, better. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2341 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/Buffer.hpp')
-rw-r--r--src/engine/Buffer.hpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/engine/Buffer.hpp b/src/engine/Buffer.hpp
index 160e6144..61455603 100644
--- a/src/engine/Buffer.hpp
+++ b/src/engine/Buffer.hpp
@@ -15,28 +15,33 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef BUFFER_H
-#define BUFFER_H
+#ifndef BUFFER_HPP
+#define BUFFER_HPP
#include <cstddef>
#include <cassert>
#include <boost/utility.hpp>
+#include <boost/intrusive_ptr.hpp>
#include "raul/Deletable.hpp"
#include "raul/SharedPtr.hpp"
-#include "types.hpp"
#include "interface/PortType.hpp"
+#include "types.hpp"
+#include "BufferFactory.hpp"
namespace Ingen {
class Context;
class Engine;
+class BufferFactory;
class Buffer : public boost::noncopyable, public Raul::Deletable
{
public:
- Buffer(Shared::PortType type, size_t size)
- : _type(type)
+ Buffer(BufferFactory& factory, Shared::PortType type, size_t size)
+ : _factory(factory)
+ , _type(type)
, _size(size)
+ , _refs(0)
{}
/** Clear contents and reset state */
@@ -58,7 +63,16 @@ public:
Shared::PortType type() const { return _type; }
size_t size() const { return _size; }
+ inline void ref() { ++_refs; }
+
+ inline void deref() {
+ assert(_refs > 0);
+ if ((--_refs) == 0)
+ _factory.recycle(this);
+ }
+
protected:
+ BufferFactory& _factory;
Shared::PortType _type;
size_t _size;
@@ -67,9 +81,16 @@ protected:
private:
Buffer* _next; ///< Intrusive linked list for BufferFactory
+ size_t _refs; ///< Intrusive reference count for intrusive_ptr
};
-
} // namespace Ingen
-#endif // BUFFER_H
+
+namespace boost {
+ inline void intrusive_ptr_add_ref(Ingen::Buffer* b) { b->ref(); }
+ inline void intrusive_ptr_release(Ingen::Buffer* b) { b->deref(); }
+}
+
+
+#endif // BUFFER_HPP