From 4a3d7877f6b03fac7755f997b945583ba5732d13 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 4 Dec 2009 19:24:09 +0000 Subject: 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 --- libs/ardour/session_events.cc | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'libs/ardour/session_events.cc') 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 (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 (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) -- cgit v1.2.3