The open source OpenXR runtime

xrt: Refactor reference functions to be clearer

+49 -12
+1 -1
src/xrt/auxiliary/tracking/t_tracking.h
··· 307 307 *dst = src; 308 308 309 309 if (old_dst) { 310 - if (xrt_reference_dec(&old_dst->reference)) { 310 + if (xrt_reference_dec_and_is_zero(&old_dst->reference)) { 311 311 t_stereo_camera_calibration_destroy(old_dst); 312 312 } 313 313 }
+1 -1
src/xrt/auxiliary/util/u_space_overseer.c
··· 125 125 *dst = src; 126 126 127 127 if (old_dst) { 128 - if (xrt_reference_dec(&old_dst->base.reference)) { 128 + if (xrt_reference_dec_and_is_zero(&old_dst->base.reference)) { 129 129 old_dst->base.destroy(&old_dst->base); 130 130 } 131 131 }
+2 -2
src/xrt/auxiliary/util/u_worker.h
··· 79 79 *dst = src; 80 80 81 81 if (old_dst) { 82 - if (xrt_reference_dec(&old_dst->reference)) { 82 + if (xrt_reference_dec_and_is_zero(&old_dst->reference)) { 83 83 u_worker_thread_pool_destroy(old_dst); 84 84 } 85 85 } ··· 164 164 *dst = src; 165 165 166 166 if (old_dst) { 167 - if (xrt_reference_dec(&old_dst->reference)) { 167 + if (xrt_reference_dec_and_is_zero(&old_dst->reference)) { 168 168 u_worker_group_destroy(old_dst); 169 169 } 170 170 }
+1 -1
src/xrt/drivers/rift_s/rift_s.c
··· 304 304 *dst = src; 305 305 306 306 if (old_dst) { 307 - if (xrt_reference_dec(&old_dst->ref)) { 307 + if (xrt_reference_dec_and_is_zero(&old_dst->ref)) { 308 308 rift_s_system_free(old_dst); 309 309 } 310 310 }
+1 -1
src/xrt/drivers/wmr/wmr_hmd_controller.c
··· 113 113 { 114 114 struct wmr_hmd_controller_connection *conn = (struct wmr_hmd_controller_connection *)(base); 115 115 116 - if (xrt_reference_dec(&conn->ref)) { 116 + if (xrt_reference_dec_and_is_zero(&conn->ref)) { 117 117 wmr_hmd_controller_connection_destroy(conn); 118 118 } else { 119 119 os_mutex_lock(&conn->lock);
+2 -2
src/xrt/include/xrt/xrt_compositor.h
··· 498 498 *dst = src; 499 499 500 500 if (old_dst) { 501 - if (xrt_reference_dec(&old_dst->reference)) { 501 + if (xrt_reference_dec_and_is_zero(&old_dst->reference)) { 502 502 old_dst->destroy(old_dst); 503 503 } 504 504 } ··· 694 694 *dst = src; 695 695 696 696 if (old_dst) { 697 - if (xrt_reference_dec(&old_dst->reference)) { 697 + if (xrt_reference_dec_and_is_zero(&old_dst->reference)) { 698 698 old_dst->destroy(old_dst); 699 699 } 700 700 }
+38 -1
src/xrt/include/xrt/xrt_defines.h
··· 1304 1304 * 1305 1305 */ 1306 1306 1307 + /*! 1308 + * Increment the reference, probably want @ref xrt_reference_inc_and_was_zero. 1309 + * 1310 + * @memberof xrt_reference 1311 + * @ingroup xrt_iface 1312 + */ 1307 1313 static inline void 1308 1314 xrt_reference_inc(struct xrt_reference *xref) 1309 1315 { 1310 1316 xrt_atomic_s32_inc_return(&xref->count); 1311 1317 } 1312 1318 1313 - static inline bool 1319 + /*! 1320 + * Decrement the reference, probably want @ref xrt_reference_dec_and_is_zero. 1321 + * 1322 + * @memberof xrt_reference 1323 + * @ingroup xrt_iface 1324 + */ 1325 + static inline void 1314 1326 xrt_reference_dec(struct xrt_reference *xref) 1327 + { 1328 + xrt_atomic_s32_dec_return(&xref->count); 1329 + } 1330 + 1331 + /*! 1332 + * Increment the reference and return true if the value @p was zero. 1333 + * 1334 + * @memberof xrt_reference 1335 + * @ingroup xrt_iface 1336 + */ 1337 + XRT_CHECK_RESULT static inline bool 1338 + xrt_reference_inc_and_was_zero(struct xrt_reference *xref) 1339 + { 1340 + int32_t count = xrt_atomic_s32_inc_return(&xref->count); 1341 + return count == 1; 1342 + } 1343 + 1344 + /*! 1345 + * Decrement the reference and return true if the value is now zero. 1346 + * 1347 + * @memberof xrt_reference 1348 + * @ingroup xrt_iface 1349 + */ 1350 + XRT_CHECK_RESULT static inline bool 1351 + xrt_reference_dec_and_is_zero(struct xrt_reference *xref) 1315 1352 { 1316 1353 int32_t count = xrt_atomic_s32_dec_return(&xref->count); 1317 1354 return count == 0;
+1 -1
src/xrt/include/xrt/xrt_frame.h
··· 143 143 *dst = src; 144 144 145 145 if (old_dst) { 146 - if (xrt_reference_dec(&old_dst->reference)) { 146 + if (xrt_reference_dec_and_is_zero(&old_dst->reference)) { 147 147 old_dst->destroy(old_dst); 148 148 } 149 149 }
+1 -1
src/xrt/include/xrt/xrt_space.h
··· 66 66 *dst = src; 67 67 68 68 if (old_dst) { 69 - if (xrt_reference_dec(&old_dst->reference)) { 69 + if (xrt_reference_dec_and_is_zero(&old_dst->reference)) { 70 70 old_dst->destroy(old_dst); 71 71 } 72 72 }
+1 -1
src/xrt/state_trackers/oxr/oxr_objects.h
··· 2152 2152 static inline void 2153 2153 oxr_refcounted_unref(struct oxr_refcounted *orc) 2154 2154 { 2155 - if (xrt_reference_dec(&orc->base)) { 2155 + if (xrt_reference_dec_and_is_zero(&orc->base)) { 2156 2156 orc->destroy(orc); 2157 2157 } 2158 2158 }