rework locking (fa07233a, 112fba182)
[ardour.git] / libs / pbd / event_loop.cc
index e6f5414d11ff2136327574ebc420947be4d18f19..a1b3670a6870964d51389228e5fd86406c020780 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;
@@ -60,7 +60,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 +86,19 @@ EventLoop::invalidate_request (void* data)
         * inherit (indirectly) from sigc::trackable.
         */
 
-        if (ir->event_loop) {
-               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;
+       if (ir->event_loop) {
+               {
+                       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;
+                       }
                }
+               // should this not always be deleted, regardless if there's an event_loop?
                delete ir;
-        }
+       }
 
-        return 0;
+       return 0;
 }
 
 vector<EventLoop::ThreadBufferMapping>
@@ -147,7 +150,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) {
 
@@ -219,3 +222,15 @@ EventLoop::pre_register (const string& emitting_thread_name, uint32_t num_reques
        }
 }
 
+void
+EventLoop::remove_request_buffer_from_map (void* ptr)
+{
+       Glib::Threads::RWLock::WriterLock lm (thread_buffer_requests_lock);
+
+       for (ThreadRequestBufferList::iterator x = thread_buffer_requests.begin(); x != thread_buffer_requests.end(); ++x) {
+               if (x->second.request_buffer == ptr) {
+                       thread_buffer_requests.erase (x);
+                       break;
+               }
+       }
+}