[pypy-commit] extradoc extradoc: Kill ValidateForInevitable(). Using ValidateDuringCommit(),
arigo
noreply at buildbot.pypy.org
Sun Aug 26 11:16:01 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: extradoc
Changeset: r4727:23d5fdc930bc
Date: 2012-08-26 11:15 +0200
http://bitbucket.org/pypy/extradoc/changeset/23d5fdc930bc/
Log: Kill ValidateForInevitable(). Using ValidateDuringCommit(), which
has the correct behavior of detecting locks.
diff --git a/talk/stm2012/stmimpl.rst b/talk/stm2012/stmimpl.rst
--- a/talk/stm2012/stmimpl.rst
+++ b/talk/stm2012/stmimpl.rst
@@ -406,16 +406,18 @@
The last detection for inconsistency is during commit, when
``ValidateDuringCommit`` is called. It is a slightly more complex
version than ``ValidateDuringTransaction`` because it has to handle
-"locks" correctly::
+"locks" correctly. It also returns a True/False result instead of
+aborting::
def ValidateDuringCommit():
for R in list_of_read_objects:
v = R->h_revision
if not (v & 1): # "is a pointer", i.e.
- AbortTransaction() # "has a more recent revision"
+ return False # "has a more recent revision"
if v >= LOCKED: # locked
if v != my_lock: # and not by me
- AbortTransaction()
+ return False
+ return True
Local garbage collection
@@ -508,7 +510,8 @@
while not CMPXCHG(&global_cur_time, cur_time, cur_time + 2):
cur_time = global_cur_time # try again
if cur_time != start_time:
- ValidateDuringCommit() # only call it if needed
+ if not ValidateDuringCommit(): # only call it if needed
+ AbortTransaction() # last abort point
UpdateChainHeads(cur_time)
Note the general style of usage of CMPXCHG: we first read normally the
@@ -633,16 +636,12 @@
while not CMPXCHG(&global_cur_time, cur_time, INEVITABLE):
cur_time = global_cur_time # try again
if start_time != cur_time:
- ValidateForInevitable(cur_time)
- is_inevitable = True
-
- def ValidateForInevitable(t):
- start_time = t
- for R in list_of_read_objects:
- if not (R->h_revision & 1):
+ start_time = cur_time
+ if not ValidateDuringCommit():
global_cur_time = t # must restore the value
inevitable_mutex.release()
AbortTransaction()
+ is_inevitable = True
We use a normal OS mutex to allow other threads to really sleep instead
of spin-looping until the inevitable transaction finishes. So the
More information about the pypy-commit
mailing list