From 4b3043ccdafbfcc373e2107aa8df92d0db354fbd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 13 Jan 2016 23:00:02 -0500 Subject: [PATCH] use a unique key to store per-thread request buffers --- libs/pbd/event_loop.cc | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/libs/pbd/event_loop.cc b/libs/pbd/event_loop.cc index 1117761003..09099f7eb5 100644 --- a/libs/pbd/event_loop.cc +++ b/libs/pbd/event_loop.cc @@ -17,6 +17,10 @@ */ +#include + +#include + #include "pbd/compose.h" #include "pbd/debug.h" #include "pbd/event_loop.h" @@ -171,24 +175,30 @@ EventLoop::pre_register (const string& emitting_thread_name, uint32_t num_reques AbstractUI constructor. Note that if */ - /* make a key composed of the emitter and receiver thread names */ + const string key = string_compose ("%1/%2", mapping.emitting_thread, mapping.target_thread_name); - string key = emitting_thread_name; - key += '/'; - key += mapping.target_thread_name; - - /* if the emitting thread was killed and recreated (with the - * same name), this will replace the entry in - * thread_buffer_requests. The old entry will be lazily deleted - * when the target thread finds the request buffer and realizes - * that it is dead. + /* note that there is no cleanup mechanism to remove + * dead/out-of-date entries from this map. * - * If the request buffer is replaced before the target thread - * ever finds the dead version, we will leak the old request - * buffer. + * the request buffers themselves will be cleaned up + * when the requesting thread exits (by the + * thread-local-storage (TLS) cleanup mechanism). + * + * but an entry will remain in the map. + * + * really need a way to register some end-of-thread callback + * that will remove the entry from the thread_buffer_requests + * container. but there is no such thing in the pthreads API + * + * the target thread only searches the map once, when the event + * loop object is constructed. if it finds invalid buffers + * it will (a) never get any requests for them anyway (b) will + * find them marked "dead" and delete them. */ thread_buffer_requests[key] = mapping; - DEBUG_TRACE (PBD::DEBUG::EventLoop, string_compose ("pre-registered request buffer for \"%1\" to send to \"%2\", buffer @ %3\n", emitting_thread_name, trs->name, mapping.request_buffer)); + DEBUG_TRACE (PBD::DEBUG::EventLoop, string_compose ("pre-registered request buffer for \"%1\" to send to \"%2\", buffer @ %3 (key was %4)\n", + emitting_thread_name, trs->name, mapping.request_buffer, key)); } } + -- 2.30.2