Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 /*
0009  * "casa   [r1] 0x80, r2, r0"  and
0010  * "casxa  [r1] 0x80, r2, r0"  do the following:
0011  *
0012  *     if ([r1] == r2) {
0013  *         swap(r0, [r1]);
0014  *     } else {
0015  *         r0 = [r1];
0016  *     }
0017  *
0018  * so "r0 == r2" means that the operation was successful.
0019  *
0020  *
0021  * The "r" means the general register.
0022  * The "+r" means the general register used for both input and output.
0023  */
0024 
0025 
0026 #if (NGX_PTR_SIZE == 4)
0027 #define NGX_CASA  "casa"
0028 #else
0029 #define NGX_CASA  "casxa"
0030 #endif
0031 
0032 
0033 static ngx_inline ngx_atomic_uint_t
0034 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
0035     ngx_atomic_uint_t set)
0036 {
0037     __asm__ volatile (
0038 
0039     NGX_CASA " [%1] 0x80, %2, %0"
0040 
0041     : "+r" (set) : "r" (lock), "r" (old) : "memory");
0042 
0043     return (set == old);
0044 }
0045 
0046 
0047 static ngx_inline ngx_atomic_int_t
0048 ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add)
0049 {
0050     ngx_atomic_uint_t  old, res;
0051 
0052     old = *value;
0053 
0054     for ( ;; ) {
0055 
0056         res = old + add;
0057 
0058         __asm__ volatile (
0059 
0060         NGX_CASA " [%1] 0x80, %2, %0"
0061 
0062         : "+r" (res) : "r" (value), "r" (old) : "memory");
0063 
0064         if (res == old) {
0065             return res;
0066         }
0067 
0068         old = res;
0069     }
0070 }
0071 
0072 
0073 #if (NGX_SMP)
0074 #define ngx_memory_barrier()                                                  \
0075             __asm__ volatile (                                                \
0076             "membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"        \
0077             ::: "memory")
0078 #else
0079 #define ngx_memory_barrier()   __asm__ volatile ("" ::: "memory")
0080 #endif
0081 
0082 #define ngx_cpu_pause()