re PR libfortran/89020 (close(status='DELETE') does not remove file)
[gcc.git] / libgcc / emutls.c
index b7ee3bdfa7cec09b1f43aba5bed1132e71cea4ee..c725142e465366da14322aae2f8257257100251b 100644 (file)
@@ -1,5 +1,5 @@
 /* TLS emulation.
-   Copyright (C) 2006, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2006-2019 Free Software Foundation, Inc.
    Contributed by Jakub Jelinek <jakub@redhat.com>.
 
 This file is part of GCC.
@@ -27,6 +27,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "tsystem.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "libgcc_tm.h"
 #include "gthr.h"
 
 typedef unsigned int word __attribute__((mode(word)));
@@ -135,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))
     {
@@ -146,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);
     }