change the way thread name is managed and accessed; store thread name for JACK thread(s); remove bits of debugging output

git-svn-id: svn://localhost/ardour2/branches/3.0@6399 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2009-12-26 16:15:11 +00:00
parent b6f4cdaea2
commit 35c72a53b4
6 changed files with 118 additions and 48 deletions

View file

@ -134,6 +134,10 @@ _thread_init_callback (void * /*arg*/)
knows about it. knows about it.
*/ */
char* c = new char[12];
strcpy (c, X_("audioengine"));
pthread_set_name (c);
PBD::notify_gui_about_thread_creation ("gui", pthread_self(), X_("Audioengine"), 4096); PBD::notify_gui_about_thread_creation ("gui", pthread_self(), X_("Audioengine"), 4096);
PBD::notify_gui_about_thread_creation ("midiui", pthread_self(), X_("Audioengine"), 128); PBD::notify_gui_about_thread_creation ("midiui", pthread_self(), X_("Audioengine"), 128);

View file

@ -425,7 +425,6 @@ Session::destroy ()
routes.flush (); routes.flush ();
boost::shared_ptr<RouteList> r = routes.reader (); boost::shared_ptr<RouteList> r = routes.reader ();
cerr << "\n\n\n AFTER ROUTE CLEARING, there are " << r->size() << " routes in RCU\n";
DEBUG_TRACE (DEBUG::Destruction, "delete diskstreams\n"); DEBUG_TRACE (DEBUG::Destruction, "delete diskstreams\n");
{ {
@ -2129,20 +2128,21 @@ Session::add_routes (RouteList& new_routes, bool save)
for (RouteList::iterator x = new_routes.begin(); x != new_routes.end(); ++x) { for (RouteList::iterator x = new_routes.begin(); x != new_routes.end(); ++x) {
boost::weak_ptr<Route> wpr (*x); boost::weak_ptr<Route> wpr (*x);
boost::shared_ptr<Route> r (*x);
(*x)->listen_changed.connect_same_thread (*this, boost::bind (&Session::route_listen_changed, this, _1, wpr)); r->listen_changed.connect_same_thread (*this, boost::bind (&Session::route_listen_changed, this, _1, wpr));
(*x)->solo_changed.connect_same_thread (*this, boost::bind (&Session::route_solo_changed, this, _1, wpr)); r->solo_changed.connect_same_thread (*this, boost::bind (&Session::route_solo_changed, this, _1, wpr));
(*x)->mute_changed.connect_same_thread (*this, boost::bind (&Session::route_mute_changed, this, _1)); r->mute_changed.connect_same_thread (*this, boost::bind (&Session::route_mute_changed, this, _1));
(*x)->output()->changed.connect_same_thread (*this, boost::bind (&Session::set_worst_io_latencies_x, this, _1, _2)); r->output()->changed.connect_same_thread (*this, boost::bind (&Session::set_worst_io_latencies_x, this, _1, _2));
(*x)->processors_changed.connect_same_thread (*this, boost::bind (&Session::route_processors_changed, this, _1)); r->processors_changed.connect_same_thread (*this, boost::bind (&Session::route_processors_changed, this, _1));
(*x)->route_group_changed.connect_same_thread (*this, boost::bind (&Session::route_group_changed, this)); r->route_group_changed.connect_same_thread (*this, boost::bind (&Session::route_group_changed, this));
if ((*x)->is_master()) { if (r->is_master()) {
_master_out = (*x); _master_out = r;
} }
if ((*x)->is_control()) { if (r->is_control()) {
_control_out = (*x); _control_out = r;
} }
} }

View file

@ -1104,7 +1104,6 @@ Session::set_state (const XMLNode& node, int version)
XMLNode* child; XMLNode* child;
const XMLProperty* prop; const XMLProperty* prop;
int ret = -1; int ret = -1;
extern void boost_debug_shared_ptr_show_live_debugging (bool);
_state_of_the_state = StateOfTheState (_state_of_the_state|CannotSave); _state_of_the_state = StateOfTheState (_state_of_the_state|CannotSave);
@ -1379,6 +1378,7 @@ Session::XMLRouteFactory (const XMLNode& node, int version)
DataType type = DataType::AUDIO; DataType type = DataType::AUDIO;
const XMLProperty* prop = node.property("default-type"); const XMLProperty* prop = node.property("default-type");
boost::shared_ptr<Route> ret;
if (prop) { if (prop) {
type = DataType(prop->value()); type = DataType(prop->value());
@ -1390,17 +1390,18 @@ Session::XMLRouteFactory (const XMLNode& node, int version)
if (type == DataType::AUDIO) { if (type == DataType::AUDIO) {
AudioTrack* at = new AudioTrack (*this, node, version); AudioTrack* at = new AudioTrack (*this, node, version);
boost_debug_shared_ptr_mark_interesting (at, "Track"); boost_debug_shared_ptr_mark_interesting (at, "Track");
return boost::shared_ptr<Route> (at); ret.reset (at);
} else { } else {
boost::shared_ptr<Route> ret (new MidiTrack (*this, node, version)); ret.reset (new MidiTrack (*this, node, version));
return ret;
} }
} else { } else {
Route* rt = new Route (*this, node); Route* rt = new Route (*this, node);
boost_debug_shared_ptr_mark_interesting (rt, "Route"); boost_debug_shared_ptr_mark_interesting (rt, "Route");
return boost::shared_ptr<Route> (rt); ret.reset (rt);
} }
return ret;
} }
int int

