< prev index next >

src/hotspot/os_cpu/solaris_sparc/atomic_solaris_sparc.hpp

Print this page




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef OS_CPU_SOLARIS_SPARC_ATOMIC_SOLARIS_SPARC_HPP
  26 #define OS_CPU_SOLARIS_SPARC_ATOMIC_SOLARIS_SPARC_HPP
  27 
  28 // Implementation of class atomic
  29 
  30 // Implement ADD using a CAS loop.
  31 template<size_t byte_size>
  32 struct Atomic::PlatformAdd {
  33   template<typename I, typename D>
  34   inline D operator()(I add_value, D volatile* dest, atomic_memory_order order) const {
  35     D old_value = *dest;
  36     while (true) {
  37       D new_value = old_value + add_value;
  38       D result = cmpxchg(new_value, dest, old_value);
  39       if (result == old_value) break;
  40       old_value = result;
  41     }
  42     return old_value + add_value;
  43   }
  44 };
  45 
  46 template<>
  47 template<typename T>
  48 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
  49                                              T volatile* dest,
  50                                              atomic_memory_order order) const {
  51   STATIC_ASSERT(4 == sizeof(T));
  52   __asm__ volatile (  "swap [%2],%0"
  53                     : "=r" (exchange_value)
  54                     : "0" (exchange_value), "r" (dest)




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef OS_CPU_SOLARIS_SPARC_ATOMIC_SOLARIS_SPARC_HPP
  26 #define OS_CPU_SOLARIS_SPARC_ATOMIC_SOLARIS_SPARC_HPP
  27 
  28 // Implementation of class atomic
  29 
  30 // Implement ADD using a CAS loop.
  31 template<size_t byte_size>
  32 struct Atomic::PlatformAdd {
  33   template<typename D, typename I>
  34   inline D operator()(D volatile* dest, I add_value, atomic_memory_order order) const {
  35     D old_value = *dest;
  36     while (true) {
  37       D new_value = old_value + add_value;
  38       D result = cmpxchg(new_value, dest, old_value);
  39       if (result == old_value) break;
  40       old_value = result;
  41     }
  42     return old_value + add_value;
  43   }
  44 };
  45 
  46 template<>
  47 template<typename T>
  48 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
  49                                              T volatile* dest,
  50                                              atomic_memory_order order) const {
  51   STATIC_ASSERT(4 == sizeof(T));
  52   __asm__ volatile (  "swap [%2],%0"
  53                     : "=r" (exchange_value)
  54                     : "0" (exchange_value), "r" (dest)


< prev index next >