clean up consequences of using IO/Port/Buffer for LTC output, and in related work...
[ardour.git] / libs / pbd / event_loop.cc
1 #include "pbd/event_loop.h"
2 #include "pbd/stacktrace.h"
3
4 using namespace PBD;
5 using namespace std;
6
7 static void do_not_delete_the_loop_pointer (void*) { }
8
9 Glib::Threads::Private<EventLoop> EventLoop::thread_event_loop (do_not_delete_the_loop_pointer); 
10
11 EventLoop* 
12 EventLoop::get_event_loop_for_thread() {
13         return thread_event_loop.get ();
14 }
15
16 void 
17 EventLoop::set_event_loop_for_thread (EventLoop* loop) 
18 {
19         thread_event_loop.set (loop);
20 }
21
22 void* 
23 EventLoop::invalidate_request (void* data)
24 {
25         InvalidationRecord* ir = (InvalidationRecord*) data;
26
27         /* Some of the requests queued with an EventLoop may involve functors
28          * that make method calls to objects whose lifetime is shorter
29          * than the EventLoop's. We do not want to make those calls if the
30          * object involve has been destroyed. To prevent this, we 
31          * provide a way to invalidate those requests when the object is
32          * destroyed.
33          *
34          * An object was passed to __invalidator() which added a callback to
35          * EventLoop::invalidate_request() to its "notify when destroyed"
36          * list. __invalidator() returned an InvalidationRecord that has been
37          * to passed to this function as data.
38          *
39          * The object is currently being destroyed and so we want to
40          * mark all requests involving this object that are queued with
41          * any EventLoop as invalid. 
42          *
43          * As of April 2012, we are usign sigc::trackable as the base object
44          * used to queue calls to ::invalidate_request() to be made upon
45          * destruction, via its ::add_destroy_notify_callback() API. This is
46          * not necessarily ideal, but it is very close to precisely what we
47          * want, and many of the objects we want to do this with already
48          * inherit (indirectly) from sigc::trackable.
49          */
50         
51         if (ir->event_loop) {
52                 Glib::Threads::Mutex::Lock lm (ir->event_loop->slot_invalidation_mutex());
53                 for (list<BaseRequestObject*>::iterator i = ir->requests.begin(); i != ir->requests.end(); ++i) {
54                         (*i)->valid = false;
55                         (*i)->invalidation = 0;
56                 }
57                 delete ir;
58         } 
59
60         return 0;
61 }
62