src/os/unix/ngx_gcc_atomic_sparc64.h - nginx-1.7.10

Functions defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. /*
  6. * "casa   [r1] 0x80, r2, r0"  and
  7. * "casxa  [r1] 0x80, r2, r0"  do the following:
  8. *
  9. *     if ([r1] == r2) {
  10. *         swap(r0, [r1]);
  11. *     } else {
  12. *         r0 = [r1];
  13. *     }
  14. *
  15. * so "r0 == r2" means that the operation was successful.
  16. *
  17. *
  18. * The "r" means the general register.
  19. * The "+r" means the general register used for both input and output.
  20. */


  21. #if (NGX_PTR_SIZE == 4)
  22. #define NGX_CASA  "casa"
  23. #else
  24. #define NGX_CASA  "casxa"
  25. #endif


  26. static ngx_inline ngx_atomic_uint_t
  27. ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
  28.     ngx_atomic_uint_t set)
  29. {
  30.     __asm__ volatile (

  31.     NGX_CASA " [%1] 0x80, %2, %0"

  32.     : "+r" (set) : "r" (lock), "r" (old) : "memory");

  33.     return (set == old);
  34. }


  35. static ngx_inline ngx_atomic_int_t
  36. ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add)
  37. {
  38.     ngx_atomic_uint_t  old, res;

  39.     old = *value;

  40.     for ( ;; ) {

  41.         res = old + add;

  42.         __asm__ volatile (

  43.         NGX_CASA " [%1] 0x80, %2, %0"

  44.         : "+r" (res) : "r" (value), "r" (old) : "memory");

  45.         if (res == old) {
  46.             return res;
  47.         }

  48.         old = res;
  49.     }
  50. }


  51. #if (NGX_SMP)
  52. #define ngx_memory_barrier()                                                  \
  53.             __asm__ volatile (                                                \
  54.             "membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"        \
  55.             ::: "memory")
  56. #else
  57. #define ngx_memory_barrier()   __asm__ volatile ("" ::: "memory")
  58. #endif

  59. #define ngx_cpu_pause()