"Fossies" - the Fresh Open Source Software Archive

Member "openpa-1.0.4/src/primitives/opa_sun_atomic_ops.h" (5 Dec 2012, 2943 Bytes) of package /linux/misc/openpa-1.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "opa_sun_atomic_ops.h" see the Fossies "Dox" file reference documentation.

    1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
    2 /*  
    3  *  (C) 2008 by Argonne National Laboratory.
    4  *      See COPYRIGHT in top-level directory.
    5  */
    6 
    7 
    8 #ifndef OPA_SUN_ATOMIC_OPS_H_INCLUDED
    9 #define OPA_SUN_ATOMIC_OPS_H_INCLUDED
   10 
   11 #include <atomic.h>
   12 
   13 typedef struct { volatile uint_t v;  } OPA_int_t;
   14 typedef struct { void * volatile v; } OPA_ptr_t;
   15 
   16 #define OPA_INT_T_INITIALIZER(val_) { (val_) }
   17 #define OPA_PTR_T_INITIALIZER(val_) { (val_) }
   18 
   19 static _opa_inline int OPA_load_int(_opa_const OPA_int_t *ptr)
   20 {
   21     return (int)ptr->v;
   22 }
   23 
   24 static _opa_inline void OPA_store_int(OPA_int_t *ptr, int val)
   25 {
   26     ptr->v = (uint)val;
   27 }
   28 
   29 static _opa_inline void *OPA_load_ptr(_opa_const OPA_ptr_t *ptr)
   30 {
   31     return ptr->v;
   32 }
   33 
   34 static _opa_inline void OPA_store_ptr(OPA_ptr_t *ptr, void *val)
   35 {
   36     ptr->v = val;
   37 }
   38 
   39 static _opa_inline int OPA_load_acquire_int(_opa_const OPA_int_t *ptr)
   40 {
   41     int tmp;
   42     tmp = ptr->v;
   43     membar_enter();
   44     return tmp;
   45 }
   46 
   47 static _opa_inline void OPA_store_release_int(OPA_int_t *ptr, int val)
   48 {
   49     membar_exit();
   50     ptr->v = val;
   51 }
   52 
   53 static _opa_inline void *OPA_load_acquire_ptr(_opa_const OPA_ptr_t *ptr)
   54 {
   55     void *tmp;
   56     tmp = ptr->v;
   57     membar_enter();
   58     return tmp;
   59 }
   60 
   61 static _opa_inline void OPA_store_release_ptr(OPA_ptr_t *ptr, void *val)
   62 {
   63     membar_exit();
   64     ptr->v = val;
   65 }
   66 
   67 
   68 static _opa_inline void OPA_add_int(OPA_int_t *ptr, int val)
   69 {
   70     atomic_add_int(&ptr->v, val);
   71 }
   72 
   73 static _opa_inline void OPA_incr_int(OPA_int_t *ptr)
   74 {
   75     atomic_inc_uint(&ptr->v);
   76 }
   77 
   78 static _opa_inline void OPA_decr_int(OPA_int_t *ptr)
   79 {
   80     atomic_dec_uint(&ptr->v);
   81 }
   82 
   83 
   84 static _opa_inline int OPA_decr_and_test_int(OPA_int_t *ptr)
   85 {
   86     return atomic_dec_uint_nv(&ptr->v) == 0;    
   87 }
   88 
   89 
   90 static _opa_inline int OPA_fetch_and_add_int(OPA_int_t *ptr, int val)
   91 {
   92     return (int)atomic_add_int_nv(&ptr->v, val) - val;
   93 }
   94 
   95 static _opa_inline int OPA_fetch_and_decr_int(OPA_int_t *ptr)
   96 {
   97     return (int)atomic_dec_uint_nv(&ptr->v) + 1;
   98 }
   99 
  100 static _opa_inline int OPA_fetch_and_incr_int(OPA_int_t *ptr)
  101 {
  102     return (int)atomic_inc_uint_nv(&ptr->v) - 1;
  103 }
  104 
  105 
  106 static _opa_inline void *OPA_cas_ptr(OPA_ptr_t *ptr, void *oldv, void *newv)
  107 {
  108     return atomic_cas_ptr(ptr, oldv, newv);
  109 }
  110 
  111 static _opa_inline int OPA_cas_int(OPA_int_t *ptr, int oldv, int newv)
  112 {
  113     return (int)atomic_cas_uint(&ptr->v, (uint_t)oldv, (uint_t)newv);
  114 }
  115 
  116 
  117 static _opa_inline void *OPA_swap_ptr(OPA_ptr_t *ptr, void *val)
  118 {
  119     return atomic_swap_ptr(ptr, val);
  120 }
  121 
  122 static _opa_inline int OPA_swap_int(OPA_int_t *ptr, int val)
  123 {
  124     return (int)atomic_swap_uint(&ptr->v, (uint_t) val);
  125 }
  126 
  127 
  128 #define OPA_write_barrier()      membar_producer()
  129 #define OPA_read_barrier()       membar_consumer()
  130 #define OPA_read_write_barrier() do { membar_consumer(); membar_producer(); } while (0)
  131 
  132 /* is this portable enough? */
  133 #define OPA_compiler_barrier()   __asm__ __volatile__  ( ""  ::: "memory" )
  134 
  135 #endif /* OPA_SUN_ATOMIC_OPS_H_INCLUDED */