void-packages/srcpkgs/sysbench/patches/atomics.patch
Đoàn Trần Công Danh 4b97cd2fb4 srcpkgs/s*: convert patches to -Np1
```sh
git grep -l '^patch_args=-Np0' "srcpkgs/$1*/template" |
while read template; do
	for p in ${template%/template}/patches/*; do
		sed -i '
			\,^[+-][+-][+-] /dev/null,b
			/^[*-]\+ [0-9]\+\(,[0-9]\+\)\? [*-]\+$/b
			s,^[*][*][*] ,&a/,
			/^--- /{
				s,\(^--- \)\(./\)*,\1a/,
				s,[.-][Oo][Rr][Ii][Gg]\([	/]\),\1,
				s/[.-][Oo][Rr][Ii][Gg]$//
				s/[.]patched[.]\([^.]\)/.\1/
				h
			}
			/^+++ -/{
				g
				s/^--- a/+++ b/
				b
			}
			s,\(^+++ \)\(./\)*,\1b/,
		' "$p"
	done
	sed -i '/^patch_args=/d' $template
done
```
2021-06-20 13:17:29 +07:00

42 lines
1.7 KiB
Diff

Use C11 style atomic builtins instead of the legacy __sync primitives
This is because unlike legacy __sync stuff, __atomic_* can make use of
libatomic on any arbitrary platform, while on e.g. ppc32 and mips,
__sync_val_compare_and_swap_8 and so on are not available at all.
--- a/src/sb_ck_pr.h
+++ b/src/sb_ck_pr.h
@@ -118,7 +118,8 @@ CK_PR_LOAD_S(64, uint64_t)
ck_pr_cas_##S(M *target, T compare, T set) \
{ \
bool z; \
- z = __sync_bool_compare_and_swap((T *)target, compare, set); \
+ z = __atomic_compare_exchange((T *)target, &compare, &set, \
+ false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
return z; \
}
@@ -133,9 +134,11 @@ CK_PR_CAS_S(64, uint64_t)
CK_CC_INLINE static bool \
ck_pr_cas_##S##_value(T *target, T compare, T set, T *v) \
{ \
- set = __sync_val_compare_and_swap(target, compare, set);\
- *v = set; \
- return (set == compare); \
+ bool z; \
+ z = __atomic_compare_exchange(target, &compare, &set, false, \
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
+ *v = compare; \
+ return z; \
}
CK_PR_CAS_O(64, uint64_t)
@@ -149,7 +152,7 @@ CK_PR_CAS_O(64, uint64_t)
CK_CC_INLINE static void \
ck_pr_##K##_##S(M *target, T d) \
{ \
- d = __sync_fetch_and_##K((T *)target, d); \
+ d = __atomic_fetch_##K((T *)target, d, __ATOMIC_SEQ_CST); \
return; \
}