The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

i/xrt: Add debugging tools for xrt_reference

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2499>

authored by

Beyley Cardellio and committed by
Marge Bot
c6a7804c ca895cc4

+28 -4
+28 -4
src/xrt/include/xrt/xrt_defines.h
··· 13 13 #pragma once 14 14 15 15 #include "xrt/xrt_compiler.h" 16 + #include "xrt/xrt_results.h" 16 17 17 - #include "xrt/xrt_results.h" 18 + #include <stdio.h> 18 19 19 20 #ifdef __cplusplus 20 21 extern "C" { ··· 2124 2125 * 2125 2126 */ 2126 2127 2128 + // @note We're not using U_LOG_RAW because we can't include u_logging.h inside xrt_defines.h without causing problems. 2129 + #if 0 2130 + #define XRT_REFERENCE_DEBUG_PRINT(ACTION, PTR, COUNT) \ 2131 + do { \ 2132 + int32_t __count = (COUNT); \ 2133 + printf(#ACTION " %p to %u", (void *)(PTR), __count); \ 2134 + if (__count < 0) { \ 2135 + XRT_DEBUGBREAK(); \ 2136 + } \ 2137 + } while (false) 2138 + #else 2139 + #define XRT_REFERENCE_DEBUG_PRINT(ACTION, PTR, COUNT) 2140 + #endif 2141 + 2127 2142 /*! 2128 2143 * Increment the reference, probably want @ref xrt_reference_inc_and_was_zero. 2129 2144 * ··· 2133 2148 static inline void 2134 2149 xrt_reference_inc(struct xrt_reference *xref) 2135 2150 { 2136 - xrt_atomic_s32_inc_return(&xref->count); 2151 + XRT_MAYBE_UNUSED int32_t count = xrt_atomic_s32_inc_return(&xref->count); 2152 + 2153 + XRT_REFERENCE_DEBUG_PRINT(Incremented, xref, count); 2137 2154 } 2138 2155 2139 2156 /*! ··· 2145 2162 static inline void 2146 2163 xrt_reference_dec(struct xrt_reference *xref) 2147 2164 { 2148 - xrt_atomic_s32_dec_return(&xref->count); 2165 + XRT_MAYBE_UNUSED int32_t count = xrt_atomic_s32_dec_return(&xref->count); 2166 + 2167 + XRT_REFERENCE_DEBUG_PRINT(Decremented, xref, count); 2149 2168 } 2150 2169 2151 2170 /*! ··· 2158 2177 xrt_reference_inc_and_was_zero(struct xrt_reference *xref) 2159 2178 { 2160 2179 int32_t count = xrt_atomic_s32_inc_return(&xref->count); 2180 + 2181 + XRT_REFERENCE_DEBUG_PRINT(Incremented, xref, count); 2182 + 2161 2183 return count == 1; 2162 2184 } 2163 2185 ··· 2171 2193 xrt_reference_dec_and_is_zero(struct xrt_reference *xref) 2172 2194 { 2173 2195 int32_t count = xrt_atomic_s32_dec_return(&xref->count); 2196 + 2197 + XRT_REFERENCE_DEBUG_PRINT(Decremented, xref, count); 2198 + 2174 2199 return count == 0; 2175 2200 } 2176 - 2177 2201 2178 2202 #ifdef __cplusplus 2179 2203 }