New PHP5 APC - version 3.0.18, using PHP5 5.2.0-8+etch10,
[php5-apc.git] / arch / x86_64 / atomic.h
1 /*
2   +----------------------------------------------------------------------+
3   | APC                                                                  |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 2006 The PHP Group                                     |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: Brian Shire <shire@php.net>                                 |
16   +----------------------------------------------------------------------+
17
18  */
19
20 /* $Id: atomic.h,v 1.1 2006/09/29 07:13:01 shire Exp $ */
21
22
23 #include <sys/syscall.h>
24 #include <sys/time.h>
25 #include <linux/futex.h>
26
27 /* int sys_futex (void *futex, int op, int val, const struct timespec *timeout); */
28 static inline long int apc_sys_futex(void *futex, int op, int val, const struct timespec *timeout) {
29
30   long int ret;
31
32   /* x86_64 system calls are performed with the faster SYSCALL operation.
33    *  the argument order is D, S, d, c, b, a rather than
34    *  a, b, c, d, S, D as on the i386 int 80h call. 
35   */ 
36   asm volatile ("syscall" 
37        : "=a" (ret)
38        : "0" (SYS_futex), 
39          "D" (futex), 
40          "S" (op), 
41          "d" (val),
42          "c" (timeout)
43        : "r11", "rcx", "memory"
44       );
45
46   return ret;
47
48
49
50
51 static inline int apc_cmpxchg(volatile int *ptr, int old, int new) {
52
53     int prev;
54
55     asm volatile ("LOCK cmpxchgl %1, %2"
56                    : "=a" (prev)
57                    : "r" (new), 
58                      "m" (*(ptr)), 
59                      "0"(old)
60                    : "memory", "cc"
61                  );
62
63     return prev;
64 }
65
66 static inline int apc_xchg(volatile int *ptr, int new) {
67
68     int ret;
69   
70     asm volatile ("LOCK xchgl %[new], %[ptr]"
71                   : "=a" (ret)
72                   : [new] "0" (new), 
73                     [ptr] "m" (*(ptr))
74                   : "memory"
75                  );
76
77     return ret;
78     
79 }
80