Fix compilation on Windows. Probably.
[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         /* Some of the requests queued with an EventLoop may involve functors
29          * that make method calls to objects whose lifetime is shorter
30          * than the EventLoop's. We do not want to make those calls if the
31          * object involve has been destroyed. To prevent this, we 
32          * provide a way to invalidate those requests when the object is
33          * destroyed.
34          *
35          * An object was passed to __invalidator() which added a callback to
36          * EventLoop::invalidate_request() to its "notify when destroyed"
37          * list. __invalidator() returned an InvalidationRecord that has been
38          * to passed to this function as data.
39          *
40          * The object is currently being destroyed and so we want to
41          * mark all requests involving this object that are queued with
42          * any EventLoop as invalid. 
43          *
44          * As of April 2012, we are usign sigc::trackable as the base object
45          * used to queue calls to ::invalidate_request() to be made upon
46          * destruction, via its ::add_destroy_notify_callback() API. This is
47          * not necessarily ideal, but it is very close to precisely what we
48          * want, and many of the objects we want to do this with already
49          * inherit (indirectly) from sigc::trackable.
50          */
51         
52         if (ir->event_loop) {
53                 Glib::Mutex::Lock lm (ir->event_loop->slot_invalidation_mutex());
54                 for (list<BaseRequestObject*>::iterator i = ir->requests.begin(); i != ir->requests.end(); ++i) {
55                         (*i)->valid = false;
56                         (*i)->invalidation = 0;
57                 }
58                 delete ir;
59         } 
60
61         return 0;
62 }
63