Require thread name to be passed to PBD::Thread and store thread
This commit is contained in:
parent
88a24ae8e5
commit
e8445d13ec
@ -97,7 +97,7 @@ namespace PBD {
|
||||
|
||||
class LIBPBD_API Thread {
|
||||
public:
|
||||
static Thread* create (boost::function<void ()> const&, std::string const& name = "");
|
||||
static Thread* create (boost::function<void ()> const&, std::string const& name);
|
||||
static Thread* self ();
|
||||
void join ();
|
||||
bool caller_is_self () const;
|
||||
|
@ -486,6 +486,12 @@ PBD::Thread::Thread (boost::function<void ()> const& slot, std::string const& na
|
||||
if (pthread_create (&_t, &thread_attributes, _run, this)) {
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
if (_joinable) {
|
||||
pthread_mutex_lock (&thread_map_lock);
|
||||
all_threads[_t] = name;
|
||||
pthread_mutex_unlock (&thread_map_lock);
|
||||
}
|
||||
}
|
||||
|
||||
void*
|
||||
@ -494,8 +500,22 @@ PBD::Thread::_run (void* arg) {
|
||||
if (!self->_name.empty ()) {
|
||||
pthread_set_name (self->_name.c_str ());
|
||||
}
|
||||
|
||||
DEBUG_TRACE (PBD::DEBUG::Threads, string_compose ("Started: '%1'\n", self->_name));
|
||||
|
||||
self->_slot ();
|
||||
|
||||
/* cleanup */
|
||||
pthread_mutex_lock (&thread_map_lock);
|
||||
for (auto const& t : all_threads) {
|
||||
if (pthread_equal (t.first, pthread_self ())) {
|
||||
DEBUG_TRACE (PBD::DEBUG::Threads, string_compose ("Terminated: '%1'\n", t.second));
|
||||
all_threads.erase (t.first);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock (&thread_map_lock);
|
||||
|
||||
pthread_exit (0);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user