mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-08 13:30:08 -05:00
loop: remove the eventfd to stop the loop
We can just as well use _invoke to schedule a task in the context of the loop.
This commit is contained in:
parent
3256c6e5e7
commit
5ab031b472
3 changed files with 18 additions and 35 deletions
|
|
@ -90,11 +90,13 @@ static void *do_loop(void *user_data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void do_stop(void *data, uint64_t count)
|
||||
static int do_stop(struct spa_loop *loop, bool async, uint32_t seq,
|
||||
const void *data, size_t size, void *user_data)
|
||||
{
|
||||
struct pw_data_loop *this = data;
|
||||
struct pw_data_loop *this = user_data;
|
||||
pw_log_debug("%p: stopping", this);
|
||||
this->running = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct pw_data_loop *loop_new(struct pw_loop *loop, const struct spa_dict *props)
|
||||
|
|
@ -122,23 +124,14 @@ static struct pw_data_loop *loop_new(struct pw_loop *loop, const struct spa_dict
|
|||
}
|
||||
this->loop = loop;
|
||||
|
||||
if (props == NULL ||
|
||||
(str = spa_dict_lookup(props, "loop.cancel")) == NULL ||
|
||||
pw_properties_parse_bool(str) == false) {
|
||||
this->event = pw_loop_add_event(this->loop, do_stop, this);
|
||||
if (this->event == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("%p: can't add event: %m", this);
|
||||
goto error_loop_destroy;
|
||||
}
|
||||
}
|
||||
if (props != NULL &&
|
||||
(str = spa_dict_lookup(props, "loop.cancel")) != NULL)
|
||||
this->cancel = pw_properties_parse_bool(str);
|
||||
|
||||
spa_hook_list_init(&this->listener_list);
|
||||
|
||||
return this;
|
||||
|
||||
error_loop_destroy:
|
||||
if (this->created && this->loop)
|
||||
pw_loop_destroy(this->loop);
|
||||
error_free:
|
||||
free(this);
|
||||
error_cleanup:
|
||||
|
|
@ -169,8 +162,6 @@ void pw_data_loop_destroy(struct pw_data_loop *loop)
|
|||
|
||||
pw_data_loop_stop(loop);
|
||||
|
||||
if (loop->event)
|
||||
pw_loop_destroy_source(loop->loop, loop->event);
|
||||
if (loop->created)
|
||||
pw_loop_destroy(loop->loop);
|
||||
|
||||
|
|
@ -232,12 +223,12 @@ int pw_data_loop_stop(struct pw_data_loop *loop)
|
|||
{
|
||||
pw_log_debug("%p stopping", loop);
|
||||
if (loop->running) {
|
||||
if (loop->event) {
|
||||
pw_log_debug("%p signal", loop);
|
||||
pw_loop_signal_event(loop->loop, loop->event);
|
||||
} else {
|
||||
if (loop->cancel) {
|
||||
pw_log_debug("%p cancel", loop);
|
||||
pthread_cancel(loop->thread);
|
||||
} else {
|
||||
pw_log_debug("%p signal", loop);
|
||||
pw_loop_invoke(loop->loop, do_stop, 1, NULL, 0, false, loop);
|
||||
}
|
||||
pw_log_debug("%p join", loop);
|
||||
pw_thread_utils_join((struct spa_thread*)loop->thread, NULL);
|
||||
|
|
|
|||
|
|
@ -29,11 +29,13 @@
|
|||
PW_LOG_TOPIC_EXTERN(log_main_loop);
|
||||
#define PW_LOG_TOPIC_DEFAULT log_main_loop
|
||||
|
||||
static void do_stop(void *data, uint64_t count)
|
||||
static int do_stop(struct spa_loop *loop, bool async, uint32_t seq,
|
||||
const void *data, size_t size, void *user_data)
|
||||
{
|
||||
struct pw_main_loop *this = data;
|
||||
struct pw_main_loop *this = user_data;
|
||||
pw_log_debug("%p: do stop", this);
|
||||
this->running = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct pw_main_loop *loop_new(struct pw_loop *loop, const struct spa_dict *props)
|
||||
|
|
@ -59,19 +61,10 @@ static struct pw_main_loop *loop_new(struct pw_loop *loop, const struct spa_dict
|
|||
}
|
||||
this->loop = loop;
|
||||
|
||||
this->event = pw_loop_add_event(this->loop, do_stop, this);
|
||||
if (this->event == NULL) {
|
||||
res = -errno;
|
||||
goto error_free_loop;
|
||||
}
|
||||
|
||||
spa_hook_list_init(&this->listener_list);
|
||||
|
||||
return this;
|
||||
|
||||
error_free_loop:
|
||||
if (this->created && this->loop)
|
||||
pw_loop_destroy(this->loop);
|
||||
error_free:
|
||||
free(this);
|
||||
error_cleanup:
|
||||
|
|
@ -132,7 +125,7 @@ SPA_EXPORT
|
|||
int pw_main_loop_quit(struct pw_main_loop *loop)
|
||||
{
|
||||
pw_log_debug("%p: quit", loop);
|
||||
return pw_loop_signal_event(loop->loop, loop->event);
|
||||
return pw_loop_invoke(loop->loop, do_stop, 1, NULL, 0, false, loop);
|
||||
}
|
||||
|
||||
/** Start a main loop
|
||||
|
|
|
|||
|
|
@ -472,9 +472,9 @@ struct pw_data_loop {
|
|||
struct pw_loop *loop;
|
||||
|
||||
struct spa_hook_list listener_list;
|
||||
struct spa_source *event;
|
||||
|
||||
pthread_t thread;
|
||||
unsigned int cancel:1;
|
||||
unsigned int created:1;
|
||||
unsigned int running:1;
|
||||
};
|
||||
|
|
@ -486,7 +486,6 @@ struct pw_main_loop {
|
|||
struct pw_loop *loop;
|
||||
|
||||
struct spa_hook_list listener_list;
|
||||
struct spa_source *event;
|
||||
|
||||
unsigned int created:1;
|
||||
unsigned int running:1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue