17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP 27 #define OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP 28 29 #include "runtime/os.hpp" 30 31 // Implementation of class atomic 32 33 template<size_t byte_size> 34 struct Atomic::PlatformAdd 35 : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> > 36 { 37 template<typename I, typename D> 38 D add_and_fetch(I add_value, D volatile* dest, atomic_memory_order order) const; 39 }; 40 41 template<> 42 template<typename I, typename D> 43 inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest, 44 atomic_memory_order order) const { 45 STATIC_ASSERT(4 == sizeof(I)); 46 STATIC_ASSERT(4 == sizeof(D)); 47 48 return __sync_add_and_fetch(dest, add_value); 49 } 50 51 template<> 52 template<typename I, typename D> 53 inline D Atomic::PlatformAdd<8>::add_and_fetch(I add_value, D volatile* dest, 54 atomic_memory_order order) const { 55 STATIC_ASSERT(8 == sizeof(I)); 56 STATIC_ASSERT(8 == sizeof(D)); 57 return __sync_add_and_fetch(dest, add_value); 58 } 59 60 template<> 61 template<typename T> 62 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value, 63 T volatile* dest, 64 atomic_memory_order order) const { 65 STATIC_ASSERT(4 == sizeof(T)); 66 // __sync_lock_test_and_set is a bizarrely named atomic exchange 67 // operation. Note that some platforms only support this with the 68 // limitation that the only valid value to store is the immediate 69 // constant 1. There is a test for this in JNI_CreateJavaVM(). 70 T result = __sync_lock_test_and_set (dest, exchange_value); 71 // All atomic operations are expected to be full memory barriers 72 // (see atomic.hpp). However, __sync_lock_test_and_set is not 73 // a full memory barrier, but an acquire barrier. Hence, this added | 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP 27 #define OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP 28 29 #include "runtime/os.hpp" 30 31 // Implementation of class atomic 32 33 template<size_t byte_size> 34 struct Atomic::PlatformAdd 35 : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> > 36 { 37 template<typename D, typename I> 38 D add_and_fetch(D volatile* dest, I add_value, atomic_memory_order order) const; 39 }; 40 41 template<> 42 template<typename D, typename I> 43 inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value, 44 atomic_memory_order order) const { 45 STATIC_ASSERT(4 == sizeof(I)); 46 STATIC_ASSERT(4 == sizeof(D)); 47 48 return __sync_add_and_fetch(dest, add_value); 49 } 50 51 template<> 52 template<typename D, typename I> 53 inline D Atomic::PlatformAdd<8>::add_and_fetch(D volatile* dest, I add_value, 54 atomic_memory_order order) const { 55 STATIC_ASSERT(8 == sizeof(I)); 56 STATIC_ASSERT(8 == sizeof(D)); 57 return __sync_add_and_fetch(dest, add_value); 58 } 59 60 template<> 61 template<typename T> 62 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value, 63 T volatile* dest, 64 atomic_memory_order order) const { 65 STATIC_ASSERT(4 == sizeof(T)); 66 // __sync_lock_test_and_set is a bizarrely named atomic exchange 67 // operation. Note that some platforms only support this with the 68 // limitation that the only valid value to store is the immediate 69 // constant 1. There is a test for this in JNI_CreateJavaVM(). 70 T result = __sync_lock_test_and_set (dest, exchange_value); 71 // All atomic operations are expected to be full memory barriers 72 // (see atomic.hpp). However, __sync_lock_test_and_set is not 73 // a full memory barrier, but an acquire barrier. Hence, this added |