X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=php5-apc.git;a=blobdiff_plain;f=arch%2Fi386%2Fatomic.h;fp=arch%2Fi386%2Fatomic.h;h=069a5b06fa3c19eb590a1c3a71bf7b350a5b6858;hp=0000000000000000000000000000000000000000;hb=3682e0a7a26931aabca2b6e54eb08efd7dc0430b;hpb=575ce08215526bb71a967d69d601e77e1afbcd11 diff --git a/arch/i386/atomic.h b/arch/i386/atomic.h new file mode 100644 index 0000000..069a5b0 --- /dev/null +++ b/arch/i386/atomic.h @@ -0,0 +1,79 @@ +/* + +----------------------------------------------------------------------+ + | 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; + + /* i386 system calls are performed with nt 80h operation. + * the argument order is a, b, c, d, S, D + */ + asm volatile ("int $0x80" + : "=a" (ret) + : "0" (SYS_futex), + "b" (futex), + "c" (op), + "d" (val), + "S" (timeout) + : "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; + +} +