2 Copyright (C) 2012 Paul Davis
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.
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.
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.
20 #include "pbd/event_loop.h"
21 #include "pbd/stacktrace.h"
26 static void do_not_delete_the_loop_pointer (void*) { }
28 Glib::Threads::Private<EventLoop> EventLoop::thread_event_loop (do_not_delete_the_loop_pointer);
31 EventLoop::get_event_loop_for_thread() {
32 return thread_event_loop.get ();
36 EventLoop::set_event_loop_for_thread (EventLoop* loop)
38 thread_event_loop.set (loop);
42 EventLoop::invalidate_request (void* data)
44 InvalidationRecord* ir = (InvalidationRecord*) data;
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
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.
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.
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.
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) {
74 (*i)->invalidation = 0;