Skip to main content
Version: Dev (main)

Cancellation

Functions Index​

static QarResultqar_cancel_token_cancel (QarCancelToken *token)

Signal cancellation on a token. More...

static QarResultqar_cancel_token_cancel_after (QarCancelToken *token, uint32_t timeout_ms)

Schedule cancellation after timeout_ms. More...

static QarResultqar_cancel_token_create (QarCancelToken **out_token)

Create a new cancellation token (non-signaled). More...

static QarResultqar_cancel_token_create_with_timeout (QarCancelToken **out_token, uint32_t timeout_ms)

Create a token that auto-cancels after timeout_ms. More...

static voidqar_cancel_token_handle_destroy (QarCancelToken *handle)

Destroy a token handle, cancelling what it owns. More...

static boolqar_cancel_token_is_cancelled (const QarCancelToken *token)

Check if token was canceled. More...

static boolqar_cancel_token_is_timeout (const QarCancelToken *token)

Check if token reached its timeout. More...

Description​

Ending a subscription. Every qar_*_subscribe_* function hands its subscription to the cancel token passed to it (where a NULL token is allowed, the subscription is the session's alone). These calls end it: qar_cancel_token_cancel() and qar_cancel_token_handle_destroy() on that token, qar_session_handle_destroy() on its session, qar_library_destroy(). When one of them returns:

  • a callback of the subscription that was running on another thread has returned: the call waited for it,
  • no callback of the subscription starts afterwards.

So user_state only has to stay valid until that call returns, and may be freed right after it.

From inside the subscription's own callback a call cannot wait for the callback it is made from. qar_cancel_token_cancel() and qar_cancel_token_handle_destroy() are allowed there: they return without waiting for that callback, which then finishes normally, and no further callback of the subscription starts. Keep user_state valid until that callback returns. Do not destroy the session or the library from a callback.

Waiting for a callback means: do not end a subscription while holding a lock its callback takes, and do not end subscription A from a callback of subscription B while a callback of B can be ending A.

A token's timeout (qar_cancel_token_create_with_timeout(), qar_cancel_token_cancel_after()) stops its subscriptions shortly after it expires but does not wait for a running callback. Cancel or destroy the token before freeing user_state.

Async calls. Every qar_*_async function that returns success fires its result callback exactly once, on a library thread:

  • with the outcome, success or error;
  • with QAR_STATUS_TIMEOUT when its cancel token is cancelled, times out or is destroyed before the call finished;
  • with QAR_STATUS_TIMEOUT when its owner goes away first: qar_session_handle_destroy() (calls on a session or a render sender), qar_render_stream_handle_destroy() (calls on that render sender), qar_runtime_handle_destroy() (onboard, rejoin) or qar_library_destroy(). That destroy call returns only after the callback has returned, unless it is made from that very callback (a render sender destroyed from its begin-frame callback).

When the call itself returns an error, the callback never fires. Keep user_state valid until the result callback has returned; no progress callback of the call fires after it. A cancel arriving just as the call finishes may still deliver the outcome instead of QAR_STATUS_TIMEOUT. Do not destroy the call's session, runtime or the library from its result callback.

Functions​

qar_cancel_token_cancel()​

QarResult qar_cancel_token_cancel (QarCancelToken * token)
inline static

Signal cancellation on a token.

Ends every subscription started with it: returns once no callback of those subscriptions is running on another thread, and none starts afterwards. Called from inside one of their callbacks it does not wait for that callback; see Ending a subscription.

Definition at line 3286 of file qar_streaming.h.

qar_cancel_token_cancel_after()​

QarResult qar_cancel_token_cancel_after (QarCancelToken * token, uint32_t timeout_ms)
inline static

Schedule cancellation after timeout_ms.

Definition at line 3289 of file qar_streaming.h.

qar_cancel_token_create()​

QarResult qar_cancel_token_create (QarCancelToken ** out_token)
inline static

Create a new cancellation token (non-signaled).

Definition at line 3266 of file qar_streaming.h.

qar_cancel_token_create_with_timeout()​

QarResult qar_cancel_token_create_with_timeout (QarCancelToken ** out_token, uint32_t timeout_ms)
inline static

Create a token that auto-cancels after timeout_ms.

Definition at line 3268 of file qar_streaming.h.

qar_cancel_token_handle_destroy()​

void qar_cancel_token_handle_destroy (QarCancelToken * handle)
inline static

Destroy a token handle, cancelling what it owns.

Ends every subscription started with it, waiting for a running callback; see Ending a subscription.

Definition at line 3277 of file qar_streaming.h.

qar_cancel_token_is_cancelled()​

bool qar_cancel_token_is_cancelled (const QarCancelToken * token)
inline static

Check if token was canceled.

Definition at line 3291 of file qar_streaming.h.

qar_cancel_token_is_timeout()​

bool qar_cancel_token_is_timeout (const QarCancelToken * token)
inline static

Check if token reached its timeout.

Definition at line 3293 of file qar_streaming.h.


Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.9.8.