From 88a24ae8e53c00fd5adc47fa8dc0dabe9f784bbe Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 28 Sep 2024 00:14:45 +0200 Subject: [PATCH] Let PBD::Thread set thread-name --- libs/ardour/audioengine.cc | 6 ++---- libs/ardour/automation_watch.cc | 3 +-- libs/ardour/butler.cc | 3 +-- libs/ardour/midi_patch_manager.cc | 3 +-- libs/ardour/source_factory.cc | 4 +--- libs/ardour/triggerbox.cc | 5 +---- libs/ardour/worker.cc | 4 +--- libs/audiographer/audiographer/sndfile/tmp_file_rt.h | 1 - libs/pbd/base_ui.cc | 3 +-- libs/pbd/downloader.cc | 2 +- libs/pbd/inflater.cc | 2 +- libs/surfaces/cc121/cc121.cc | 2 -- libs/surfaces/contourdesign/contourdesign.cc | 2 -- libs/surfaces/faderport8/faderport8.cc | 2 -- .../generic_midi/generic_midi_control_protocol.cc | 2 -- libs/surfaces/launch_control_xl/launch_control_xl.cc | 2 -- libs/surfaces/mackie/mackie_control_protocol.cc | 2 -- libs/surfaces/maschine2/maschine2.cc | 9 +-------- libs/surfaces/osc/osc.cc | 2 -- libs/surfaces/us2400/us2400_control_protocol.cc | 2 -- libs/surfaces/websockets/ardour_websockets.cc | 1 - libs/surfaces/wiimote/wiimote.cc | 2 -- libs/waveview/wave_view_private.cc | 4 +--- 23 files changed, 13 insertions(+), 55 deletions(-) diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index dd8f4253d4..d46ea648eb 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -678,7 +678,6 @@ void AudioEngine::do_reset_backend() { SessionEvent::create_per_thread_pool (X_("Backend reset processing thread"), 1024); - pthread_set_name ("EngineWatchdog"); Glib::Threads::Mutex::Lock guard (_reset_request_lock); @@ -739,7 +738,6 @@ void AudioEngine::do_devicelist_update() { SessionEvent::create_per_thread_pool (X_("Device list update processing thread"), 512); - pthread_set_name ("DeviceList"); Glib::Threads::Mutex::Lock guard (_devicelist_update_lock); @@ -769,13 +767,13 @@ AudioEngine::start_hw_event_processing() if (_hw_reset_event_thread == 0) { _hw_reset_request_count.store (0); _stop_hw_reset_processing.store (0); - _hw_reset_event_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_reset_backend, this)); + _hw_reset_event_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_reset_backend, this), "EngineWatchdog"); } if (_hw_devicelist_update_thread == 0) { _hw_devicelist_update_count.store (0); _stop_hw_devicelist_processing.store (0); - _hw_devicelist_update_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_devicelist_update, this)); + _hw_devicelist_update_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_devicelist_update, this), "DeviceList"); } } diff --git a/libs/ardour/automation_watch.cc b/libs/ardour/automation_watch.cc index beea168108..3778367e9e 100644 --- a/libs/ardour/automation_watch.cc +++ b/libs/ardour/automation_watch.cc @@ -202,7 +202,6 @@ void AutomationWatch::thread () { pbd_set_thread_priority (pthread_self(), PBD_SCHED_FIFO, AudioEngine::instance()->client_real_time_priority() - 2); // XXX - pthread_set_name ("AutomationWatch"); while (_run_thread) { Glib::usleep ((gulong) floor (Config->get_automation_interval_msecs() * 1000)); // TODO use pthread_cond_timedwait on _run_thread timer (); @@ -224,7 +223,7 @@ AutomationWatch::set_session (Session* s) if (_session) { _run_thread = true; - _thread = PBD::Thread::create (boost::bind (&AutomationWatch::thread, this)); + _thread = PBD::Thread::create (boost::bind (&AutomationWatch::thread, this), "AutomationWatch"); _session->TransportStateChange.connect_same_thread (transport_connection, boost::bind (&AutomationWatch::transport_state_change, this)); } diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc index 2a31403a1f..274e2cf5ea 100644 --- a/libs/ardour/butler.cc +++ b/libs/ardour/butler.cc @@ -141,7 +141,7 @@ Butler::start_thread () should_run = false; - if (pthread_create_and_store ("disk butler", &thread, _thread_work, this)) { + if (pthread_create_and_store ("butler", &thread, _thread_work, this)) { error << _("Session: could not create butler thread") << endmsg; return -1; } @@ -171,7 +171,6 @@ void* Butler::_thread_work (void* arg) { SessionEvent::create_per_thread_pool ("butler events", 4096); - pthread_set_name (X_("butler")); /* get thread buffers for RegionFx */ ARDOUR::ProcessThread* pt = new ProcessThread (); pt->get_buffers (); diff --git a/libs/ardour/midi_patch_manager.cc b/libs/ardour/midi_patch_manager.cc index 40d6af221e..8933731fc6 100644 --- a/libs/ardour/midi_patch_manager.cc +++ b/libs/ardour/midi_patch_manager.cc @@ -275,7 +275,6 @@ MidiPatchManager::load_midnams () */ PBD::notify_event_loops_about_thread_creation (pthread_self(), "midi-patch-manager", 8); - pthread_set_name ("MIDNAMLoader"); { PBD::Unwinder npc (no_patch_changed_messages, true); @@ -291,7 +290,7 @@ MidiPatchManager::load_midnams () void MidiPatchManager::load_midnams_in_thread () { - _midnam_load_thread = PBD::Thread::create (boost::bind (&MidiPatchManager::load_midnams, this)); + _midnam_load_thread = PBD::Thread::create (boost::bind (&MidiPatchManager::load_midnams, this), "MIDNAMLoader"); } void diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc index 527a09e5b4..841b4cba14 100644 --- a/libs/ardour/source_factory.cc +++ b/libs/ardour/source_factory.cc @@ -65,8 +65,6 @@ static void peak_thread_work () { SessionEvent::create_per_thread_pool (X_("PeakFile Builder "), 64); - pthread_set_name ("PeakFileBuilder"); - while (true) { SourceFactory::peak_building_lock.lock (); @@ -119,7 +117,7 @@ SourceFactory::init () } peak_thread_run = true; for (int n = 0; n < 2; ++n) { - peak_thread_pool.push_back (PBD::Thread::create (&peak_thread_work)); + peak_thread_pool.push_back (PBD::Thread::create (&peak_thread_work, string_compose ("PeakFileBuilder-%1", n))); } } diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 870b15780c..7656be5a2f 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -4879,7 +4879,7 @@ TriggerBoxThread::TriggerBoxThread () : requests (1024) , _xthread (true) { - if (pthread_create_and_store ("triggerbox thread", &thread, _thread_work, this)) { + if (pthread_create_and_store ("TriggerBox Worker", &thread, _thread_work, this)) { error << _("Session: could not create triggerbox thread") << endmsg; throw failed_constructor (); } @@ -4897,15 +4897,12 @@ void * TriggerBoxThread::_thread_work (void* arg) { SessionEvent::create_per_thread_pool ("tbthread events", 4096); - pthread_set_name (X_("tbthread")); return ((TriggerBoxThread *) arg)->thread_work (); } void * TriggerBoxThread::thread_work () { - pthread_set_name (X_("Trigger Worker")); - while (true) { char msg; diff --git a/libs/ardour/worker.cc b/libs/ardour/worker.cc index 1fc385c958..e8fbe3abfd 100644 --- a/libs/ardour/worker.cc +++ b/libs/ardour/worker.cc @@ -41,7 +41,7 @@ Worker::Worker(Workee* workee, uint32_t ring_size, bool threaded) , _synchronous(!threaded) { if (threaded) { - _thread = PBD::Thread::create (boost::bind (&Worker::run, this)); + _thread = PBD::Thread::create (boost::bind (&Worker::run, this), "LV2Worker"); } } @@ -137,8 +137,6 @@ Worker::emit_responses() void Worker::run() { - pthread_set_name ("LV2Worker"); - void* buf = NULL; size_t buf_size = 0; while (true) { diff --git a/libs/audiographer/audiographer/sndfile/tmp_file_rt.h b/libs/audiographer/audiographer/sndfile/tmp_file_rt.h index c1c63b8322..4b9f321b4e 100644 --- a/libs/audiographer/audiographer/sndfile/tmp_file_rt.h +++ b/libs/audiographer/audiographer/sndfile/tmp_file_rt.h @@ -136,7 +136,6 @@ class TmpFileRt static void * _disk_thread (void *arg) { TmpFileRt *d = static_cast(arg); - pthread_set_name ("ExportDiskIO"); d->disk_thread (); return 0; } diff --git a/libs/pbd/base_ui.cc b/libs/pbd/base_ui.cc index 9c0a9a264d..d6b37f3657 100644 --- a/libs/pbd/base_ui.cc +++ b/libs/pbd/base_ui.cc @@ -94,7 +94,6 @@ BaseUI::set_thread_priority () const void BaseUI::main_thread () { - pthread_set_name (string_compose ("UI:%1", event_loop_name ()).c_str ()); DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: event loop running in thread %2\n", event_loop_name(), pthread_name())); set_event_loop_for_thread (this); thread_init (); @@ -122,7 +121,7 @@ BaseUI::run () attach_request_source (); Glib::Threads::Mutex::Lock lm (_run_lock); - _run_loop_thread = PBD::Thread::create (boost::bind (&BaseUI::main_thread, this)); + _run_loop_thread = PBD::Thread::create (boost::bind (&BaseUI::main_thread, this), string_compose ("UI:%1", event_loop_name ())); _running.wait (_run_lock); } diff --git a/libs/pbd/downloader.cc b/libs/pbd/downloader.cc index 57ff9e5ca7..9acf3ff360 100644 --- a/libs/pbd/downloader.cc +++ b/libs/pbd/downloader.cc @@ -98,7 +98,7 @@ Downloader::start () _cancel = false; _status = 0; /* unknown at this point */ - return 0 != (thread = PBD::Thread::create (boost::bind (&Downloader::download, this))); + return 0 != (thread = PBD::Thread::create (boost::bind (&Downloader::download, this), "Downloader")); } void diff --git a/libs/pbd/inflater.cc b/libs/pbd/inflater.cc index 35f9b2a1df..4a747f8ffe 100644 --- a/libs/pbd/inflater.cc +++ b/libs/pbd/inflater.cc @@ -45,7 +45,7 @@ Inflater::~Inflater () int Inflater::start () { - return 0 != (thread = PBD::Thread::create (boost::bind (&Inflater::threaded_inflate, this))); + return 0 != (thread = PBD::Thread::create (boost::bind (&Inflater::threaded_inflate, this), "Inflater")); } void diff --git a/libs/surfaces/cc121/cc121.cc b/libs/surfaces/cc121/cc121.cc index 1debf8e69c..f5360f5007 100644 --- a/libs/surfaces/cc121/cc121.cc +++ b/libs/surfaces/cc121/cc121.cc @@ -258,8 +258,6 @@ CC121::stop () void CC121::thread_init () { - pthread_set_name (event_loop_name().c_str()); - PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048); ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128); diff --git a/libs/surfaces/contourdesign/contourdesign.cc b/libs/surfaces/contourdesign/contourdesign.cc index a7fa14b4b4..21f13d856f 100644 --- a/libs/surfaces/contourdesign/contourdesign.cc +++ b/libs/surfaces/contourdesign/contourdesign.cc @@ -238,8 +238,6 @@ void ContourDesignControlProtocol::thread_init () { DEBUG_TRACE (DEBUG::ContourDesignControl, "thread_init()\n"); - - pthread_set_name (X_("contourdesign")); PBD::notify_event_loops_about_thread_creation (pthread_self (), X_("contourdesign"), 2048); ARDOUR::SessionEvent::create_per_thread_pool (X_("contourdesign"), 128); diff --git a/libs/surfaces/faderport8/faderport8.cc b/libs/surfaces/faderport8/faderport8.cc index bbf77723db..852697f311 100644 --- a/libs/surfaces/faderport8/faderport8.cc +++ b/libs/surfaces/faderport8/faderport8.cc @@ -283,8 +283,6 @@ FaderPort8::stop () void FaderPort8::thread_init () { - pthread_set_name (event_loop_name().c_str()); - PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048); ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128); diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc index 697f2c8c10..612502964d 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc @@ -308,8 +308,6 @@ GenericMidiControlProtocol::stop () void GenericMidiControlProtocol::thread_init () { - pthread_set_name (event_loop_name().c_str()); - PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048); ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128); diff --git a/libs/surfaces/launch_control_xl/launch_control_xl.cc b/libs/surfaces/launch_control_xl/launch_control_xl.cc index acf04b5717..9e15164820 100644 --- a/libs/surfaces/launch_control_xl/launch_control_xl.cc +++ b/libs/surfaces/launch_control_xl/launch_control_xl.cc @@ -665,8 +665,6 @@ void LaunchControlXL::handle_midi_note_off_message(MIDI::Parser & parser, MIDI:: void LaunchControlXL::thread_init () { - pthread_set_name (event_loop_name().c_str()); - PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048); ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128); diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc index 7e34712c1c..d372da6265 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.cc +++ b/libs/surfaces/mackie/mackie_control_protocol.cc @@ -194,8 +194,6 @@ MackieControlProtocol::~MackieControlProtocol() void MackieControlProtocol::thread_init () { - pthread_set_name (event_loop_name().c_str()); - PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048); ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128); diff --git a/libs/surfaces/maschine2/maschine2.cc b/libs/surfaces/maschine2/maschine2.cc index e2bc32fbbe..616f3eab2e 100644 --- a/libs/surfaces/maschine2/maschine2.cc +++ b/libs/surfaces/maschine2/maschine2.cc @@ -307,16 +307,9 @@ Maschine2::stop () void Maschine2::thread_init () { - pthread_set_name (event_loop_name().c_str()); ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 1024); PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 1024); - - struct sched_param rtparam; - memset (&rtparam, 0, sizeof (rtparam)); - rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */ - if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) { - // do we care? not particularly. - } + set_thread_priority (); } void diff --git a/libs/surfaces/osc/osc.cc b/libs/surfaces/osc/osc.cc index f1b6a8f9d6..6e30b6b139 100644 --- a/libs/surfaces/osc/osc.cc +++ b/libs/surfaces/osc/osc.cc @@ -284,8 +284,6 @@ OSC::start () void OSC::thread_init () { - pthread_set_name (event_loop_name().c_str()); - if (_osc_unix_server) { Glib::RefPtr src = IOSource::create (lo_server_get_socket_fd (_osc_unix_server), IO_IN|IO_HUP|IO_ERR); src->connect (sigc::bind (sigc::mem_fun (*this, &OSC::osc_input_handler), _osc_unix_server)); diff --git a/libs/surfaces/us2400/us2400_control_protocol.cc b/libs/surfaces/us2400/us2400_control_protocol.cc index 57f52a3cd5..101b41bd3d 100644 --- a/libs/surfaces/us2400/us2400_control_protocol.cc +++ b/libs/surfaces/us2400/us2400_control_protocol.cc @@ -174,8 +174,6 @@ US2400Protocol::~US2400Protocol() void US2400Protocol::thread_init () { - pthread_set_name (event_loop_name().c_str()); - PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048); ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128); diff --git a/libs/surfaces/websockets/ardour_websockets.cc b/libs/surfaces/websockets/ardour_websockets.cc index 9b8ec442ef..5fec5d5819 100644 --- a/libs/surfaces/websockets/ardour_websockets.cc +++ b/libs/surfaces/websockets/ardour_websockets.cc @@ -76,7 +76,6 @@ ArdourWebsockets::set_active (bool yn) void ArdourWebsockets::thread_init () { - pthread_set_name (event_loop_name ().c_str ()); PBD::notify_event_loops_about_thread_creation (pthread_self (), event_loop_name (), 2048); SessionEvent::create_per_thread_pool (event_loop_name (), 128); } diff --git a/libs/surfaces/wiimote/wiimote.cc b/libs/surfaces/wiimote/wiimote.cc index b92d0901fc..388161ad84 100644 --- a/libs/surfaces/wiimote/wiimote.cc +++ b/libs/surfaces/wiimote/wiimote.cc @@ -154,8 +154,6 @@ WiimoteControlProtocol::thread_init () { DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::thread_init init\n"); - pthread_set_name (X_("wiimote")); - // allow to make requests to the GUI and RT thread(s) PBD::notify_event_loops_about_thread_creation (pthread_self (), X_("wiimote"), 2048); BasicUI::register_thread ("wiimote"); diff --git a/libs/waveview/wave_view_private.cc b/libs/waveview/wave_view_private.cc index e1bcb2d783..eb68bfbfe5 100644 --- a/libs/waveview/wave_view_private.cc +++ b/libs/waveview/wave_view_private.cc @@ -405,7 +405,7 @@ WaveViewDrawingThread::start () { assert (!_thread); - _thread = PBD::Thread::create (&WaveViewThreads::thread_proc); + _thread = PBD::Thread::create (&WaveViewThreads::thread_proc, "WaveViewDrawing"); } void @@ -477,8 +477,6 @@ WaveViewThreads::thread_proc () void WaveViewThreads::_thread_proc () { - pthread_set_name ("WaveViewDrawing"); - while (true) { _queue_mutex.lock ();