X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=php5-apc.git;a=blobdiff_plain;f=arch%2Fx86_64%2Fatomic.h;fp=arch%2Fx86_64%2Fatomic.h;h=4b882d5a2e6966e28978dab6fb5b19f27ee3a588;hp=0000000000000000000000000000000000000000;hb=3682e0a7a26931aabca2b6e54eb08efd7dc0430b;hpb=575ce08215526bb71a967d69d601e77e1afbcd11 diff --git a/arch/x86_64/atomic.h b/arch/x86_64/atomic.h new file mode 100644 index 0000000..4b882d5 --- /dev/null +++ b/arch/x86_64/atomic.h @@ -0,0 +1,80 @@ +/* + +----------------------------------------------------------------------+ + | APC | + +----------------------------------------------------------------------+ + | Copyright (c) 2006 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Brian Shire | + +----------------------------------------------------------------------+ + + */ + +/* $Id: atomic.h,v 1.1 2006/09/29 07:13:01 shire Exp $ */ + + +#include +#include +#include + +/* int sys_futex (void *futex, int op, int val, const struct timespec *timeout); */ +static inline long int apc_sys_futex(void *futex, int op, int val, const struct timespec *timeout) { + + long int ret; + + /* x86_64 system calls are performed with the faster SYSCALL operation. + * the argument order is D, S, d, c, b, a rather than + * a, b, c, d, S, D as on the i386 int 80h call. + */ + asm volatile ("syscall" + : "=a" (ret) + : "0" (SYS_futex), + "D" (futex), + "S" (op), + "d" (val), + "c" (timeout) + : "r11", "rcx", "memory" + ); + + return ret; + +} + + +static inline int apc_cmpxchg(volatile int *ptr, int old, int new) { + + int prev; + + asm volatile ("LOCK cmpxchgl %1, %2" + : "=a" (prev) + : "r" (new), + "m" (*(ptr)), + "0"(old) + : "memory", "cc" + ); + + return prev; +} + +static inline int apc_xchg(volatile int *ptr, int new) { + + int ret; + + asm volatile ("LOCK xchgl %[new], %[ptr]" + : "=a" (ret) + : [new] "0" (new), + [ptr] "m" (*(ptr)) + : "memory" + ); + + return ret; + +} +