Re: atomic cas, again; PHP this time
Dixi quod…
>Geert Uytterhoeven dixit:
>
>>Yes, you should use the syscall, as finding out whether cas is safe
>>or not from userspace is non-trivial.
>by the particular libc. So I guess I will have to “repurpose” a
>few lines from the libgcc helper.
Does this look sound to you (all of you) and not close enough to
the actual libgcc source to be a derived work of it? (Went through
quite a few iterations of it… I hate GCC’s inline asm!)
Description: add Linux/m68k atomic code
Origin: libgcc 4.7
Bug: https://bugs.php.net/bug.php?id=60925
Author: Thorsten Glaser <tg@debian.org>
Index: php5-5.4.0/sapi/fpm/fpm/fpm_atomic.h
===================================================================
--- php5-5.4.0.orig/sapi/fpm/fpm/fpm_atomic.h 2011-06-26 15:48:11.000000000 +0000
+++ php5-5.4.0/sapi/fpm/fpm/fpm_atomic.h 2012-03-12 21:11:44.000000000 +0000
@@ -5,6 +5,12 @@
#ifndef FPM_ATOMIC_H
#define FPM_ATOMIC_H 1
+#if defined(__m68k__)
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#endif
+
#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
@@ -137,6 +143,34 @@
#error Sparc v8 and predecessors are not and will not be supported (see bug report 53310)
#endif /* #if (__sparcv9 || __sparcv9__) */
+#elif defined(__m68k__) && defined(__linux__)
+
+typedef signed int atomic_int_t __attribute__((__aligned__(4)));
+typedef unsigned int atomic_uint_t __attribute__((__aligned__(4)));
+typedef volatile unsigned int atomic_t __attribute__((__aligned__(4)));
+
+#ifndef SYS_atomic_cmpxchg_32
+#define SYS_atomic_cmpxchg_32 335
+#endif
+
+static inline atomic_uint_t atomic_cas_32(atomic_t *lock, atomic_uint_t old, atomic_uint_t new) /* {{{ */
+{
+ register atomic_t *a0 asm("a0") = lock;
+ register atomic_uint_t d2 asm("d2") = old;
+ register atomic_uint_t d1 asm("d1") = new;
+ register atomic_uint_t d0 asm("d0") = SYS_atomic_cmpxchg_32;
+
+ asm volatile("trap #0" : "+r" (d0), "+r" (d1), "+r" (a0) : "r" (d2) : "memory", "a1");
+ return (d0);
+}
+/* }}} */
+
+static inline atomic_uint_t atomic_cmp_set(atomic_t *lock, atomic_uint_t old, atomic_uint_t set) /* {{{ */
+{
+ return (atomic_cas_32(lock, old, set) == old);
+}
+/* }}} */
+
#else
#error Unsupported processor. Please open a bug report (bugs.php.net).
bye,
//mirabilos
--
.intel_syntax noprefix
.code16
.text
reboot: ljmp 0xF000,0xFFF0
Reply to: