By analogy with InterlockedIncrement. It avoids the need for a configure check on Windows platforms.
Signed-off-by: Alexandre Julliard julliard@winehq.org --- v2: make enqueued_fence_count a LONG as well --- include/private/vkd3d_common.h | 13 ++++--------- libs/vkd3d/command.c | 6 +++--- libs/vkd3d/vkd3d_private.h | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h index d22c26c098c7..1e19758abc40 100644 --- a/include/private/vkd3d_common.h +++ b/include/private/vkd3d_common.h @@ -201,6 +201,10 @@ static inline LONG InterlockedIncrement(LONG volatile *x) { return __sync_add_and_fetch(x, 1); } +static inline LONG InterlockedAdd(LONG volatile *x, LONG val) +{ + return __sync_add_and_fetch(x, val); +} # else # error "InterlockedIncrement() not implemented for this platform" # endif /* HAVE_SYNC_ADD_AND_FETCH */ @@ -215,15 +219,6 @@ static inline LONG InterlockedDecrement(LONG volatile *x) # endif #endif /* _WIN32 */
-#if HAVE_SYNC_ADD_AND_FETCH -# define atomic_add_fetch(ptr, val) __sync_add_and_fetch(ptr, val) -#elif defined(_MSC_VER) -/* InterlockedAdd returns value after increment, like add_and_fetch. */ -# define atomic_add_fetch(ptr, val) InterlockedAdd(ptr, val) -#else -# error "atomic_add_fetch() not implemented for this platform" -#endif /* HAVE_SYNC_ADD_AND_FETCH */ - static inline void vkd3d_parse_version(const char *version, int *major, int *minor) { *major = atoi(version); diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 2cf1eba23d94..f1ec6be3fd20 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -288,7 +288,7 @@ static void vkd3d_fence_worker_remove_fence(struct vkd3d_fence_worker *worker, s LONG count; int rc;
- if (!(count = atomic_add_fetch(&fence->pending_worker_operation_count, 0))) + if (!(count = InterlockedAdd(&fence->pending_worker_operation_count, 0))) return;
WARN("Waiting for %u pending fence operations (fence %p).\n", count, fence); @@ -299,7 +299,7 @@ static void vkd3d_fence_worker_remove_fence(struct vkd3d_fence_worker *worker, s return; }
- while ((count = atomic_add_fetch(&fence->pending_worker_operation_count, 0))) + while ((count = InterlockedAdd(&fence->pending_worker_operation_count, 0))) { TRACE("Still waiting for %u pending fence operations (fence %p).\n", count, fence);
@@ -410,7 +410,7 @@ static void *vkd3d_fence_worker_main(void *arg) { vkd3d_wait_for_gpu_fences(worker);
- if (!worker->fence_count || atomic_add_fetch(&worker->enqueued_fence_count, 0)) + if (!worker->fence_count || InterlockedAdd(&worker->enqueued_fence_count, 0)) { if ((rc = pthread_mutex_lock(&worker->mutex))) { diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 136b020330a9..d21cd411ec8a 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -192,7 +192,7 @@ struct vkd3d_fence_worker bool should_exit; bool pending_fence_destruction;
- size_t enqueued_fence_count; + LONG enqueued_fence_count; struct vkd3d_enqueued_fence { VkFence vk_fence;