ardour
event_loop.cc
Go to the documentation of this file.
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*
32  return thread_event_loop.get ();
33 }
34 
35 void
37 {
38  thread_event_loop.set (loop);
39 }
40 
41 void*
43 {
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) {
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 
static void set_event_loop_for_thread(EventLoop *ui)
Definition: event_loop.cc:36
static Glib::Threads::Private< EventLoop > thread_event_loop
Definition: event_loop.h:80
Definition: Beats.hpp:239
static EventLoop * get_event_loop_for_thread()
Definition: event_loop.cc:31
std::list< BaseRequestObject * > requests
Definition: event_loop.h:54
static void * invalidate_request(void *data)
Definition: event_loop.cc:42
virtual Glib::Threads::Mutex & slot_invalidation_mutex()=0
Definition: debug.h:30
static void do_not_delete_the_loop_pointer(void *)
Definition: event_loop.cc:26