node: improve pending results

Make a special function for pending results to make it clear that it
is different from normal results. Don't pass result code to result
function, it is not useful because since the callback is called, all
must be fine.

The spa_pending is removed from the list right before the callback
and can thus be freed in the callback. Pass the spa_pending in
the pending callback so that extra data can be added that way.

Reuse spa_pending objects in link and nodes instead of allocating. We
always only have one pending operation and we can cancel any pending
previous operation by removing the pending.
This commit is contained in:
Wim Taymans 2019-02-21 12:14:25 +01:00
parent a3ca2df0fe
commit 98463b689b
33 changed files with 126 additions and 156 deletions

View file

@ -212,15 +212,15 @@ struct spa_node {
* The hook is automatically removed after the hook is called.
*
* \param node a spa_node
* \param res an async return value to wait for
* \param seq an async return value to wait for
* \param pending a spa_pending structure
* \param func a result callback
* \param data data passed to \a func
* \return 0 on success
* -EINVAL when node is NULL
*/
int (*wait) (struct spa_node *node, int res, struct spa_pending *pending,
spa_result_func_t func, void *data);
int (*wait) (struct spa_node *node, int seq, struct spa_pending *pending,
spa_pending_func_t func, void *data);
/**
* Enumerate the parameters of a node.

View file

@ -37,20 +37,17 @@ struct spa_result_node_enum_params_data {
};
static inline int spa_result_func_node_enum_params(void *data,
int seq, int res, const void *result)
uint32_t count, const void *result)
{
struct spa_result_node_enum_params_data *d =
(struct spa_result_node_enum_params_data *)data;
const struct spa_result_node_enum_params *r =
(const struct spa_result_node_enum_params *)result;
if (res == 1) {
uint32_t offset = d->builder->state.offset;
spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param));
d->data.next = r->next;
d->data.param = SPA_MEMBER(d->builder->data, offset, struct spa_pod);
}
return res;
uint32_t offset = d->builder->state.offset;
spa_pod_builder_raw_padded(d->builder, r->param, SPA_POD_SIZE(r->param));
d->data.next = r->next;
d->data.param = SPA_MEMBER(d->builder->data, offset, struct spa_pod);
return 1;
}
static inline int spa_node_enum_params_sync(struct spa_node *node,