View file

@ -65,7 +65,7 @@ Backtrace::print (std::ostream& str) const
strings = ::backtrace_symbols (trace, size); strings = ::backtrace_symbols (trace, size);
#endif #endif
if (strings) { if (strings) {
for (i = 5; i < 5+18 && i < size; i++) { for (i = 3; i < 5+18 && i < size; i++) {
str << strings[i] << std::endl; str << strings[i] << std::endl;
} }
free (strings); free (strings);
@ -204,11 +204,49 @@ boost_debug_shared_ptr_operator_equals (void const *sp, void const *old_obj, int
} }
void void
boost_debug_shared_ptr_reset (void const *sp, void const *obj, int use_count) boost_debug_shared_ptr_reset (void const *sp, void const *old_obj, int old_use_count, void const *obj, int new_use_count)
{ {
if (is_interesting_object (obj)) { if (old_obj == 0 && obj == 0) {
return;
}
Glib::Mutex::Lock guard (the_lock);
if (is_interesting_object (old_obj) || is_interesting_object (obj)) {
if (debug_out) { if (debug_out) {
cerr << "reset sp to object @ " << obj << " @ " << sp << " UC was " << use_count << " (total sp's = " << sptrs.size() << ')' << endl; cerr << "RESET SWAPS " << old_obj << " & " << obj << endl;
}
}
if (is_interesting_object (old_obj)) {
if (debug_out) {
cerr << "\tlost old sp @ " << sp << " for " << old_obj << " UC = " << old_use_count << " now for " << obj << " UC = " << new_use_count
<< " (total sp's = " << sptrs.size() << ')' << endl;
}
PointerMap::iterator x = sptrs.find (sp);
if (x != sptrs.end()) {
sptrs.erase (x);
if (debug_out) {
cerr << "\tRemoved (by reset) sp for " << old_obj << " @ " << sp << " UC = " << old_use_count << " (total sp's = " << sptrs.size() << ')' << endl;
}
}
}
if (is_interesting_object (obj)) {
pair<void const*, SPDebug*> newpair;
newpair.first = sp;
newpair.second = new SPDebug (new Backtrace());
sptrs.insert (newpair);
if (debug_out) {
cerr << "reset created sp for " << obj << " @ " << sp << " used to point to " << old_obj << " UC = " << old_use_count
<< " UC = " << new_use_count
<< " (total sp's = " << sptrs.size() << ')' << endl;
cerr << *newpair.second << endl;
} }
} }
} }

View file

@ -32,7 +32,8 @@ void pthread_cancel_one (pthread_t thread);
void pthread_cancel_all (); void pthread_cancel_all ();
void pthread_kill_all (int signum); void pthread_kill_all (int signum);
void pthread_exit_pbd (void* status); void pthread_exit_pbd (void* status);
std::string pthread_name (); const char* pthread_name ();
void pthread_set_name (const char* name);
namespace PBD { namespace PBD {
extern void notify_gui_about_thread_creation (std::string, pthread_t, std::string, int requests = 256); extern void notify_gui_about_thread_creation (std::string, pthread_t, std::string, int requests = 256);

View file

@ -18,7 +18,7 @@
$Id$ $Id$
*/ */
#include <map> #include <set>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
@ -30,9 +30,10 @@
using namespace std; using namespace std;
typedef std::map<string,pthread_t> ThreadMap; typedef std::set<pthread_t> ThreadMap;
static ThreadMap all_threads; static ThreadMap all_threads;
static pthread_mutex_t thread_map_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t thread_map_lock = PTHREAD_MUTEX_INITIALIZER;
static Glib::StaticPrivate<char> thread_name;
namespace PBD { namespace PBD {
PBD::Signal4<void,std::string, pthread_t,std::string,uint32_t> ThreadCreatedWithRequestSize; PBD::Signal4<void,std::string, pthread_t,std::string,uint32_t> ThreadCreatedWithRequestSize;
@ -55,6 +56,30 @@ PBD::notify_gui_about_thread_creation (std::string target_gui, pthread_t thread,
ThreadCreatedWithRequestSize (target_gui, thread, str, request_count); ThreadCreatedWithRequestSize (target_gui, thread, str, request_count);
} }
struct ThreadStartWithName {
void* (*thread_work)(void*);
void* arg;
const char* name;
ThreadStartWithName (void* (*f)(void*), void* a, const char* s)
: thread_work (f), arg (a), name (s) {}
};
static void*
fake_thread_start (void* arg)
{
ThreadStartWithName* ts = (ThreadStartWithName*) arg;
void* (*thread_work)(void*) = ts->thread_work;
void* thread_arg = ts->arg;
pthread_set_name (ts->name);
delete ts;
/* name will be deleted by the default handler for GStaticPrivate, when the thread exits */
return thread_work (thread_arg);
}
int int
pthread_create_and_store (string name, pthread_t *thread, void * (*start_routine)(void *), void * arg) pthread_create_and_store (string name, pthread_t *thread, void * (*start_routine)(void *), void * arg)
{ {
@ -65,13 +90,14 @@ pthread_create_and_store (string name, pthread_t *thread, void * (*start_routin
pthread_attr_init(&default_attr); pthread_attr_init(&default_attr);
pthread_attr_setstacksize(&default_attr, 500000); pthread_attr_setstacksize(&default_attr, 500000);
if ((ret = thread_creator (thread, &default_attr, start_routine, arg)) == 0) { char* cname = new char[name.length() + 1];
std::pair<string,pthread_t> newpair; strcpy (cname, name.c_str());
newpair.first = name;
newpair.second = *thread;
ThreadStartWithName* ts = new ThreadStartWithName (start_routine, arg, cname);
if ((ret = thread_creator (thread, &default_attr, fake_thread_start, ts)) == 0) {
pthread_mutex_lock (&thread_map_lock); pthread_mutex_lock (&thread_map_lock);
all_threads.insert (newpair); all_threads.insert (*thread);
pthread_mutex_unlock (&thread_map_lock); pthread_mutex_unlock (&thread_map_lock);
} }
@ -80,21 +106,21 @@ pthread_create_and_store (string name, pthread_t *thread, void * (*start_routin
return ret; return ret;
} }
string void
pthread_set_name (const char *str)
{
/* str will be deleted when this thread exits */
thread_name.set (const_cast<char*>(str));
}
const char *
pthread_name () pthread_name ()
{ {
pthread_t self = pthread_self(); const char* str = thread_name.get ();
string str;
pthread_mutex_lock (&thread_map_lock); if (str) {
for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) {
if (i->second == self) {
str = i->first;
pthread_mutex_unlock (&thread_map_lock);
return str; return str;
} }
}
pthread_mutex_unlock (&thread_map_lock);
return "unknown"; return "unknown";
} }
@ -103,8 +129,8 @@ pthread_kill_all (int signum)
{ {
pthread_mutex_lock (&thread_map_lock); pthread_mutex_lock (&thread_map_lock);
for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) { for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) {
if (i->second != pthread_self()) { if ((*i) != pthread_self()) {
pthread_kill (i->second, signum); pthread_kill ((*i), signum);
} }
} }
all_threads.clear(); all_threads.clear();
@ -116,8 +142,8 @@ pthread_cancel_all ()
{ {
pthread_mutex_lock (&thread_map_lock); pthread_mutex_lock (&thread_map_lock);
for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) { for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) {
if (i->second != pthread_self()) { if ((*i) != pthread_self()) {
pthread_cancel (i->second); pthread_cancel ((*i));
} }
} }
all_threads.clear(); all_threads.clear();
@ -129,7 +155,7 @@ pthread_cancel_one (pthread_t thread)
{ {
pthread_mutex_lock (&thread_map_lock); pthread_mutex_lock (&thread_map_lock);
for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) { for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) {
if (i->second == thread) { if ((*i) == thread) {
all_threads.erase (i); all_threads.erase (i);
break; break;
} }
@ -146,7 +172,7 @@ pthread_exit_pbd (void* status)
pthread_mutex_lock (&thread_map_lock); pthread_mutex_lock (&thread_map_lock);
for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) { for (ThreadMap::iterator i = all_threads.begin(); i != all_threads.end(); ++i) {
if (i->second == thread) { if ((*i) == thread) {
all_threads.erase (i); all_threads.erase (i);
break; break;
} }