hooks: add and use _fast callback function

Add a _fast callback function that skips the version and method check.
We can use this in places where performance is critical when we do the
check out of the critical loops.

Make all system methods _fast calls. We expect them to exist and have
the right version. If we add new versions we can make them slow.
This commit is contained in:
Wim Taymans 2023-05-06 00:24:05 +02:00
parent 9967c35bbe
commit efea7ad060
12 changed files with 76 additions and 29 deletions

View file

@ -1191,7 +1191,7 @@ static int node_ready(void *d, int status)
if (status & SPA_STATUS_HAVE_DATA) {
spa_list_for_each(p, &node->rt.output_mix, rt.node_link)
spa_node_process(p->mix);
spa_node_process_fast(p->mix);
}
a->state[0].status = status;

View file

@ -51,18 +51,10 @@ static void *do_loop(void *user_data)
{
struct pw_data_loop *this = user_data;
int res;
int (*iterate) (void *object, int timeout);
struct spa_interface *iface = &this->loop->control->iface;
struct spa_callbacks *cb = &iface->cb;
const struct spa_loop_control_methods *m =
(const struct spa_loop_control_methods *)cb->funcs;
struct spa_callbacks *cb = &this->loop->control->iface.cb;
const struct spa_loop_control_methods *m = cb->funcs;
void *data = cb->data;
if (!SPA_CALLBACK_CHECK(m, iterate, 0)) {
pw_log_error("loop is missing iterate method");
return NULL;
}
iterate = m->iterate;
int (*iterate) (void *object, int timeout) = m->iterate;
pw_log_debug("%p: enter thread", this);
pw_loop_enter(this->loop);

View file

@ -1166,13 +1166,13 @@ static inline int process_node(void *data)
if (SPA_LIKELY(this->added)) {
spa_list_for_each(p, &this->rt.input_mix, rt.node_link)
spa_node_process(p->mix);
spa_node_process_fast(p->mix);
status = spa_node_process(this->node);
status = spa_node_process_fast(this->node);
if (status & SPA_STATUS_HAVE_DATA) {
spa_list_for_each(p, &this->rt.output_mix, rt.node_link)
spa_node_process(p->mix);
spa_node_process_fast(p->mix);
}
} else {
/* This can happen when we deactivated the node but some links are
@ -1822,7 +1822,7 @@ again:
/* remote nodes have done the output mix already before
* they triggered the ready event */
spa_list_for_each(p, &node->rt.output_mix, rt.node_link)
spa_node_process(p->mix);
spa_node_process_fast(p->mix);
}
return resume_node(node, status, nsec);
}

View file

@ -109,6 +109,12 @@ struct pw_loop *pw_loop_new(const struct spa_dict *props)
goto error_unload_loop;
}
this->control = iface;
if (!spa_interface_callback_check(&this->control->iface,
struct spa_loop_control_methods, iterate, 0)) {
res = -EINVAL;
pw_log_error("%p: loop does not support iterate", this);
goto error_unload_loop;
}
if ((res = spa_handle_get_interface(impl->loop_handle,
SPA_TYPE_INTERFACE_LoopUtils,

View file

@ -45,8 +45,8 @@ pw_loop_destroy(struct pw_loop *loop);
#define pw_loop_get_fd(l) spa_loop_control_get_fd((l)->control)
#define pw_loop_add_hook(l,...) spa_loop_control_add_hook((l)->control,__VA_ARGS__)
#define pw_loop_enter(l) spa_loop_control_enter((l)->control)
#define pw_loop_iterate(l,...) spa_loop_control_iterate((l)->control,__VA_ARGS__)
#define pw_loop_leave(l) spa_loop_control_leave((l)->control)
#define pw_loop_iterate(l,...) spa_loop_control_iterate_fast((l)->control,__VA_ARGS__)
#define pw_loop_add_io(l,...) spa_loop_utils_add_io((l)->utils,__VA_ARGS__)
#define pw_loop_update_io(l,...) spa_loop_utils_update_io((l)->utils,__VA_ARGS__)