mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
data-loop: use pthread_cancel to stop thread
Use pthread_cancel to terminate the data threads. We need this for jack support but it's generally useful for a data thread.
This commit is contained in:
parent
bac6bf090c
commit
940aba8623
2 changed files with 17 additions and 26 deletions
|
|
@ -55,6 +55,14 @@ void pw_data_loop_exit(struct pw_data_loop *this)
|
||||||
this->running = false;
|
this->running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void thread_cleanup(void *arg)
|
||||||
|
{
|
||||||
|
struct pw_data_loop *this = arg;
|
||||||
|
pw_log_debug(NAME" %p: leave thread", this);
|
||||||
|
this->running = false;
|
||||||
|
pw_loop_enter(this->loop);
|
||||||
|
}
|
||||||
|
|
||||||
static void *do_loop(void *user_data)
|
static void *do_loop(void *user_data)
|
||||||
{
|
{
|
||||||
struct pw_data_loop *this = user_data;
|
struct pw_data_loop *this = user_data;
|
||||||
|
|
@ -63,6 +71,8 @@ static void *do_loop(void *user_data)
|
||||||
pw_log_debug(NAME" %p: enter thread", this);
|
pw_log_debug(NAME" %p: enter thread", this);
|
||||||
pw_loop_enter(this->loop);
|
pw_loop_enter(this->loop);
|
||||||
|
|
||||||
|
pthread_cleanup_push(thread_cleanup, this);
|
||||||
|
|
||||||
while (this->running) {
|
while (this->running) {
|
||||||
if ((res = pw_loop_iterate(this->loop, -1)) < 0) {
|
if ((res = pw_loop_iterate(this->loop, -1)) < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
|
|
@ -71,21 +81,11 @@ static void *do_loop(void *user_data)
|
||||||
this, res, spa_strerror(res));
|
this, res, spa_strerror(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pthread_cleanup_pop(1);
|
||||||
pw_log_debug(NAME" %p: leave thread", this);
|
|
||||||
pw_loop_leave(this->loop);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void do_stop(void *data, uint64_t count)
|
|
||||||
{
|
|
||||||
struct pw_data_loop *this = data;
|
|
||||||
pw_log_debug(NAME" %p: stopping", this);
|
|
||||||
this->running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct pw_data_loop *loop_new(struct pw_loop *loop, const struct spa_dict *props)
|
static struct pw_data_loop *loop_new(struct pw_loop *loop, const struct spa_dict *props)
|
||||||
{
|
{
|
||||||
struct pw_data_loop *this;
|
struct pw_data_loop *this;
|
||||||
|
|
@ -110,20 +110,10 @@ static struct pw_data_loop *loop_new(struct pw_loop *loop, const struct spa_dict
|
||||||
}
|
}
|
||||||
this->loop = loop;
|
this->loop = loop;
|
||||||
|
|
||||||
this->event = pw_loop_add_event(this->loop, do_stop, this);
|
|
||||||
if (this->event == NULL) {
|
|
||||||
res = -errno;
|
|
||||||
pw_log_error(NAME" %p: can't add event: %m", this);
|
|
||||||
goto error_loop_destroy;
|
|
||||||
}
|
|
||||||
|
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
error_loop_destroy:
|
|
||||||
if (this->created && this->loop)
|
|
||||||
pw_loop_destroy(this->loop);
|
|
||||||
error_free:
|
error_free:
|
||||||
free(this);
|
free(this);
|
||||||
error_cleanup:
|
error_cleanup:
|
||||||
|
|
@ -156,7 +146,6 @@ void pw_data_loop_destroy(struct pw_data_loop *loop)
|
||||||
|
|
||||||
pw_data_loop_stop(loop);
|
pw_data_loop_stop(loop);
|
||||||
|
|
||||||
pw_loop_destroy_source(loop->loop, loop->event);
|
|
||||||
if (loop->created)
|
if (loop->created)
|
||||||
pw_loop_destroy(loop->loop);
|
pw_loop_destroy(loop->loop);
|
||||||
free(loop);
|
free(loop);
|
||||||
|
|
@ -212,11 +201,15 @@ int pw_data_loop_start(struct pw_data_loop *loop)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int pw_data_loop_stop(struct pw_data_loop *loop)
|
int pw_data_loop_stop(struct pw_data_loop *loop)
|
||||||
{
|
{
|
||||||
|
pw_log_debug(NAME": %p stopping", loop);
|
||||||
if (loop->running) {
|
if (loop->running) {
|
||||||
pw_loop_signal_event(loop->loop, loop->event);
|
pw_log_debug(NAME": %p cancel", loop);
|
||||||
|
pthread_cancel(loop->thread);
|
||||||
|
pw_log_debug(NAME": %p join", loop);
|
||||||
pthread_join(loop->thread, NULL);
|
pthread_join(loop->thread, NULL);
|
||||||
|
pw_log_debug(NAME": %p joined", loop);
|
||||||
}
|
}
|
||||||
|
pw_log_debug(NAME": %p stopped", loop);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -282,8 +282,6 @@ struct pw_data_loop {
|
||||||
|
|
||||||
struct spa_hook_list listener_list;
|
struct spa_hook_list listener_list;
|
||||||
|
|
||||||
struct spa_source *event;
|
|
||||||
|
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
unsigned int created:1;
|
unsigned int created:1;
|
||||||
unsigned int running:1;
|
unsigned int running:1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue