ref: 11729e23cb62f2e262afd4580906b6aca4f7a113
parent: 18dbc24cdfd2f6b1105589fbf261b528e7d35035
author: Sigrid <ftrvxmtrx@gmail.com>
date: Fri Jun 19 12:52:35 EDT 2020
arm64/tas: use atomic builtin when possible, fixes drawterm on aarch64 android
--- a/posix-arm64/tas.c
+++ b/posix-arm64/tas.c
@@ -1,9 +1,16 @@
#include "u.h"
#include "libc.h"
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
int
tas(int *x)
{
+#if __has_builtin(__atomic_test_and_set) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)))
+ return __atomic_test_and_set(x, __ATOMIC_ACQ_REL);
+#else
int v,t, i = 1;
__asm__ (
@@ -23,4 +30,5 @@
print("canlock: corrupted 0x%lux\n", v);
return 1;
}
+#endif
}