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

@ -43,15 +43,18 @@ extern "C" {
#define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK)
#define SPA_RESULT_RETURN_ASYNC(seq) (SPA_ASYNC_BIT | SPA_RESULT_ASYNC_SEQ(seq))
typedef int (*spa_result_func_t) (void *data, int seq, int res, const void *result);
typedef int (*spa_result_func_t) (void *data, uint32_t count, const void *result);
struct spa_pending;
typedef int (*spa_pending_func_t) (struct spa_pending *pending, const void *result);
struct spa_pending {
struct spa_list link;
int seq;
int res;
spa_result_func_t func;
void *data;
void (*removed) (struct spa_pending *pending);
struct spa_list link; /**< link used internally */
int seq; /**< sequence number of pending result */
int res; /**< result code of operation */
spa_pending_func_t func; /**< callback function */
void *data; /**< extra user data */
};
#ifdef __cplusplus