summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-09-24 04:52:23 +0000
committerDavid Robillard <d@drobilla.net>2011-09-24 04:52:23 +0000
commit9085d33b7600fd2721f0a2401a4e69830c457f84 (patch)
tree17631e4c88c8fd9d61045e23e84de5f19c005b7b /src
parent0e310888809be1b55e6c24081f41f56bebf00f58 (diff)
downloadingen-9085d33b7600fd2721f0a2401a4e69830c457f84.tar.gz
ingen-9085d33b7600fd2721f0a2401a4e69830c457f84.tar.bz2
ingen-9085d33b7600fd2721f0a2401a4e69830c457f84.zip
Remove concept of "blocking" events in favour of store RWLock.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3488 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/server/EventSource.cpp6
-rw-r--r--src/server/EventSource.hpp10
-rw-r--r--src/server/QueuedEvent.hpp11
-rw-r--r--src/server/Request.hpp5
-rw-r--r--src/server/events/Connect.cpp39
-rw-r--r--src/server/events/Connect.hpp6
-rw-r--r--src/server/events/CreateNode.cpp6
-rw-r--r--src/server/events/CreateNode.hpp5
-rw-r--r--src/server/events/CreatePort.cpp19
-rw-r--r--src/server/events/CreatePort.hpp5
-rw-r--r--src/server/events/Delete.cpp4
-rw-r--r--src/server/events/Disconnect.cpp20
-rw-r--r--src/server/events/Disconnect.hpp11
-rw-r--r--src/server/events/DisconnectAll.cpp8
-rw-r--r--src/server/events/Move.cpp11
-rw-r--r--src/server/events/SetMetadata.cpp13
-rw-r--r--src/server/events/SetMetadata.hpp3
17 files changed, 80 insertions, 102 deletions
diff --git a/src/server/EventSource.cpp b/src/server/EventSource.cpp
index ef982664..3d3e5e08 100644
--- a/src/server/EventSource.cpp
+++ b/src/server/EventSource.cpp
@@ -27,7 +27,6 @@ namespace Ingen {
namespace Server {
EventSource::EventSource()
- : _blocking_semaphore(0)
{
Thread::set_context(THREAD_PRE_PROCESS);
set_name("EventSource");
@@ -120,11 +119,6 @@ EventSource::_whipped()
assert(ev->is_prepared());
_prepared_back = (QueuedEvent*)ev->next();
-
- // If event was blocking, wait for event to being run through the
- // process thread before preparing the next event
- if (ev->is_blocking())
- _blocking_semaphore.wait();
}
} // namespace Server
diff --git a/src/server/EventSource.hpp b/src/server/EventSource.hpp
index 5d3c1e14..f05322e0 100644
--- a/src/server/EventSource.hpp
+++ b/src/server/EventSource.hpp
@@ -19,7 +19,6 @@
#define INGEN_ENGINE_EVENTSOURCE_HPP
#include "raul/AtomicPtr.hpp"
-#include "raul/Semaphore.hpp"
#include "raul/Slave.hpp"
namespace Ingen {
@@ -46,13 +45,6 @@ public:
bool empty() { return !_head.get(); }
- /** Signal that a blocking event is finished.
- *
- * This MUST be called by blocking events in their post_process() method
- * to resume pre-processing of events.
- */
- inline void unblock() { _blocking_semaphore.post(); }
-
protected:
void push_queued(QueuedEvent* const ev);
@@ -64,8 +56,6 @@ private:
Raul::AtomicPtr<QueuedEvent> _head;
Raul::AtomicPtr<QueuedEvent> _prepared_back;
Raul::AtomicPtr<QueuedEvent> _tail;
-
- Raul::Semaphore _blocking_semaphore;
};
} // namespace Server
diff --git a/src/server/QueuedEvent.hpp b/src/server/QueuedEvent.hpp
index 20229272..6c851047 100644
--- a/src/server/QueuedEvent.hpp
+++ b/src/server/QueuedEvent.hpp
@@ -45,30 +45,23 @@ public:
virtual void execute(ProcessContext& context);
- /** True iff this event blocks the prepare phase of other events. */
- bool is_blocking() { return _blocking; }
-
- bool is_prepared() { return _pre_processed; }
+ bool is_prepared() const { return _pre_processed; }
protected:
QueuedEvent(Engine& engine,
SharedPtr<Request> request,
- FrameTime time,
- bool blocking=false)
+ FrameTime time)
: Event(engine, request, time)
, _pre_processed(false)
- , _blocking(blocking)
{}
// NULL event base (for internal events only!)
explicit QueuedEvent(Engine& engine)
: Event(engine, SharedPtr<Request>(), 0)
, _pre_processed(false)
- , _blocking(false)
{}
bool _pre_processed;
- bool _blocking;
};
} // namespace Server
diff --git a/src/server/Request.hpp b/src/server/Request.hpp
index 185c250c..da3ebece 100644
--- a/src/server/Request.hpp
+++ b/src/server/Request.hpp
@@ -53,11 +53,6 @@ public:
ClientInterface* client() const { return _client; }
void set_client(ClientInterface* client) { _client = client; }
- void unblock() {
- if (_source)
- _source->unblock();
- }
-
void respond_ok() {
if (_client)
_client->response_ok(_id);
diff --git a/src/server/events/Connect.cpp b/src/server/events/Connect.cpp
index e0f09a3d..b67eacbc 100644
--- a/src/server/events/Connect.cpp
+++ b/src/server/events/Connect.cpp
@@ -16,9 +16,13 @@
*/
#include <string>
+
#include <boost/format.hpp>
+#include <glibmm/thread.h>
+
#include "raul/Maid.hpp"
#include "raul/Path.hpp"
+
#include "ClientBroadcaster.hpp"
#include "Connect.hpp"
#include "ConnectionImpl.hpp"
@@ -40,7 +44,11 @@ namespace Ingen {
namespace Server {
namespace Events {
-Connect::Connect(Engine& engine, SharedPtr<Request> request, SampleCount timestamp, const Path& src_port_path, const Path& dst_port_path)
+Connect::Connect(Engine& engine,
+ SharedPtr<Request> request,
+ SampleCount timestamp,
+ const Path& src_port_path,
+ const Path& dst_port_path)
: QueuedEvent(engine, request, timestamp)
, _src_port_path(src_port_path)
, _dst_port_path(dst_port_path)
@@ -50,12 +58,13 @@ Connect::Connect(Engine& engine, SharedPtr<Request> request, SampleCount timesta
, _compiled_patch(NULL)
, _port_listnode(NULL)
, _buffers(NULL)
-{
-}
+{}
void
Connect::pre_process()
{
+ Glib::RWLock::ReaderLock rlock(_engine.engine_store()->lock());
+
PortImpl* src_port = _engine.engine_store()->find_port(_src_port_path);
PortImpl* dst_port = _engine.engine_store()->find_port(_dst_port_path);
if (!src_port || !dst_port) {
@@ -122,15 +131,23 @@ Connect::pre_process()
_port_listnode = new InputPort::Connections::Node(_connection);
- // Need to be careful about patch port connections here and adding a node's
- // parent as a dependant/provider, or adding a patch as it's own provider...
- if (src_node != dst_node && src_node->parent() == dst_node->parent()) {
- dst_node->providers()->push_back(new Raul::List<NodeImpl*>::Node(src_node));
- src_node->dependants()->push_back(new Raul::List<NodeImpl*>::Node(dst_node));
- }
+ rlock.release();
+
+ {
+ Glib::RWLock::ReaderLock wlock(_engine.engine_store()->lock());
- _patch->add_connection(_connection);
- _dst_input_port->increment_num_connections();
+ /* Need to be careful about patch port connections here and adding a
+ node's parent as a dependant/provider, or adding a patch as its own
+ provider...
+ */
+ if (src_node != dst_node && src_node->parent() == dst_node->parent()) {
+ dst_node->providers()->push_back(new Raul::List<NodeImpl*>::Node(src_node));
+ src_node->dependants()->push_back(new Raul::List<NodeImpl*>::Node(dst_node));
+ }
+
+ _patch->add_connection(_connection);
+ _dst_input_port->increment_num_connections();
+ }
/*if ((_dst_input_port->num_connections() == 1
&& (_connection->must_mix() || _connection->must_queue()))
diff --git a/src/server/events/Connect.hpp b/src/server/events/Connect.hpp
index 1cc98729..d250b791 100644
--- a/src/server/events/Connect.hpp
+++ b/src/server/events/Connect.hpp
@@ -49,7 +49,11 @@ namespace Events {
class Connect : public QueuedEvent
{
public:
- Connect(Engine& engine, SharedPtr<Request> request, SampleCount timestamp, const Raul::Path& src_port_path, const Raul::Path& dst_port_path);
+ Connect(Engine& engine,
+ SharedPtr<Request> request,
+ SampleCount timestamp,
+ const Raul::Path& src_port_path,
+ const Raul::Path& dst_port_path);
void pre_process();
void execute(ProcessContext& context);
diff --git a/src/server/events/CreateNode.cpp b/src/server/events/CreateNode.cpp
index 39d5f86d..7722caee 100644
--- a/src/server/events/CreateNode.cpp
+++ b/src/server/events/CreateNode.cpp
@@ -57,7 +57,6 @@ CreateNode::CreateNode(
, _node_already_exists(false)
, _polyphonic(false)
, _properties(properties)
- , _lock(engine.engine_store()->lock(), Glib::NOT_LOCK)
{
const Resource::Properties::const_iterator p = properties.find(
engine.world()->uris()->ingen_polyphonic);
@@ -69,8 +68,6 @@ CreateNode::CreateNode(
void
CreateNode::pre_process()
{
- _lock.acquire();
-
if (_engine.engine_store()->find_object(_path) != NULL) {
_node_already_exists = true;
QueuedEvent::pre_process();
@@ -121,7 +118,6 @@ void
CreateNode::post_process()
{
if (!_request) {
- _lock.release();
return;
}
@@ -143,8 +139,6 @@ CreateNode::post_process()
_request->respond_ok();
_engine.broadcaster()->send_object(_node, true); // yes, send ports
}
-
- _lock.release();
}
} // namespace Server
diff --git a/src/server/events/CreateNode.hpp b/src/server/events/CreateNode.hpp
index 47f86622..86cabf2a 100644
--- a/src/server/events/CreateNode.hpp
+++ b/src/server/events/CreateNode.hpp
@@ -20,8 +20,6 @@
#include <string>
-#include <glibmm/thread.h>
-
#include "ingen/Resource.hpp"
#include "QueuedEvent.hpp"
@@ -65,8 +63,7 @@ private:
bool _node_already_exists;
bool _polyphonic;
- Resource::Properties _properties;
- Glib::RWLock::WriterLock _lock;
+ Resource::Properties _properties;
};
} // namespace Server
diff --git a/src/server/events/CreatePort.cpp b/src/server/events/CreatePort.cpp
index fdf675a6..5c3ecbd2 100644
--- a/src/server/events/CreatePort.cpp
+++ b/src/server/events/CreatePort.cpp
@@ -49,7 +49,7 @@ CreatePort::CreatePort(
const Raul::URI& type,
bool is_output,
const Resource::Properties& properties)
- : QueuedEvent(engine, request, timestamp, bool(request))
+ : QueuedEvent(engine, request, timestamp)
, _path(path)
, _type(type)
, _is_output(is_output)
@@ -58,16 +58,7 @@ CreatePort::CreatePort(
, _patch_port(NULL)
, _driver_port(NULL)
, _properties(properties)
- , _lock(engine.engine_store()->lock(), Glib::NOT_LOCK)
{
- /* This is blocking because of the two different sets of Patch ports, the array used in the
- * audio thread (inherited from NodeImpl), and the arrays used in the pre processor thread.
- * If two add port events arrive in the same cycle and the second pre processes before the
- * first executes, bad things happen (ports are lost).
- *
- * TODO: fix this using RCU?
- */
-
if (_data_type == PortType::UNKNOWN)
_error = UNKNOWN_TYPE;
}
@@ -75,8 +66,6 @@ CreatePort::CreatePort(
void
CreatePort::pre_process()
{
- _lock.acquire();
-
if (_error == UNKNOWN_TYPE || _engine.engine_store()->find_object(_path)) {
QueuedEvent::pre_process();
return;
@@ -156,16 +145,12 @@ CreatePort::execute(ProcessContext& context)
if (_driver_port) {
_engine.driver()->add_port(_driver_port);
}
-
- if (_request)
- _request->unblock();
}
void
CreatePort::post_process()
{
if (!_request) {
- _lock.release();
return;
}
@@ -188,8 +173,6 @@ CreatePort::post_process()
_request->respond_error(msg);
break;
}
-
- _lock.release();
}
} // namespace Server
diff --git a/src/server/events/CreatePort.hpp b/src/server/events/CreatePort.hpp
index e3c13fa1..56c0f0a0 100644
--- a/src/server/events/CreatePort.hpp
+++ b/src/server/events/CreatePort.hpp
@@ -18,8 +18,6 @@
#ifndef INGEN_EVENTS_CREATEPORT_HPP
#define INGEN_EVENTS_CREATEPORT_HPP
-#include <glibmm/thread.h>
-
#include "raul/Array.hpp"
#include "raul/Path.hpp"
@@ -75,8 +73,7 @@ private:
DriverPort* _driver_port; ///< Driver (eg Jack) port if this is a toplevel port
bool _succeeded;
- Resource::Properties _properties;
- Glib::RWLock::WriterLock _lock;
+ Resource::Properties _properties;
};
} // namespace Server
diff --git a/src/server/events/Delete.cpp b/src/server/events/Delete.cpp
index 4f13cd97..1e7b35e8 100644
--- a/src/server/events/Delete.cpp
+++ b/src/server/events/Delete.cpp
@@ -40,7 +40,7 @@ Delete::Delete(Engine& engine,
SharedPtr<Request> request,
FrameTime time,
const Raul::URI& uri)
- : QueuedEvent(engine, request, time, true)
+ : QueuedEvent(engine, request, time)
, _uri(uri)
, _store_iterator(engine.engine_store()->end())
, _garbage(NULL)
@@ -166,8 +166,6 @@ Delete::execute(ProcessContext& context)
_engine.maid()->push(parent_patch->compiled_patch());
parent_patch->compiled_patch(_compiled_patch);
}
-
- _request->unblock();
}
void
diff --git a/src/server/events/Disconnect.cpp b/src/server/events/Disconnect.cpp
index e7177fab..de078c3f 100644
--- a/src/server/events/Disconnect.cpp
+++ b/src/server/events/Disconnect.cpp
@@ -15,10 +15,12 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "raul/log.hpp"
+#include <glibmm/thread.h>
+
#include "raul/Maid.hpp"
#include "raul/Path.hpp"
-#include "events/Disconnect.hpp"
+#include "raul/log.hpp"
+
#include "AudioBuffer.hpp"
#include "ClientBroadcaster.hpp"
#include "ConnectionImpl.hpp"
@@ -32,6 +34,7 @@
#include "ProcessContext.hpp"
#include "Request.hpp"
#include "ThreadManager.hpp"
+#include "events/Disconnect.hpp"
using namespace std;
using namespace Raul;
@@ -40,12 +43,11 @@ namespace Ingen {
namespace Server {
namespace Events {
-Disconnect::Disconnect(
- Engine& engine,
- SharedPtr<Request> request,
- SampleCount timestamp,
- const Raul::Path& src_port_path,
- const Raul::Path& dst_port_path)
+Disconnect::Disconnect(Engine& engine,
+ SharedPtr<Request> request,
+ SampleCount timestamp,
+ const Raul::Path& src_port_path,
+ const Raul::Path& dst_port_path)
: QueuedEvent(engine, request, timestamp)
, _src_port_path(src_port_path)
, _dst_port_path(dst_port_path)
@@ -113,6 +115,8 @@ Disconnect::Impl::Impl(Engine& e,
void
Disconnect::pre_process()
{
+ Glib::RWLock::WriterLock lock(_engine.engine_store()->lock());
+
if (_src_port_path.parent().parent() != _dst_port_path.parent().parent()
&& _src_port_path.parent() != _dst_port_path.parent().parent()
&& _src_port_path.parent().parent() != _dst_port_path.parent()) {
diff --git a/src/server/events/Disconnect.hpp b/src/server/events/Disconnect.hpp
index a553fe79..d0124ce1 100644
--- a/src/server/events/Disconnect.hpp
+++ b/src/server/events/Disconnect.hpp
@@ -46,12 +46,11 @@ namespace Events {
class Disconnect : public QueuedEvent
{
public:
- Disconnect(
- Engine& engine,
- SharedPtr<Request> request,
- SampleCount timestamp,
- const Raul::Path& src_port_path,
- const Raul::Path& dst_port_path);
+ Disconnect(Engine& engine,
+ SharedPtr<Request> request,
+ SampleCount timestamp,
+ const Raul::Path& src_port_path,
+ const Raul::Path& dst_port_path);
void pre_process();
void execute(ProcessContext& context);
diff --git a/src/server/events/DisconnectAll.cpp b/src/server/events/DisconnectAll.cpp
index 23db5167..f355575a 100644
--- a/src/server/events/DisconnectAll.cpp
+++ b/src/server/events/DisconnectAll.cpp
@@ -16,6 +16,7 @@
*/
#include <boost/format.hpp>
+#include <glibmm/thread.h>
#include "raul/Array.hpp"
#include "raul/Maid.hpp"
@@ -98,7 +99,11 @@ DisconnectAll::maybe_remove_connection(ConnectionImpl* c)
void
DisconnectAll::pre_process()
{
+ Glib::RWLock::WriterLock lock(_engine.engine_store()->lock(), Glib::NOT_LOCK);
+
if (!_deleting) {
+ lock.acquire();
+
_parent = _engine.engine_store()->find_patch(_parent_path);
if (_parent == NULL) {
@@ -115,7 +120,8 @@ DisconnectAll::pre_process()
return;
}
- if (object->parent_patch() != _parent && object->parent()->parent_patch() != _parent) {
+ if (object->parent_patch() != _parent
+ && object->parent()->parent_patch() != _parent) {
_error = INVALID_PARENT_PATH;
QueuedEvent::pre_process();
return;
diff --git a/src/server/events/Move.cpp b/src/server/events/Move.cpp
index 2e006b8c..ec2f763e 100644
--- a/src/server/events/Move.cpp
+++ b/src/server/events/Move.cpp
@@ -15,15 +15,18 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <glibmm/thread.h>
+
#include "raul/Path.hpp"
-#include "events/Move.hpp"
+
#include "ClientBroadcaster.hpp"
+#include "Driver.hpp"
#include "Engine.hpp"
-#include "NodeImpl.hpp"
#include "EngineStore.hpp"
+#include "NodeImpl.hpp"
#include "PatchImpl.hpp"
#include "Request.hpp"
-#include "Driver.hpp"
+#include "events/Move.hpp"
using namespace std;
using namespace Raul;
@@ -48,6 +51,8 @@ Move::~Move()
void
Move::pre_process()
{
+ Glib::RWLock::WriterLock lock(_engine.engine_store()->lock());
+
if (!_old_path.parent().is_parent_of(_new_path)) {
_error = PARENT_DIFFERS;
QueuedEvent::pre_process();
diff --git a/src/server/events/SetMetadata.cpp b/src/server/events/SetMetadata.cpp
index 1a2d6b17..efa57198 100644
--- a/src/server/events/SetMetadata.cpp
+++ b/src/server/events/SetMetadata.cpp
@@ -57,7 +57,7 @@ SetMetadata::SetMetadata(
const URI& subject,
const Properties& properties,
const Properties& remove)
- : QueuedEvent(engine, request, timestamp, false)
+ : QueuedEvent(engine, request, timestamp)
, _create_event(NULL)
, _subject(subject)
, _properties(properties)
@@ -67,6 +67,7 @@ SetMetadata::SetMetadata(
, _compiled_patch(NULL)
, _create(create)
, _context(context)
+ , _lock(engine.engine_store()->lock(), Glib::NOT_LOCK)
{
if (context != Resource::DEFAULT) {
Resource::set_context(_properties, context);
@@ -102,6 +103,8 @@ SetMetadata::pre_process()
const bool is_graph_object = Path::is_path(_subject);
+ _lock.acquire();
+
_object = is_graph_object
? _engine.engine_store()->find_object(Path(_subject.str()))
: static_cast<Shared::ResourceImpl*>(_engine.node_factory()->plugin(_subject));
@@ -135,7 +138,6 @@ SetMetadata::pre_process()
_create_event = new CreateNode(_engine, sub_request, _time,
path, p->second.get_uri(), _properties);
} else if (is_port) {
- _blocking = bool(_request);
_create_event = new CreatePort(_engine, sub_request, _time,
path, data_type.uri(), is_output, _properties);
}
@@ -219,7 +221,6 @@ SetMetadata::pre_process()
} else if (key == uris.ingen_polyphony) {
if (value.type() == Atom::INT) {
op = POLYPHONY;
- _blocking = true;
_patch->prepare_internal_poly(*_engine.buffer_factory(), value.get_int32());
} else {
_error = BAD_VALUE_TYPE;
@@ -230,7 +231,6 @@ SetMetadata::pre_process()
if (parent) {
if (value.type() == Atom::BOOL) {
op = POLYPHONIC;
- _blocking = true;
obj->set_property(key, value.get_bool(), value.context());
NodeImpl* node = dynamic_cast<NodeImpl*>(obj);
if (node)
@@ -340,9 +340,6 @@ SetMetadata::execute(ProcessContext& context)
}
QueuedEvent::execute(context);
-
- if (_blocking)
- _request->unblock();
}
void
@@ -380,6 +377,8 @@ SetMetadata::post_process()
% _subject % _error_predicate).str());
break;
}
+
+ _lock.release();
}
} // namespace Server
diff --git a/src/server/events/SetMetadata.hpp b/src/server/events/SetMetadata.hpp
index 6e2a93a2..bf359b79 100644
--- a/src/server/events/SetMetadata.hpp
+++ b/src/server/events/SetMetadata.hpp
@@ -18,6 +18,7 @@
#ifndef INGEN_EVENTS_SETMETADATA_HPP
#define INGEN_EVENTS_SETMETADATA_HPP
+#include <glibmm/thread.h>
#include <vector>
@@ -120,6 +121,8 @@ private:
ControlBindings::Key _binding;
SharedPtr<ControlBindings::Bindings> _old_bindings;
+
+ Glib::RWLock::WriterLock _lock;
};
} // namespace Server