match.pd: Fix fneg/fadd optimization [PR109583]
[platform/upstream/gcc.git] / libitm / method-gl.cc
index 4b6769b..882715d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2023 Free Software Foundation, Inc.
    Contributed by Torvald Riegel <triegel@redhat.com>.
 
    This file is part of the GNU Transactional Memory Library (libitm).
@@ -291,12 +291,18 @@ public:
         // See begin_or_restart() for why we need release memory order here.
        v = gl_mg::clear_locked(v) + 1;
        o_gl_mg.orec.store(v, memory_order_release);
-
-       // Need to ensure privatization safety. Every other transaction must
-       // have a snapshot time that is at least as high as our commit time
-       // (i.e., our commit must be visible to them).
-       priv_time = v;
       }
+
+    // Need to ensure privatization safety. Every other transaction must have
+    // a snapshot time that is at least as high as our commit time (i.e., our
+    // commit must be visible to them).  Because of proxy privatization, we
+    // must ensure that even if we are a read-only transaction.  See
+    // ml_wt_dispatch::trycommit() for details: We can't get quite the same
+    // set of problems because we just use one orec and thus, for example,
+    // there cannot be concurrent writers -- but we can still get pending
+    // loads to privatized data when not ensuring privatization safety, which
+    // is problematic if the program unmaps the privatized memory.
+    priv_time = v;
     return true;
   }
 
@@ -338,10 +344,19 @@ public:
 
   }
 
+  virtual bool snapshot_most_recent()
+  {
+    // This is the same check as in validate() except that we do not restart
+    // on failure but simply return the result.
+    return o_gl_mg.orec.load(memory_order_relaxed)
+       == gtm_thr()->shared_state.load(memory_order_relaxed);
+  }
+
+
   CREATE_DISPATCH_METHODS(virtual, )
   CREATE_DISPATCH_METHODS_MEM()
 
-  gl_wt_dispatch() : abi_dispatch(false, true, false, false, &o_gl_mg)
+  gl_wt_dispatch() : abi_dispatch(false, true, false, false, 0, &o_gl_mg)
   { }
 };