summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-12-04 19:24:09 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-12-04 19:24:09 +0000
commit4a3d7877f6b03fac7755f997b945583ba5732d13 (patch)
tree1099df5854224acbb17a650215d7f07710b8babe /libs/ardour
parent478fd92039443743babec98812f10921209f1e5a (diff)
cross-thread handling of SessionEvent allocation/deallocation, with widespread consequences
git-svn-id: svn://localhost/ardour2/branches/3.0@6283 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/analyser.cc2
-rw-r--r--libs/ardour/ardour/session_event.h19
-rw-r--r--libs/ardour/audioengine.cc2
-rw-r--r--libs/ardour/butler.cc1
-rw-r--r--libs/ardour/enums.cc6
-rw-r--r--libs/ardour/export_channel_configuration.cc1
-rw-r--r--libs/ardour/globals.cc12
-rw-r--r--libs/ardour/session_events.cc40
-rw-r--r--libs/ardour/session_midi.cc1
-rw-r--r--libs/ardour/source_factory.cc1
-rw-r--r--libs/ardour/wscript4
11 files changed, 72 insertions, 17 deletions
diff --git a/libs/ardour/analyser.cc b/libs/ardour/analyser.cc
index 2e68cfed83..8e2ec99f27 100644
--- a/libs/ardour/analyser.cc
+++ b/libs/ardour/analyser.cc
@@ -19,6 +19,7 @@
#include "ardour/analyser.h"
#include "ardour/audiofilesource.h"
+#include "ardour/session_event.h"
#include "ardour/transient_detector.h"
#include "pbd/pthread_utils.h"
@@ -76,6 +77,7 @@ void
Analyser::work ()
{
PBD::notify_gui_about_thread_creation (pthread_self(), string ("analyser-") + to_string (pthread_self(), std::dec));
+ SessionEvent::create_per_thread_pool ("Analyser", 64);
while (true) {
analysis_queue_lock.lock ();
diff --git a/libs/ardour/ardour/session_event.h b/libs/ardour/ardour/session_event.h
index 767c374988..07c795257f 100644
--- a/libs/ardour/ardour/session_event.h
+++ b/libs/ardour/ardour/session_event.h
@@ -98,18 +98,17 @@ struct SessionEvent {
return e1->before (*e2);
}
- void *operator new (size_t) {
- return pool.alloc ();
- }
-
- void operator delete (void *ptr, size_t /*size*/) {
- pool.release (ptr);
- }
+ void* operator new (size_t);
+ void operator delete (void *ptr, size_t /*size*/);
static const nframes_t Immediate = 0;
+ static void create_per_thread_pool (const std::string& n, unsigned long nitems);
+ static void init_event_pool ();
+
private:
- static MultiAllocSingleReleasePool pool;
+ static PerThreadPool* pool;
+ CrossThreadPool* own_pool;
};
class SessionEventManager {
@@ -120,8 +119,8 @@ class SessionEventManager {
void add_event (nframes64_t action_frame, SessionEvent::Type type, nframes64_t target_frame = 0);
void remove_event (nframes64_t frame, SessionEvent::Type type);
void clear_events (SessionEvent::Type type);
-
-
+
+
protected:
RingBuffer<SessionEvent*> pending_events;
typedef std::list<SessionEvent *> Events;
diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc
index 2f344eb8ba..b69b06c4db 100644
--- a/libs/ardour/audioengine.cc
+++ b/libs/ardour/audioengine.cc
@@ -136,6 +136,8 @@ _thread_init_callback (void * /*arg*/)
*/
PBD::notify_gui_about_thread_creation (pthread_self(), X_("Audioengine"), 4096);
+ SessionEvent::create_per_thread_pool (X_("Audioengine"), 512);
+
MIDI::JACK_MidiPort::set_process_thread (pthread_self());
}
diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc
index 3d43c11e38..76a7fb2424 100644
--- a/libs/ardour/butler.cc
+++ b/libs/ardour/butler.cc
@@ -114,6 +114,7 @@ void *
Butler::_thread_work (void* arg)
{
PBD::notify_gui_about_thread_creation (pthread_self(), X_("Butler"));
+ SessionEvent::create_per_thread_pool ("butler events", 64);
return ((Butler *) arg)->thread_work ();
}
diff --git a/libs/ardour/enums.cc b/libs/ardour/enums.cc
index aa7dda9e50..0676973e53 100644
--- a/libs/ardour/enums.cc
+++ b/libs/ardour/enums.cc
@@ -43,6 +43,8 @@ using namespace PBD;
using namespace ARDOUR;
using namespace MIDI;
+namespace ARDOUR {
+
void
setup_enum_writer ()
{
@@ -584,6 +586,8 @@ setup_enum_writer ()
}
+} /* namespace ARDOUR */
+
/* deserializing types from ardour/types.h */
std::istream& operator>>(std::istream& o, HeaderFormat& var)
@@ -795,3 +799,5 @@ std::ostream& operator<<(std::ostream& o, const WaveformShape& var)
std::string s = enum_2_string (var);
return o << s;
}
+
+
diff --git a/libs/ardour/export_channel_configuration.cc b/libs/ardour/export_channel_configuration.cc
index 47bbbd276c..047aadc671 100644
--- a/libs/ardour/export_channel_configuration.cc
+++ b/libs/ardour/export_channel_configuration.cc
@@ -177,6 +177,7 @@ void *
ExportChannelConfiguration::_write_files (void *arg)
{
notify_gui_about_thread_creation (pthread_self(), "Export post-processing");
+ SessionEvent::create_per_thread_pool ("exporter events", 64);
// cc can be trated like 'this'
WriterThread & cc (*((WriterThread *) arg));
diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc
index 6e6ae9bf80..9953524c34 100644
--- a/libs/ardour/globals.cc
+++ b/libs/ardour/globals.cc
@@ -72,6 +72,7 @@
#include "ardour/rc_configuration.h"
#include "ardour/runtime_functions.h"
#include "ardour/session.h"
+#include "ardour/session_event.h"
#include "ardour/source_factory.h"
#include "ardour/utils.h"
@@ -110,6 +111,8 @@ mix_buffers_no_gain_t ARDOUR::mix_buffers_no_gain = 0;
sigc::signal<void,std::string> ARDOUR::BootMessage;
+void ARDOUR::setup_enum_writer ();
+
int
ARDOUR::setup_midi ()
{
@@ -283,14 +286,15 @@ lotsa_files_please ()
int
ARDOUR::init (bool use_vst, bool try_optimization)
{
- if (!Glib::thread_supported())
+ if (!Glib::thread_supported()) {
Glib::thread_init();
+ }
- PBD::ID::init ();
+ (void) bindtextdomain(PACKAGE, LOCALEDIR);
- extern void setup_enum_writer ();
+ PBD::ID::init ();
+ SessionEvent::init_event_pool ();
- (void) bindtextdomain(PACKAGE, LOCALEDIR);
/* provide a state version for the few cases that need it and are not
driven by reading state from disk (e.g. undo/redo)
diff --git a/libs/ardour/session_events.cc b/libs/ardour/session_events.cc
index 98620e269f..8818436ed7 100644
--- a/libs/ardour/session_events.cc
+++ b/libs/ardour/session_events.cc
@@ -37,7 +37,45 @@ using namespace std;
using namespace ARDOUR;
using namespace PBD;
-MultiAllocSingleReleasePool SessionEvent::pool ("event", sizeof (SessionEvent), 512);
+PerThreadPool* SessionEvent::pool;
+
+void
+SessionEvent::init_event_pool ()
+{
+ pool = new PerThreadPool;
+}
+
+void
+SessionEvent::create_per_thread_pool (const std::string& name, unsigned long nitems)
+{
+ /* this is a per-thread call that simply creates a thread-private ptr to
+ a CrossThreadPool for use by this thread whenever events are allocated/released
+ from SessionEvent::pool()
+ */
+ pool->create_per_thread_pool (name, sizeof (SessionEvent), nitems);
+}
+
+void *
+SessionEvent::operator new (size_t)
+{
+ CrossThreadPool* p = pool->per_thread_pool ();
+ SessionEvent* ev = static_cast<SessionEvent*> (p->alloc ());
+ ev->own_pool = p;
+ return ev;
+}
+
+void
+SessionEvent::operator delete (void *ptr, size_t /*size*/)
+{
+ Pool* p = pool->per_thread_pool ();
+ SessionEvent* ev = static_cast<SessionEvent*> (ptr);
+
+ if (p == ev->own_pool) {
+ p->release (ptr);
+ } else {
+ ev->own_pool->push (ev);
+ }
+}
void
SessionEventManager::add_event (nframes64_t frame, SessionEvent::Type type, nframes64_t target_frame)
diff --git a/libs/ardour/session_midi.cc b/libs/ardour/session_midi.cc
index b05cfc83a2..fe332b71c2 100644
--- a/libs/ardour/session_midi.cc
+++ b/libs/ardour/session_midi.cc
@@ -1094,6 +1094,7 @@ Session::midi_thread_work ()
vector<MIDI::Port*> ports;
PBD::notify_gui_about_thread_creation (pthread_self(), X_("MIDI"), 2048);
+ SessionEvent::create_per_thread_pool (X_("MIDI I/O"), 128);
memset (&rtparam, 0, sizeof (rtparam));
rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc
index 6753a0738f..b85f5b67a0 100644
--- a/libs/ardour/source_factory.cc
+++ b/libs/ardour/source_factory.cc
@@ -59,6 +59,7 @@ static void
peak_thread_work ()
{
PBD::notify_gui_about_thread_creation (pthread_self(), string ("peakbuilder-") + to_string (pthread_self(), std::dec));
+ SessionEvent::create_per_thread_pool (X_("PeakFile Builder "), 64);
while (true) {
diff --git a/libs/ardour/wscript b/libs/ardour/wscript
index 22d86ffd3c..67998ff5fb 100644
--- a/libs/ardour/wscript
+++ b/libs/ardour/wscript
@@ -263,7 +263,7 @@ def build(bld):
obj.includes = ['.', '../surfaces/control_protocol', '..']
obj.name = 'libardour'
obj.target = 'ardour'
- obj.uselib = 'GLIBMM AUBIO SIGCPP XML UUID JACK SNDFILE SAMPLERATE LRDF OSX'
+ obj.uselib = 'GLIBMM GTHREAD AUBIO SIGCPP XML UUID JACK SNDFILE SAMPLERATE LRDF OSX'
obj.uselib_local = 'libpbd libmidipp libevoral libvamphost libvampplugin libtaglib librubberband'
obj.vnum = LIBARDOUR_LIB_VERSION
obj.install_path = os.path.join(bld.env['LIBDIR'], 'ardour3')
@@ -324,7 +324,7 @@ def build(bld):
test/testrunner.cpp
'''.split()
testobj.includes = obj.includes + ['../pbd/']
- testobj.uselib = 'CPPUNIT SIGCPP JACK GLIBMM SAMPLERATE XML LRDF'
+ testobj.uselib = 'CPPUNIT SIGCPP JACK GLIBMM GTHREAD SAMPLERATE XML LRDF'
testobj.uselib_local = 'libpbd libmidipp libardour'
testobj.name = 'libardour-tests'
testobj.target = 'run-tests'