< prev index next >

src/hotspot/share/runtime/atomic.hpp

Print this page




  87 
  88   template <typename D, typename T>
  89   inline static void release_store_fence(volatile D* dest, T store_value);
  90 
  91   // Atomically load from a location
  92   // The type T must be either a pointer type, an integral/enum type,
  93   // or a type that is primitive convertible using PrimitiveConversions.
  94   template<typename T>
  95   inline static T load(const volatile T* dest);
  96 
  97   template <typename T>
  98   inline static T load_acquire(const volatile T* dest);
  99 
 100   // Atomically add to a location. Returns updated value. add*() provide:
 101   // <fence> add-value-to-dest <membar StoreLoad|StoreStore>
 102 
 103   template<typename D, typename I>
 104   inline static D add(D volatile* dest, I add_value,
 105                       atomic_memory_order order = memory_order_conservative);
 106 
 107   template<typename I, typename D>
 108   inline static D sub(I sub_value, D volatile* dest,
 109                       atomic_memory_order order = memory_order_conservative);
 110 
 111   // Atomically increment location. inc() provide:
 112   // <fence> increment-dest <membar StoreLoad|StoreStore>
 113   // The type D may be either a pointer type, or an integral
 114   // type. If it is a pointer type, then the increment is
 115   // scaled to the size of the type pointed to by the pointer.
 116   template<typename D>
 117   inline static void inc(D volatile* dest,
 118                          atomic_memory_order order = memory_order_conservative);
 119 
 120   // Atomically decrement a location. dec() provide:
 121   // <fence> decrement-dest <membar StoreLoad|StoreStore>
 122   // The type D may be either a pointer type, or an integral
 123   // type. If it is a pointer type, then the decrement is
 124   // scaled to the size of the type pointed to by the pointer.
 125   template<typename D>
 126   inline static void dec(D volatile* dest,
 127                          atomic_memory_order order = memory_order_conservative);
 128 


 526   template<typename D, typename I>
 527   D operator()(D volatile* dest, I add_value, atomic_memory_order order) const;
 528 };
 529 
 530 template<typename D>
 531 inline void Atomic::inc(D volatile* dest, atomic_memory_order order) {
 532   STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
 533   typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I;
 534   Atomic::add(dest, I(1), order);
 535 }
 536 
 537 template<typename D>
 538 inline void Atomic::dec(D volatile* dest, atomic_memory_order order) {
 539   STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
 540   typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I;
 541   // Assumes two's complement integer representation.
 542   #pragma warning(suppress: 4146)
 543   Atomic::add(dest, I(-1), order);
 544 }
 545 
 546 template<typename I, typename D>
 547 inline D Atomic::sub(I sub_value, D volatile* dest, atomic_memory_order order) {
 548   STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
 549   STATIC_ASSERT(IsIntegral<I>::value);
 550   // If D is a pointer type, use [u]intptr_t as the addend type,
 551   // matching signedness of I.  Otherwise, use D as the addend type.
 552   typedef typename Conditional<IsSigned<I>::value, intptr_t, uintptr_t>::type PI;
 553   typedef typename Conditional<IsPointer<D>::value, PI, D>::type AddendType;
 554   // Only allow conversions that can't change the value.
 555   STATIC_ASSERT(IsSigned<I>::value == IsSigned<AddendType>::value);
 556   STATIC_ASSERT(sizeof(I) <= sizeof(AddendType));
 557   AddendType addend = sub_value;
 558   // Assumes two's complement integer representation.
 559   #pragma warning(suppress: 4146) // In case AddendType is not signed.
 560   return Atomic::add(dest, -addend, order);
 561 }
 562 
 563 // Define the class before including platform file, which may specialize
 564 // the operator definition.  No generic definition of specializations
 565 // of the operator template are provided, nor are there any generic
 566 // specializations of the class.  The platform file is responsible for
 567 // providing those.




  87 
  88   template <typename D, typename T>
  89   inline static void release_store_fence(volatile D* dest, T store_value);
  90 
  91   // Atomically load from a location
  92   // The type T must be either a pointer type, an integral/enum type,
  93   // or a type that is primitive convertible using PrimitiveConversions.
  94   template<typename T>
  95   inline static T load(const volatile T* dest);
  96 
  97   template <typename T>
  98   inline static T load_acquire(const volatile T* dest);
  99 
 100   // Atomically add to a location. Returns updated value. add*() provide:
 101   // <fence> add-value-to-dest <membar StoreLoad|StoreStore>
 102 
 103   template<typename D, typename I>
 104   inline static D add(D volatile* dest, I add_value,
 105                       atomic_memory_order order = memory_order_conservative);
 106 
 107   template<typename D, typename I>
 108   inline static D sub(D volatile* dest, I sub_value,
 109                       atomic_memory_order order = memory_order_conservative);
 110 
 111   // Atomically increment location. inc() provide:
 112   // <fence> increment-dest <membar StoreLoad|StoreStore>
 113   // The type D may be either a pointer type, or an integral
 114   // type. If it is a pointer type, then the increment is
 115   // scaled to the size of the type pointed to by the pointer.
 116   template<typename D>
 117   inline static void inc(D volatile* dest,
 118                          atomic_memory_order order = memory_order_conservative);
 119 
 120   // Atomically decrement a location. dec() provide:
 121   // <fence> decrement-dest <membar StoreLoad|StoreStore>
 122   // The type D may be either a pointer type, or an integral
 123   // type. If it is a pointer type, then the decrement is
 124   // scaled to the size of the type pointed to by the pointer.
 125   template<typename D>
 126   inline static void dec(D volatile* dest,
 127                          atomic_memory_order order = memory_order_conservative);
 128 


 526   template<typename D, typename I>
 527   D operator()(D volatile* dest, I add_value, atomic_memory_order order) const;
 528 };
 529 
 530 template<typename D>
 531 inline void Atomic::inc(D volatile* dest, atomic_memory_order order) {
 532   STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
 533   typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I;
 534   Atomic::add(dest, I(1), order);
 535 }
 536 
 537 template<typename D>
 538 inline void Atomic::dec(D volatile* dest, atomic_memory_order order) {
 539   STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
 540   typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I;
 541   // Assumes two's complement integer representation.
 542   #pragma warning(suppress: 4146)
 543   Atomic::add(dest, I(-1), order);
 544 }
 545 
 546 template<typename D, typename I>
 547 inline D Atomic::sub(D volatile* dest, I sub_value, atomic_memory_order order) {
 548   STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
 549   STATIC_ASSERT(IsIntegral<I>::value);
 550   // If D is a pointer type, use [u]intptr_t as the addend type,
 551   // matching signedness of I.  Otherwise, use D as the addend type.
 552   typedef typename Conditional<IsSigned<I>::value, intptr_t, uintptr_t>::type PI;
 553   typedef typename Conditional<IsPointer<D>::value, PI, D>::type AddendType;
 554   // Only allow conversions that can't change the value.
 555   STATIC_ASSERT(IsSigned<I>::value == IsSigned<AddendType>::value);
 556   STATIC_ASSERT(sizeof(I) <= sizeof(AddendType));
 557   AddendType addend = sub_value;
 558   // Assumes two's complement integer representation.
 559   #pragma warning(suppress: 4146) // In case AddendType is not signed.
 560   return Atomic::add(dest, -addend, order);
 561 }
 562 
 563 // Define the class before including platform file, which may specialize
 564 // the operator definition.  No generic definition of specializations
 565 // of the operator template are provided, nor are there any generic
 566 // specializations of the class.  The platform file is responsible for
 567 // providing those.


< prev index next >