partially revert 30b087ab3, CoreAudio SDK uses "Frames"
[ardour.git] / libs / pbd / event_loop.cc
index 3f5eeb0a755d3c9325fa2aa4a5162d0bf1ea8d04..e003a8d37a0ccaa635c6c8eab757dbdc939d326f 100644 (file)
@@ -27,7 +27,7 @@
 #include "pbd/error.h"
 #include "pbd/stacktrace.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace PBD;
 using namespace std;
@@ -45,6 +45,18 @@ EventLoop::EventLoop (string const& name)
 {
 }
 
+EventLoop::~EventLoop ()
+{
+       trash.sort();
+       trash.unique();
+       for (std::list<InvalidationRecord*>::iterator r = trash.begin(); r != trash.end(); ++r) {
+               if (!(*r)->in_use ()) {
+                       delete *r;
+               }
+       }
+       trash.clear ();
+}
+
 EventLoop*
 EventLoop::get_event_loop_for_thread()
 {
@@ -60,7 +72,7 @@ EventLoop::set_event_loop_for_thread (EventLoop* loop)
 void*
 EventLoop::invalidate_request (void* data)
 {
-        InvalidationRecord* ir = (InvalidationRecord*) data;
+       InvalidationRecord* ir = (InvalidationRecord*) data;
 
        /* Some of the requests queued with an EventLoop may involve functors
         * that make method calls to objects whose lifetime is shorter
@@ -86,16 +98,14 @@ EventLoop::invalidate_request (void* data)
         * inherit (indirectly) from sigc::trackable.
         */
 
-        if (ir->event_loop) {
+       if (ir->event_loop) {
+               DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: EventLoop::invalidate_request %2\n", ir->event_loop, ir));
                Glib::Threads::Mutex::Lock lm (ir->event_loop->slot_invalidation_mutex());
-               for (list<BaseRequestObject*>::iterator i = ir->requests.begin(); i != ir->requests.end(); ++i) {
-                       (*i)->valid = false;
-                       (*i)->invalidation = 0;
-               }
-               delete ir;
-        }
+               ir->invalidate ();
+               ir->event_loop->trash.push_back(ir);
+       }
 
-        return 0;
+       return 0;
 }
 
 vector<EventLoop::ThreadBufferMapping>
@@ -147,7 +157,7 @@ EventLoop::pre_register (const string& emitting_thread_name, uint32_t num_reques
         */
 
        ThreadBufferMapping mapping;
-       Glib::Threads::RWLock::ReaderLock lm (thread_buffer_requests_lock);
+       Glib::Threads::RWLock::WriterLock lm (thread_buffer_requests_lock);
 
        for (RequestBufferSuppliers::iterator trs = request_buffer_suppliers.begin(); trs != request_buffer_suppliers.end(); ++trs) {