13
0

Consolidate calls to `pthread_create' (2/2)

This commit is contained in:
Robin Gareus 2024-09-27 23:04:32 +02:00
parent 6a741689d1
commit 538a8cbccc
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
8 changed files with 22 additions and 29 deletions

View File

@ -30,6 +30,7 @@
#include <boost/operators.hpp>
#include "pbd/gstdio_compat.h"
#include "pbd/pthread_utils.h"
#include "ardour/export_pointers.h"
#include "ardour/session.h"
@ -149,7 +150,7 @@ class LIBARDOUR_API ExportHandler : public ExportElementFactory, public sigc::tr
void timespan_thread_wakeup ();
static void* _timespan_thread_run (void*);
pthread_t _timespan_thread;
PBD::Thread* _timespan_thread;
std::atomic<int> _timespan_thread_active;
pthread_mutex_t _timespan_mutex;
pthread_cond_t _timespan_cond;

View File

@ -185,7 +185,7 @@ ControlProtocolManager::set_session (Session* s)
usb_hotplug_cb, this,
&_hpcp)) {
_hotplug_thread_run = true;
if (pthread_create (&_hotplug_thread, NULL, usb_hotplug_thread, this)) {
if (pthread_create_and_store ("Ctrl USB Hotplug", &_hotplug_thread, usb_hotplug_thread, this, 0)) {
_hotplug_thread_run = false;
}
}

View File

@ -25,7 +25,6 @@
#include "pbd/gstdio_compat.h"
#include <glibmm.h>
#include <glibmm/convert.h>
#include <pthread.h>
#include "pbd/convert.h"
@ -125,7 +124,8 @@ ExportHandler::ExportHandler (Session & session)
pthread_mutex_init (&_timespan_mutex, 0);
pthread_cond_init (&_timespan_cond, 0);
_timespan_thread_active.store (1);
if (pthread_create (&_timespan_thread, NULL, _timespan_thread_run, this)) {
_timespan_thread = PBD::Thread::create (boost::bind (_timespan_thread_run, this), "ExportHandler");
if (!_timespan_thread) {
_timespan_thread_active.store (0);
fatal << "Cannot create export handler helper thread" << endmsg;
abort(); /* NOTREACHED*/
@ -145,8 +145,7 @@ ExportHandler::~ExportHandler ()
pthread_cond_signal (&_timespan_cond);
pthread_mutex_unlock (&_timespan_mutex);
void *status;
pthread_join (_timespan_thread, &status);
_timespan_thread->join ();
pthread_cond_destroy (&_timespan_cond);
pthread_mutex_destroy (&_timespan_mutex);
@ -155,13 +154,10 @@ ExportHandler::~ExportHandler ()
void*
ExportHandler::_timespan_thread_run (void* me)
{
char name[64];
snprintf (name, 64, "Export-TS-%p", (void*)DEBUG_THREAD_SELF);
pthread_set_name (name);
ExportHandler* self = static_cast<ExportHandler*> (me);
SessionEvent::create_per_thread_pool (name, 512);
PBD::notify_event_loops_about_thread_creation (pthread_self(), name, 512);
SessionEvent::create_per_thread_pool ("ExportHandler", 512);
PBD::notify_event_loops_about_thread_creation (pthread_self(), "ExportHandler", 512);
pthread_mutex_lock (&self->_timespan_mutex);
while (self->_timespan_thread_active.load ()) {
@ -178,7 +174,6 @@ ExportHandler::_timespan_thread_run (void* me)
}
}
pthread_mutex_unlock (&self->_timespan_mutex);
pthread_exit (0);
return 0;
}

View File

@ -7845,8 +7845,10 @@ Session::auto_connect_thread_start ()
lx.release ();
_ac_thread_active.store (1);
if (pthread_create (&_auto_connect_thread, NULL, auto_connect_thread, this)) {
if (pthread_create_and_store ("AutoConnect", &_auto_connect_thread, auto_connect_thread, this, 0)) {
_ac_thread_active.store (0);
fatal << "Cannot create 'session auto connect' thread" << endmsg;
abort(); /* NOTREACHED*/
}
}
@ -7881,9 +7883,7 @@ void *
Session::auto_connect_thread (void *arg)
{
Session *s = static_cast<Session *>(arg);
pthread_set_name (X_("autoconnect"));
s->auto_connect_thread_run ();
pthread_exit (0);
return 0;
}

View File

@ -1199,7 +1199,7 @@ Session::emit_thread_start ()
}
_rt_thread_active = true;
if (pthread_create (&_rt_emit_thread, NULL, emit_thread, this)) {
if (pthread_create_and_store ("SessionSignals", &_rt_emit_thread, emit_thread, this, 0)) {
_rt_thread_active = false;
}
}
@ -1225,9 +1225,7 @@ void *
Session::emit_thread (void *arg)
{
Session *s = static_cast<Session *>(arg);
pthread_set_name ("SessionSignals");
s->emit_thread_run ();
pthread_exit (0);
return 0;
}

View File

@ -138,7 +138,6 @@ class TmpFileRt
TmpFileRt *d = static_cast<TmpFileRt *>(arg);
pthread_set_name ("ExportDiskIO");
d->disk_thread ();
pthread_exit (0);
return 0;
}
@ -158,7 +157,7 @@ class TmpFileRt
pthread_mutex_init (&_disk_thread_lock, 0);
pthread_cond_init (&_data_ready, 0);
if (pthread_create (&_thread_id, NULL, _disk_thread, this)) {
if (pthread_create_and_store ("ExportDiskIO", &_thread_id, _disk_thread, this, 0)) {
_capture = false;
if (SndfileWriter<T>::throw_level (ThrowStrict)) {
throw Exception (*this, "Cannot create export disk writer");

View File

@ -59,7 +59,6 @@ write_callback (void* buffer, size_t size, size_t nmemb, void* d)
static void*
get_url (void* arg)
{
pthread_set_name ("FileArchiveURL");
FileArchive::Request* r = (FileArchive::Request*) arg;
CURL* curl;
@ -328,7 +327,10 @@ std::vector<std::string>
FileArchive::contents_url ()
{
_req.mp.reset ();
pthread_create (&_tid, NULL, get_url, (void*)&_req);
if (pthread_create_and_store ("FileArchiveHTTP", &_tid, get_url, (void*)&_req, 0)) {
return std::vector<std::string> ();
}
struct archive* a = setup_archive ();
archive_read_open (a, (void*)&_req.mp, NULL, ar_read, NULL);
@ -359,7 +361,9 @@ int
FileArchive::extract_url ()
{
_req.mp.reset ();
pthread_create (&_tid, NULL, get_url, (void*)&_req);
if (pthread_create_and_store ("FileArchiveHTTP", &_tid, get_url, (void*)&_req)) {
return -1;
}
struct archive* a = setup_archive ();
archive_read_open (a, (void*)&_req.mp, NULL, ar_read, NULL);
int rv = do_extract (a);

View File

@ -278,9 +278,7 @@ SystemExec::~SystemExec ()
static void*
interposer_thread (void *arg) {
SystemExec *sex = static_cast<SystemExec *>(arg);
pthread_set_name ("ExecStdOut");
sex->output_interposer();
pthread_exit(0);
return 0;
}
@ -522,7 +520,7 @@ SystemExec::start (StdErrMode stderr_mode, const char * /*vfork_exec_wrapper*/)
return -1;
}
int rv = pthread_create (&thread_id_tt, NULL, interposer_thread, this);
int rv = pthread_create_and_store ("ExecStdOut", &thread_id_tt, interposer_thread, this, 0);
thread_active=true;
if (rv) {
thread_active=false;
@ -560,7 +558,6 @@ SystemExec::output_interposer()
ReadStdout(rv, bytesRead); /* EMIT SIGNAL */
}
Terminated(); /* EMIT SIGNAL */
pthread_exit(0);
}
void
@ -808,7 +805,7 @@ SystemExec::start (StdErrMode stderr_mode, const char *vfork_exec_wrapper)
close_fd (pout[1]);
close_fd (pin[0]);
int rv = pthread_create (&thread_id_tt, NULL, interposer_thread, this);
int rv = pthread_create_and_store ("ExecStdOut", &thread_id_tt, interposer_thread, this, 0);
thread_active=true;
if (rv) {
@ -917,7 +914,6 @@ again:
ReadStdout (rv, r); /* EMIT SIGNAL */
}
Terminated (); /* EMIT SIGNAL */
pthread_exit (0);
}
void