By analogy with InterlockedIncrement. It avoids the need for a configure check on Windows platforms.
Signed-off-by: Alexandre Julliard julliard@winehq.org --- include/private/vkd3d_common.h | 13 ++++--------- libs/vkd3d/command.c | 6 +++--- 2 files changed, 7 insertions(+), 12 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))) {
On Fri, 28 Jan 2022 at 16:10, Alexandre Julliard julliard@winehq.org wrote:
@@ -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)) {
Unfortunately this introduces build warnings for the non-PE builds:
<vkd3d>/libs/vkd3d/command.c: In function ‘vkd3d_fence_worker_main’: <vkd3d>/libs/vkd3d/command.c:413:52: warning: pointer targets in passing argument 1 of ‘InterlockedAdd’ differ in signedness [-Wpointer-sign] if (!worker->fence_count || InterlockedAdd(&worker->enqueued_fence_count, 0))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from <vkd3d>/libs/vkd3d/vkd3d_private.h:26, from <vkd3d>/libs/vkd3d/command.c:21: <vkd3d>/include/private/vkd3d_common.h:204:20: note: expected ‘volatile LONG *’ {aka ‘volatile int ’} but argument is of type ‘size_t *’ {aka ‘unsigned int *’} static inline LONG InterlockedAdd(LONG volatile *x, LONG val) ^~~~~~~~~~~~~~