handle deletion of UI objects between the time that a callback is queued with the...
[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 void* 
24 EventLoop::invalidate_request (void* data)
25 {
26         InvalidationRecord* ir = (InvalidationRecord*) data;
27
28         if (ir->event_loop) {
29                 Glib::Mutex::Lock lm (ir->event_loop->slot_invalidation_mutex());
30                 if (ir->request) {
31                         cerr << "Object deleted had outstanding event loop request, IR created @ "
32                              << ir->file << ':' << ir->line
33                              << endl;
34                         ir->request->valid = false;
35                         ir->request->invalidation = 0;
36                 } else {
37                         cerr << "No queued request associated with object deletion from "
38                              << ir->file << ':' << ir->line
39                              << endl;
40                         
41                 }
42
43                 delete ir;
44         }
45
46         return 0;
47 }
48