[PATCH vkd3d 2/2] vkd3d: Replace atomic_add_fetch() by InterlockedAdd().

Alexandre Julliard julliard at winehq.org
Fri Jan 28 09:10:44 CST 2022


By analogy with InterlockedIncrement. It avoids the need for a
configure check on Windows platforms.

Signed-off-by: Alexandre Julliard <julliard at 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)))
             {
-- 
2.34.1



More information about the wine-devel mailing list