Commits

Armin Rigo committed 9df339c

Update to match the latest version of stmimpl.rst.

  • Participants
  • Parent commits c02ecbf

Comments (0)

Files changed (1)

File hack/stm/python/c2.py

 
     def ValidateNow(self):
         self.start_time = self.GetGlobalCurTime() # copy from the global time
-        if not self.ValidateDuringTransaction():
+        if not self.ValidateDuringTransaction(False):
             self.AbortTransaction("ValidateNow")
 
-    def ValidateDuringTransaction(self):
+    def ValidateDuringTransaction(self, during_commit):
         for R in self.list_of_read_objects:
             while True:
                 v = self.h_revision(R)
                 if not self.is_odd(v):     # "is a pointer", i.e.
                     return False           #   "has a more recent revision"
                 if v >= LOCKED:            # locked
-                    self.tx_spinloop("ValidateDuringTransaction: locked obj")
-                    continue
+                    if not during_commit:
+                        assert v != self.my_lock   # we don't hold any lock
+                        self.tx_spinloop(
+                            "ValidateDuringTransaction: locked obj")
+                        continue
+                    else:
+                        if v != self.my_lock:   # not locked by me: conflict
+                            return False
                 break
         return True
 
-    def ValidateDuringCommit(self):
-        for R in self.list_of_read_objects:
-            v = self.h_revision(R)
-            if not self.is_odd(v):     # "is a pointer", i.e.
-                return False           #   "has a more recent revision"
-            if v >= LOCKED:            # locked
-                if v != self.my_lock:  # and not by me
-                    return False
-        # debugging checks only
-        seen = self.list_of_read_objects
-        for (R, _, _) in self.gcroots:
-            v = self.h_revision(R)
-            assert v == self.my_lock
-            assert R in seen
-        for R in self.global_to_local:
-            assert R in seen
-        #
-        return True
-
     # Local garbage collection
     # ------------------------------------
 
             while not self.cmpxchg('global_cur_time', cur_time, cur_time + 2):
                 cur_time = self.GetGlobalCurTimeInCommit()    # try again
             if cur_time != self.start_time:
-                if not self.ValidateDuringCommit(): #only call it if needed
+                if not self.ValidateDuringTransaction(True): # only if needed
                     self.AbortTransaction("CommitTransaction") # last abort pt
         self.UpdateChainHeads(cur_time)
         self.last_commit_time = cur_time
             cur_time = self.load('global_cur_time')    # try again
         if self.start_time != cur_time:
             self.start_time = cur_time
-            if not self.ValidateDuringTransaction():
+            if not self.ValidateDuringTransaction(False):
                 self.store('global_cur_time', cur_time) #must restore the value
                 self.inevitable_mutex_release()
                 self.AbortTransaction("BecomeInevitable")