1. Remi Meier
  2. pypy-stm-logging

Commits

Remi Meier  committed 4841942

stm: add thread.is_atomic

  • Participants
  • Parent commits b0c0a83
  • Branches stm-logging

Comments (0)

Files changed (3)

File pypy/module/thread/__init__.py

View file
  • Ignore whitespace
         '_atomic_enter':          'atomic.atomic_enter',
         '_exclusive_atomic_enter': 'atomic.exclusive_atomic_enter',
         '_atomic_exit':           'atomic.atomic_exit',
+        'is_atomic':              'atomic.is_atomic',
         'at_commit':              'stm.at_commit',
         'run_commit':             'stm.run_commit',
     }

File pypy/module/thread/atomic.py

View file
  • Ignore whitespace
             return
     raise wrap_thread_error(space,
         "atomic.__exit__(): more exits than enters")
+
+def is_atomic(space):
+    if space.config.translation.stm:
+        from pypy.rlib.rstm import is_atomic
+        return space.wrap(is_atomic() > 0)
+    else:
+        return space.wrap(space.threadlocals.is_atomic > 0)

File pypy/module/thread/test/test_atomic.py

View file
  • Ignore whitespace
                     pass
         except thread.error, e:
             assert e.message == "exclusive_atomic block can't be entered inside another atomic block"
+
+    def test_is_atomic(self):
+        import thread
+        with thread.atomic:
+            b = thread.is_atomic()
+        assert b is True
+        assert thread.is_atomic() is False