globally remove all trailing whitespace from ardour code base.
[ardour.git] / libs / pbd / event_loop.cc
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "pbd/event_loop.h"
21 #include "pbd/stacktrace.h"
22
23 using namespace PBD;
24 using namespace std;
25
26 static void do_not_delete_the_loop_pointer (void*) { }
27
28 Glib::Threads::Private<EventLoop> EventLoop::thread_event_loop (do_not_delete_the_loop_pointer);
29
30 EventLoop*
31 EventLoop::get_event_loop_for_thread() {
32         return thread_event_loop.get ();
33 }
34
35 void
36 EventLoop::set_event_loop_for_thread (EventLoop* loop)
37 {
38         thread_event_loop.set (loop);
39 }
40
41 void*
42 EventLoop::invalidate_request (void* data)
43 {
44         InvalidationRecord* ir = (InvalidationRecord*) data;
45
46         /* Some of the requests queued with an EventLoop may involve functors
47          * that make method calls to objects whose lifetime is shorter
48          * than the EventLoop's. We do not want to make those calls if the
49          * object involve has been destroyed. To prevent this, we
50          * provide a way to invalidate those requests when the object is
51          * destroyed.
52          *
53          * An object was passed to __invalidator() which added a callback to
54          * EventLoop::invalidate_request() to its "notify when destroyed"
55          * list. __invalidator() returned an InvalidationRecord that has been
56          * to passed to this function as data.
57          *
58          * The object is currently being destroyed and so we want to
59          * mark all requests involving this object that are queued with
60          * any EventLoop as invalid.
61          *
62          * As of April 2012, we are usign sigc::trackable as the base object
63          * used to queue calls to ::invalidate_request() to be made upon
64          * destruction, via its ::add_destroy_notify_callback() API. This is
65          * not necessarily ideal, but it is very close to precisely what we
66          * want, and many of the objects we want to do this with already
67          * inherit (indirectly) from sigc::trackable.
68          */
69         
70         if (ir->event_loop) {
71                 Glib::Threads::Mutex::Lock lm (ir->event_loop->slot_invalidation_mutex());
72                 for (list<BaseRequestObject*>::iterator i = ir->requests.begin(); i != ir->requests.end(); ++i) {
73                         (*i)->valid = false;
74                         (*i)->invalidation = 0;
75                 }
76                 delete ir;
77         }
78
79         return 0;
80 }
81