diff --git a/src/xrt/include/xrt/xrt_defines.h b/src/xrt/include/xrt/xrt_defines.h index 8758ef82a..ef1231296 100644 --- a/src/xrt/include/xrt/xrt_defines.h +++ b/src/xrt/include/xrt/xrt_defines.h @@ -16,6 +16,16 @@ extern "C" { #endif +/*! + * A base class for reference counted objects. + * + * @ingroup xrt_iface + */ +struct xrt_reference +{ + uint32_t count; +}; + /*! * Which blend mode does the device support, used as both a bitfield and value. * @@ -356,6 +366,26 @@ union xrt_output_value { }; +/* + * + * Inline functions + * + */ + +static inline bool +xrt_reference_dec(struct xrt_reference *xref) +{ + int count = xrt_atomic_dec_return(&xref->count); + return count == 0; +} + +static inline void +xrt_reference_inc(struct xrt_reference *xref) +{ + xrt_atomic_inc_return(&xref->count); +} + + #ifdef __cplusplus } #endif