allow invalidation-of-UI-request-by-object-deletion to work more often by setting...
[ardour.git] / libs / pbd / event_loop.cc
1 #include <iostream>
2 #include "pbd/event_loop.h"
3 #include "pbd/stacktrace.h"
4
5 using namespace PBD;
6 using namespace std;
7
8 Glib::StaticPrivate<EventLoop> EventLoop::thread_event_loop;
9
10 static void do_not_delete_the_loop_pointer (void*) { }
11
12 EventLoop* 
13 EventLoop::get_event_loop_for_thread() {
14         return thread_event_loop.get ();
15 }
16
17 void 
18 EventLoop::set_event_loop_for_thread (EventLoop* loop) 
19 {
20         thread_event_loop.set (loop, do_not_delete_the_loop_pointer); 
21 }
22
23 /** Called when a sigc::trackable that was connected to using the invalidator() macro
24  *  is destroyed.
25  */
26 void* 
27 EventLoop::invalidate_request (void* data)
28 {
29         InvalidationRecord* ir = (InvalidationRecord*) data;
30
31         if (ir->event_loop) {
32                 Glib::Mutex::Lock lm (ir->event_loop->slot_invalidation_mutex());
33                 for (list<BaseRequestObject*>::iterator i = ir->requests.begin(); i != ir->requests.end(); ++i) {
34                         (*i)->valid = false;
35                         (*i)->invalidation = 0;
36                 }
37                 delete ir;
38         } 
39
40         return 0;
41 }
42