xrt: Refactor reference functions to be clearer

This commit is contained in:
Jakob Bornecrantz 2023-11-17 16:23:31 +00:00
parent 11ae300946
commit fffdfa1c4b
10 changed files with 49 additions and 12 deletions

View file

@ -307,7 +307,7 @@ t_stereo_camera_calibration_reference(struct t_stereo_camera_calibration **dst,
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
t_stereo_camera_calibration_destroy(old_dst);
}
}

View file

@ -125,7 +125,7 @@ u_space_reference(struct u_space **dst, struct u_space *src)
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->base.reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->base.reference)) {
old_dst->base.destroy(&old_dst->base);
}
}

View file

@ -79,7 +79,7 @@ u_worker_thread_pool_reference(struct u_worker_thread_pool **dst, struct u_worke
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
u_worker_thread_pool_destroy(old_dst);
}
}
@ -164,7 +164,7 @@ u_worker_group_reference(struct u_worker_group **dst, struct u_worker_group *src
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
u_worker_group_destroy(old_dst);
}
}

View file

@ -304,7 +304,7 @@ rift_s_system_reference(struct rift_s_system **dst, struct rift_s_system *src)
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->ref)) {
if (xrt_reference_dec_and_is_zero(&old_dst->ref)) {
rift_s_system_free(old_dst);
}
}

View file

@ -113,7 +113,7 @@ wmr_hmd_controller_connection_disconnect(struct wmr_controller_connection *base)
{
struct wmr_hmd_controller_connection *conn = (struct wmr_hmd_controller_connection *)(base);
if (xrt_reference_dec(&conn->ref)) {
if (xrt_reference_dec_and_is_zero(&conn->ref)) {
wmr_hmd_controller_connection_destroy(conn);
} else {
os_mutex_lock(&conn->lock);

View file

@ -498,7 +498,7 @@ xrt_swapchain_reference(struct xrt_swapchain **dst, struct xrt_swapchain *src)
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
old_dst->destroy(old_dst);
}
}
@ -694,7 +694,7 @@ xrt_compositor_semaphore_reference(struct xrt_compositor_semaphore **dst, struct
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
old_dst->destroy(old_dst);
}
}

View file

@ -1304,14 +1304,51 @@ enum xrt_visibility_mask_type
*
*/
/*!
* Increment the reference, probably want @ref xrt_reference_inc_and_was_zero.
*
* @memberof xrt_reference
* @ingroup xrt_iface
*/
static inline void
xrt_reference_inc(struct xrt_reference *xref)
{
xrt_atomic_s32_inc_return(&xref->count);
}
static inline bool
/*!
* Decrement the reference, probably want @ref xrt_reference_dec_and_is_zero.
*
* @memberof xrt_reference
* @ingroup xrt_iface
*/
static inline void
xrt_reference_dec(struct xrt_reference *xref)
{
xrt_atomic_s32_dec_return(&xref->count);
}
/*!
* Increment the reference and return true if the value @p was zero.
*
* @memberof xrt_reference
* @ingroup xrt_iface
*/
XRT_CHECK_RESULT static inline bool
xrt_reference_inc_and_was_zero(struct xrt_reference *xref)
{
int32_t count = xrt_atomic_s32_inc_return(&xref->count);
return count == 1;
}
/*!
* Decrement the reference and return true if the value is now zero.
*
* @memberof xrt_reference
* @ingroup xrt_iface
*/
XRT_CHECK_RESULT static inline bool
xrt_reference_dec_and_is_zero(struct xrt_reference *xref)
{
int32_t count = xrt_atomic_s32_dec_return(&xref->count);
return count == 0;

View file

@ -143,7 +143,7 @@ xrt_frame_reference(struct xrt_frame **dst, struct xrt_frame *src)
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
old_dst->destroy(old_dst);
}
}

View file

@ -66,7 +66,7 @@ xrt_space_reference(struct xrt_space **dst, struct xrt_space *src)
*dst = src;
if (old_dst) {
if (xrt_reference_dec(&old_dst->reference)) {
if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
old_dst->destroy(old_dst);
}
}

View file

@ -2152,7 +2152,7 @@ oxr_refcounted_ref(struct oxr_refcounted *orc)
static inline void
oxr_refcounted_unref(struct oxr_refcounted *orc)
{
if (xrt_reference_dec(&orc->base)) {
if (xrt_reference_dec_and_is_zero(&orc->base)) {
orc->destroy(orc);
}
}