Commits

Armin Rigo  committed 14c15b3

Fix: missing re-addition into list_of_read_objects...

  • Participants
  • Parent commits bae6349

Comments (0)

Files changed (1)

File hack/stm/python/c2.py

 # This is a modelling version of ../c2/et.c
 #
 
-import random, py
+import random, py, sys
 from amd64model import CPU, System
 
 
                 pass
 
     def tx_spinloop(self, reason):
-        print "cpu %d tx_spinloop: %s" % (self._cpuindex, reason)
+        msg = "cpu %d tx_spinloop: %s" % (self._cpuindex, reason)
+        print msg
+        print >> sys.stderr, msg
 
     def is_odd(self, x):
         if isinstance(x, Object):
                     self.tx_spinloop("waiting for object release "
                                      "in LatestGlobalRevision")
                     continue                   # spin-loop to start of func
-                self.ValidateDuringTransaction()#try to move start_time forward
+                self.ValidateNow()             #try to move start_time forward
                 continue                       # restart searching from R
             break
         self.PossiblyUpdateChain(G, R, R_Container, FieldName)    # see below
     # ----------------------------------------
 
     def AddInReadSet(self, R):
-        if R not in self.list_of_read_objects:
-            if R in self._related_objects:
-                assert not (self._related_objects[R] &
-                            self.list_of_read_objects)
-            self.list_of_read_objects.add(R)
         if random.random() < self._autolocalization:
             L = self.Localize(R)
             return L
-        return R
+        else:
+            if R not in self.list_of_read_objects:
+                if R in self._related_objects:
+                    assert not (self._related_objects[R] &
+                                self.list_of_read_objects)
+                self.list_of_read_objects.add(R)
+            return R
 
     def ReadGlobalToLocal(self, R, R_Container=None, FieldName=None):
         L = self.global_to_local[R]
     # Validation
     # ------------------------------------
 
+    def ValidateNow(self):
+        self.start_time = self.GetGlobalCurTime() # copy from the global time
+        if not self.ValidateDuringTransaction():
+            self.AbortTransaction("ValidateNow")
+
     def ValidateDuringTransaction(self):
-        self.start_time = self.GetGlobalCurTime() # copy from the global time
-        for R in self.list_of_read_objects:
+        for R in self.list_of_read_objects.union(self.global_to_local):
             while True:
                 v = self.h_revision(R)
                 if not self.is_odd(v):     # "is a pointer", i.e.
-                    self.AbortTransaction("ValidateDuringTransaction")
-                                           #   "has a more recent revision"
+                    return False           #   "has a more recent revision"
                 if v >= LOCKED:            # locked
                     self.tx_spinloop("ValidateDuringTransaction: locked obj")
                     continue
                 break
+        return True
 
     def ValidateDuringCommit(self):
         for R in self.list_of_read_objects:
             if v >= LOCKED:            # locked
                 if v != self.my_lock:  # and not by me
                     return False
+        # debugging checks only
+        seen = set(self.list_of_read_objects)
+        for (R, _, _) in self.gcroots:
+            v = self.h_revision(R)
+            assert v == self.my_lock
+            seen.add(R)
+        for R in self.global_to_local:
+            assert R in seen
+        #
         return True
 
     # Local garbage collection
             assert self.h_revision(L) is R
             if not self.h_written(L):
                 self.add_flags(L, GCFLAG_GLOBAL | GCFLAG_POSSIBLY_OUTDATED)
+                self.list_of_read_objects.add(R)
                 continue
             self.gcroots.append([R, L, 0])
 
             cur_time = self.load('global_cur_time')    # try again
         if self.start_time != cur_time:
             self.start_time = cur_time
-            if not self.ValidateDuringCommit():
+            if not self.ValidateDuringTransaction():
                 self.store('global_cur_time', cur_time) #must restore the value
                 self.inevitable_mutex_release()
                 self.AbortTransaction("BecomeInevitable")