void-packages/srcpkgs/renderdoc/patches/atomic.patch
Đoàn Trần Công Danh 6b94e7e96a renderdoc: need c++14
auto in lambda
2022-01-12 19:22:17 +07:00

58 lines
1.5 KiB
Diff

@q66: replace old __sync stuff with equivalent modern ones,
so we can use libatomic on targets without atomic8 support
--- a/renderdoc/CMakeLists.txt
+++ b/renderdoc/CMakeLists.txt
@@ -55,6 +55,10 @@ elseif(UNIX)
PRIVATE -ldl
PRIVATE -lrt)
+option(NEED_LIBATOMIC "need libatomic" OFF)
+if (NEED_LIBATOMIC)
+list(APPEND RDOC_LIBRARIES PRIVATE -latomic)
+endif()
if(ENABLE_XLIB)
find_package(X11 REQUIRED)
--- a/renderdoc/os/posix/posix_threading.cpp
+++ b/renderdoc/os/posix/posix_threading.cpp
@@ -43,32 +43,33 @@ namespace Atomic
{
int32_t Inc32(int32_t *i)
{
- return __sync_add_and_fetch(i, int32_t(1));
+ return __atomic_add_fetch(i, int32_t(1), __ATOMIC_SEQ_CST);
}
int32_t Dec32(int32_t *i)
{
- return __sync_add_and_fetch(i, int32_t(-1));
+ return __atomic_sub_fetch(i, int32_t(1), __ATOMIC_SEQ_CST);
}
int64_t Inc64(int64_t *i)
{
- return __sync_add_and_fetch(i, int64_t(1));
+ return __atomic_add_fetch(i, int64_t(1), __ATOMIC_SEQ_CST);
}
int64_t Dec64(int64_t *i)
{
- return __sync_add_and_fetch(i, int64_t(-1));
+ return __atomic_sub_fetch(i, int64_t(1), __ATOMIC_SEQ_CST);
}
int64_t ExchAdd64(int64_t *i, int64_t a)
{
- return __sync_add_and_fetch(i, int64_t(a));
+ return __atomic_add_fetch(i, a, __ATOMIC_SEQ_CST);
}
int32_t CmpExch32(int32_t *dest, int32_t oldVal, int32_t newVal)
{
- return __sync_val_compare_and_swap(dest, oldVal, newVal);
+ __atomic_compare_exchange_n(dest, &oldVal, newVal, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+ return oldVal;
}
};