coarray_43.f90: Add "-latomic" option if libatomic_available.
[gcc.git] / libgcc / emutls.c
index 22ea4403edbd564226d966c3921e2dc049baf81f..ea01f0ef19a5c4fbc4d14f3b8cc067fc9e09830a 100644 (file)
@@ -1,5 +1,5 @@
 /* TLS emulation.
-   Copyright (C) 2006, 2008, 2009, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2006-2017 Free Software Foundation, Inc.
    Contributed by Jakub Jelinek <jakub@redhat.com>.
 
 This file is part of GCC.
@@ -136,7 +136,7 @@ __emutls_get_address (struct __emutls_object *obj)
 #ifndef __GTHREADS
   abort ();
 #else
-  pointer offset = obj->loc.offset;
+  pointer offset = __atomic_load_n (&obj->loc.offset, __ATOMIC_ACQUIRE);
 
   if (__builtin_expect (offset == 0, 0))
     {
@@ -147,7 +147,7 @@ __emutls_get_address (struct __emutls_object *obj)
       if (offset == 0)
        {
          offset = ++emutls_size;
-         obj->loc.offset = offset;
+         __atomic_store_n (&obj->loc.offset, offset, __ATOMIC_RELEASE);
        }
       __gthread_mutex_unlock (&emutls_mutex);
     }