From: Henri Verbeet hverbeet@codeweavers.com
--- include/private/vkd3d_common.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index f01c71253..6c8f8eedc 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -278,20 +278,32 @@ static inline uint64_t vkd3d_atomic_add_fetch_u64(uint64_t volatile *x, uint64_t #endif }
+static inline uint32_t vkd3d_atomic_add_fetch_u32(uint32_t volatile *x, uint32_t val) +{ +#if HAVE_SYNC_ADD_AND_FETCH + return __sync_add_and_fetch(x, val); +#elif defined(_WIN32) + return InterlockedAdd((LONG *)x, val); +#else +# error "vkd3d_atomic_add_fetch_u32() not implemented for this platform" +#endif +} + static inline uint64_t vkd3d_atomic_increment_u64(uint64_t volatile *x) { return vkd3d_atomic_add_fetch_u64(x, 1); }
+static inline uint32_t vkd3d_atomic_increment_u32(uint32_t volatile *x) +{ + return vkd3d_atomic_add_fetch_u32(x, 1); +} + #ifndef _WIN32 -# if HAVE_SYNC_ADD_AND_FETCH static inline LONG InterlockedIncrement(LONG volatile *x) { - return __sync_add_and_fetch(x, 1); + return vkd3d_atomic_increment_u32((uint32_t *)x); } -# else -# error "InterlockedIncrement() not implemented for this platform" -# endif /* HAVE_SYNC_ADD_AND_FETCH */
# if HAVE_SYNC_SUB_AND_FETCH static inline LONG InterlockedDecrement(LONG volatile *x)
From: Henri Verbeet hverbeet@codeweavers.com
--- libs/vkd3d-common/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-common/debug.c b/libs/vkd3d-common/debug.c index aa7df5bd7..e12cd3945 100644 --- a/libs/vkd3d-common/debug.c +++ b/libs/vkd3d-common/debug.c @@ -126,10 +126,10 @@ void vkd3d_dbg_set_log_callback(PFN_vkd3d_log callback) static char *get_buffer(void) { static char buffers[VKD3D_DEBUG_BUFFER_COUNT][VKD3D_DEBUG_BUFFER_SIZE]; - static LONG buffer_index; - LONG current_index; + static unsigned int buffer_index; + unsigned int current_index;
- current_index = InterlockedIncrement(&buffer_index) % ARRAY_SIZE(buffers); + current_index = vkd3d_atomic_increment_u32(&buffer_index) % ARRAY_SIZE(buffers); return buffers[current_index]; }
From: Henri Verbeet hverbeet@codeweavers.com
--- libs/vkd3d-common/blob.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-common/blob.c b/libs/vkd3d-common/blob.c index 0f6d5a5ee..0e178d120 100644 --- a/libs/vkd3d-common/blob.c +++ b/libs/vkd3d-common/blob.c @@ -27,7 +27,7 @@ struct vkd3d_blob { ID3D10Blob ID3DBlob_iface; - LONG refcount; + unsigned int refcount;
void *buffer; SIZE_T size; @@ -59,7 +59,7 @@ static HRESULT STDMETHODCALLTYPE vkd3d_blob_QueryInterface(ID3DBlob *iface, REFI static ULONG STDMETHODCALLTYPE vkd3d_blob_AddRef(ID3DBlob *iface) { struct vkd3d_blob *blob = impl_from_ID3DBlob(iface); - ULONG refcount = InterlockedIncrement(&blob->refcount); + unsigned int refcount = vkd3d_atomic_increment_u32(&blob->refcount);
TRACE("%p increasing refcount to %u.\n", blob, refcount);
@@ -69,7 +69,7 @@ static ULONG STDMETHODCALLTYPE vkd3d_blob_AddRef(ID3DBlob *iface) static ULONG STDMETHODCALLTYPE vkd3d_blob_Release(ID3DBlob *iface) { struct vkd3d_blob *blob = impl_from_ID3DBlob(iface); - ULONG refcount = InterlockedDecrement(&blob->refcount); + ULONG refcount = InterlockedDecrement((LONG *)&blob->refcount);
TRACE("%p decreasing refcount to %u.\n", blob, refcount);
From: Henri Verbeet hverbeet@codeweavers.com
--- include/private/vkd3d_common.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index 6c8f8eedc..46090eac1 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -294,6 +294,11 @@ static inline uint64_t vkd3d_atomic_increment_u64(uint64_t volatile *x) return vkd3d_atomic_add_fetch_u64(x, 1); }
+static inline uint32_t vkd3d_atomic_decrement_u32(uint32_t volatile *x) +{ + return vkd3d_atomic_add_fetch_u32(x, ~0u); +} + static inline uint32_t vkd3d_atomic_increment_u32(uint32_t volatile *x) { return vkd3d_atomic_add_fetch_u32(x, 1); @@ -305,15 +310,10 @@ static inline LONG InterlockedIncrement(LONG volatile *x) return vkd3d_atomic_increment_u32((uint32_t *)x); }
-# if HAVE_SYNC_SUB_AND_FETCH static inline LONG InterlockedDecrement(LONG volatile *x) { - return __sync_sub_and_fetch(x, 1); + return vkd3d_atomic_decrement_u32((uint32_t *)x); } -# else -# error "InterlockedDecrement() not implemented for this platform" -# endif - #endif /* _WIN32 */
static inline void vkd3d_parse_version(const char *version, int *major, int *minor)
From: Henri Verbeet hverbeet@codeweavers.com
--- libs/vkd3d-common/blob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-common/blob.c b/libs/vkd3d-common/blob.c index 0e178d120..6c893b892 100644 --- a/libs/vkd3d-common/blob.c +++ b/libs/vkd3d-common/blob.c @@ -69,7 +69,7 @@ static ULONG STDMETHODCALLTYPE vkd3d_blob_AddRef(ID3DBlob *iface) static ULONG STDMETHODCALLTYPE vkd3d_blob_Release(ID3DBlob *iface) { struct vkd3d_blob *blob = impl_from_ID3DBlob(iface); - ULONG refcount = InterlockedDecrement((LONG *)&blob->refcount); + unsigned int refcount = vkd3d_atomic_decrement_u32(&blob->refcount);
TRACE("%p decreasing refcount to %u.\n", blob, refcount);
This merge request was approved by Giovanni Mascellani.