13
0

change AbstractUI implementation to use EventLoop::event_loop_name() and add extra DEBUG_TRACE statements to track thread registration with event loops

This commit is contained in:
Paul Davis 2015-12-12 11:00:24 -05:00
parent a419fb5af0
commit f32fc212f3

View File

@ -75,7 +75,7 @@ AbstractUI<RequestObject>::AbstractUI (const string& name)
} }
template <typename RequestObject> void template <typename RequestObject> void
AbstractUI<RequestObject>::register_thread (string target_gui, pthread_t thread_id, string /*thread name*/, uint32_t num_requests) AbstractUI<RequestObject>::register_thread (string target_gui, pthread_t thread_id, string thread_name, uint32_t num_requests)
{ {
/* the calling thread wants to register with the thread that runs this /* the calling thread wants to register with the thread that runs this
* UI's event loop, so that it will have its own per-thread queue of * UI's event loop, so that it will have its own per-thread queue of
@ -83,10 +83,13 @@ AbstractUI<RequestObject>::register_thread (string target_gui, pthread_t thread_
* do so in a realtime-safe manner (no locks). * do so in a realtime-safe manner (no locks).
*/ */
if (target_gui != name()) { DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("in %1 (thread name %4), %2 (%5) wants to register with %3\n", event_loop_name(), thread_name, target_gui, pthread_name(), pthread_self()));
if (target_gui != event_loop_name()) {
/* this UI is not the UI that the calling thread is trying to /* this UI is not the UI that the calling thread is trying to
register with register with
*/ */
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1 : not the registration target\n", event_loop_name()));
return; return;
} }
@ -101,11 +104,14 @@ AbstractUI<RequestObject>::register_thread (string target_gui, pthread_t thread_
if (b) { if (b) {
/* thread already registered with this UI /* thread already registered with this UI
*/ */
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1 : %2 is already registered\n", event_loop_name(), thread_name));
return; return;
} }
/* create a new request queue/ringbuffer */ /* create a new request queue/ringbuffer */
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("create new request buffer for %1 in %2\n", thread_name, event_loop_name()));
b = new RequestBuffer (num_requests, *this); b = new RequestBuffer (num_requests, *this);
{ {
@ -151,11 +157,11 @@ AbstractUI<RequestObject>::get_request (RequestType rt)
rbuf->get_write_vector (&vec); rbuf->get_write_vector (&vec);
if (vec.len[0] == 0) { if (vec.len[0] == 0) {
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: no space in per thread pool for request of type %2\n", name(), rt)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: no space in per thread pool for request of type %2\n", event_loop_name(), rt));
return 0; return 0;
} }
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: allocated per-thread request of type %2, caller %3\n", name(), rt, pthread_name())); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: allocated per-thread request of type %2, caller %3\n", event_loop_name(), rt, pthread_name()));
vec.buf[0]->type = rt; vec.buf[0]->type = rt;
vec.buf[0]->valid = true; vec.buf[0]->valid = true;
@ -167,7 +173,7 @@ AbstractUI<RequestObject>::get_request (RequestType rt)
* are not at work. * are not at work.
*/ */
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: allocated normal heap request of type %2, caller %3\n", name(), rt, pthread_name())); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: allocated normal heap request of type %2, caller %3\n", event_loop_name(), rt, pthread_name()));
RequestObject* req = new RequestObject; RequestObject* req = new RequestObject;
req->type = rt; req->type = rt;
@ -222,7 +228,7 @@ AbstractUI<RequestObject>::handle_ui_requests ()
for (i = request_buffers.begin(); i != request_buffers.end(); ) { for (i = request_buffers.begin(); i != request_buffers.end(); ) {
if ((*i).second->dead) { if ((*i).second->dead) {
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 deleting dead per-thread request buffer for %3 @ %4\n", DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 deleting dead per-thread request buffer for %3 @ %4\n",
name(), pthread_name(), i->second)); event_loop_name(), pthread_name(), i->second));
delete (*i).second; delete (*i).second;
RequestBufferMapIterator tmp = i; RequestBufferMapIterator tmp = i;
++tmp; ++tmp;
@ -250,7 +256,7 @@ AbstractUI<RequestObject>::handle_ui_requests ()
request_buffer_map_lock.lock (); request_buffer_map_lock.lock ();
if (!req->valid) { if (!req->valid) {
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 handling invalid heap request, type %3, deleting\n", name(), pthread_name(), req->type)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 handling invalid heap request, type %3, deleting\n", event_loop_name(), pthread_name(), req->type));
delete req; delete req;
request_buffer_map_lock.unlock (); request_buffer_map_lock.unlock ();
continue; continue;
@ -262,7 +268,7 @@ AbstractUI<RequestObject>::handle_ui_requests ()
*/ */
if (req->invalidation) { if (req->invalidation) {
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 remove request from its invalidation list\n", name(), pthread_name())); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 remove request from its invalidation list\n", event_loop_name(), pthread_name()));
/* after this call, if the object referenced by the /* after this call, if the object referenced by the
* invalidation record is deleted, it will no longer * invalidation record is deleted, it will no longer
@ -290,7 +296,7 @@ AbstractUI<RequestObject>::handle_ui_requests ()
lm.release (); lm.release ();
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 execute request type %3\n", name(), pthread_name(), req->type)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 execute request type %3\n", event_loop_name(), pthread_name(), req->type));
/* and lets do it ... this is a virtual call so that each /* and lets do it ... this is a virtual call so that each
* specific type of UI can have its own set of requests without * specific type of UI can have its own set of requests without
@ -299,7 +305,7 @@ AbstractUI<RequestObject>::handle_ui_requests ()
do_request (req); do_request (req);
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 delete heap request type %3\n", name(), pthread_name(), req->type)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 delete heap request type %3\n", event_loop_name(), pthread_name(), req->type));
delete req; delete req;
/* re-acquire the list lock so that we check again */ /* re-acquire the list lock so that we check again */
@ -324,7 +330,7 @@ AbstractUI<RequestObject>::send_request (RequestObject *req)
/* the thread that runs this UI's event loop is sending itself /* the thread that runs this UI's event loop is sending itself
a request: we dispatch it immediately and inline. a request: we dispatch it immediately and inline.
*/ */
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 direct dispatch of request type %3\n", name(), pthread_name(), req->type)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 direct dispatch of request type %3\n", event_loop_name(), pthread_name(), req->type));
do_request (req); do_request (req);
delete req; delete req;
} else { } else {
@ -344,13 +350,13 @@ AbstractUI<RequestObject>::send_request (RequestObject *req)
RequestBuffer* rbuf = per_thread_request_buffer.get (); RequestBuffer* rbuf = per_thread_request_buffer.get ();
if (rbuf != 0) { if (rbuf != 0) {
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 send per-thread request type %3\n", name(), pthread_name(), req->type)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 send per-thread request type %3\n", event_loop_name(), pthread_name(), req->type));
rbuf->increment_write_ptr (1); rbuf->increment_write_ptr (1);
} else { } else {
/* no per-thread buffer, so just use a list with a lock so that it remains /* no per-thread buffer, so just use a list with a lock so that it remains
single-reader/single-writer semantics single-reader/single-writer semantics
*/ */
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 send heap request type %3\n", name(), pthread_name(), req->type)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 send heap request type %3\n", event_loop_name(), pthread_name(), req->type));
Glib::Threads::Mutex::Lock lm (request_list_lock); Glib::Threads::Mutex::Lock lm (request_list_lock);
request_list.push_back (req); request_list.push_back (req);
} }
@ -367,7 +373,7 @@ template<typename RequestObject> void
AbstractUI<RequestObject>::call_slot (InvalidationRecord* invalidation, const boost::function<void()>& f) AbstractUI<RequestObject>::call_slot (InvalidationRecord* invalidation, const boost::function<void()>& f)
{ {
if (caller_is_self()) { if (caller_is_self()) {
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 direct dispatch of call slot via functor @ %3, invalidation %4\n", name(), pthread_name(), &f, invalidation)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 direct dispatch of call slot via functor @ %3, invalidation %4\n", event_loop_name(), pthread_name(), &f, invalidation));
f (); f ();
return; return;
} }
@ -378,7 +384,7 @@ AbstractUI<RequestObject>::call_slot (InvalidationRecord* invalidation, const bo
return; return;
} }
DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 queue call-slot using functor @ %3, invalidation %4\n", name(), pthread_name(), &f, invalidation)); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 queue call-slot using functor @ %3, invalidation %4\n", event_loop_name(), pthread_name(), &f, invalidation));
/* copy semantics: copy the functor into the request object */ /* copy semantics: copy the functor into the request object */
@ -401,4 +407,3 @@ AbstractUI<RequestObject>::call_slot (InvalidationRecord* invalidation, const bo
send_request (req); send_request (req);
} }