[pypy-commit] pypy stmgc-c7: Use a regular lock as the fall-back "atomic" object here, as it also

arigo noreply at buildbot.pypy.org
Fri Jul 4 10:04:53 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r72352:617dab8c0da1
Date: 2014-07-04 10:04 +0200
http://bitbucket.org/pypy/pypy/changeset/617dab8c0da1/

Log:	Use a regular lock as the fall-back "atomic" object here, as it also
	supports "with" directly.

diff --git a/lib_pypy/transaction.py b/lib_pypy/transaction.py
--- a/lib_pypy/transaction.py
+++ b/lib_pypy/transaction.py
@@ -17,17 +17,11 @@
 try:
     from __pypy__.thread import atomic
 except ImportError:
-    # Not a STM-enabled PyPy.  We can still provide a version of 'atomic'
-    # that is good enough for our purposes.  With this limited version,
+    # Not a STM-enabled PyPy.  We can use a regular lock for 'atomic',
+    # which is good enough for our purposes.  With this limited version,
     # an atomic block in thread X will not prevent running thread Y, if
     # thread Y is not within an atomic block at all.
-    _atomic_global_lock = thread.allocate_lock()
-    class _Atomic(object):
-        def __enter__(self):
-            _atomic_global_lock.acquire()
-        def __exit__(self, *args):
-            _atomic_global_lock.release()
-    atomic = _Atomic()
+    atomic = thread.allocate_lock()
 
 try:
     from __pypy__.thread import signals_enabled


More information about the pypy-commit mailing list