Commits

Armin Rigo committed 43ffd21

Move thread.atomic to __pypy__.thread.atomic.

Comments (0)

Files changed (8)

pypy/module/__pypy__/__init__.py

 class ThreadModule(MixedModule):
     appleveldefs = {
         'signals_enabled': 'app_signal.signals_enabled',
+        'atomic':                  'app_atomic.atomic',
+        'exclusive_atomic':        'app_atomic.exclusive_atomic',
+        'error':                   'app_atomic.error',
     }
     interpleveldefs = {
         '_signals_enter':  'interp_signal.signals_enter',
         '_signals_exit':   'interp_signal.signals_exit',
+        '_atomic_enter':           'interp_atomic.atomic_enter',
+        '_exclusive_atomic_enter': 'interp_atomic.exclusive_atomic_enter',
+        '_atomic_exit':            'interp_atomic.atomic_exit',
     }
 
 

pypy/module/__pypy__/app_atomic.py

+from thread import error     # re-exported
+from __pypy__ import thread
+
+class Atomic(object):
+    __enter__ = thread._atomic_enter
+    __exit__  = thread._atomic_exit
+
+class ExclusiveAtomic(object):
+    __enter__ = thread._exclusive_atomic_enter
+    __exit__ = thread._atomic_exit
+
+atomic = Atomic()
+exclusive_atomic = ExclusiveAtomic()

pypy/module/__pypy__/interp_atomic.py

+from pypy.interpreter.error import OperationError
+from pypy.module.thread.error import wrap_thread_error
+
+
+
+def exclusive_atomic_enter(space):
+    if space.config.translation.stm:
+        from rpython.rlib.rstm import is_atomic
+        count = is_atomic()
+    else:
+        giltl = space.threadlocals
+        count = giltl.is_atomic
+    if count:
+        raise wrap_thread_error(space,
+            "exclusive_atomic block can't be entered inside another atomic block")
+
+    atomic_enter(space)
+
+def atomic_enter(space):
+    if space.config.translation.stm:
+        from rpython.rlib.rstm import increment_atomic
+        increment_atomic()
+    else:
+        giltl = space.threadlocals
+        giltl.is_atomic += 1
+        space.threadlocals.set_gil_releasing_calls()
+
+def atomic_exit(space, w_ignored1=None, w_ignored2=None, w_ignored3=None):
+    if space.config.translation.stm:
+        from rpython.rlib.rstm import decrement_atomic, is_atomic
+        if is_atomic():
+            decrement_atomic()
+            return
+    else:
+        giltl = space.threadlocals
+        if giltl.is_atomic > 0:
+            giltl.is_atomic -= 1
+            space.threadlocals.set_gil_releasing_calls()
+            return
+    raise wrap_thread_error(space,
+        "atomic.__exit__(): more exits than enters")

pypy/module/__pypy__/test/test_atomic.py

+from __future__ import with_statement
+from pypy.module.thread.test.support import GenericTestThread
+
+
+class AppTestAtomic(GenericTestThread):
+
+    def test_simple(self):
+        from __pypy__ import thread
+        for atomic in thread.atomic, thread.exclusive_atomic:
+            with atomic:
+                pass
+            try:
+                with atomic:
+                    raise ValueError
+            except ValueError:
+                pass
+
+    def test_nest_composable_atomic(self):
+        from __pypy__ import thread
+        with thread.atomic:
+            with thread.atomic:
+                pass
+
+    def test_nest_composable_below_exclusive(self):
+        from __pypy__ import thread
+        with thread.exclusive_atomic:
+            with thread.atomic:
+                with thread.atomic:
+                    pass
+
+    def test_nest_exclusive_fails(self):
+        from __pypy__ import thread
+        try:
+            with thread.exclusive_atomic:
+                with thread.exclusive_atomic:
+                    pass
+        except thread.error, e:
+            assert e.message == "exclusive_atomic block can't be entered inside another atomic block"
+
+    def test_nest_exclusive_fails2(self):
+        from __pypy__ import thread
+        try:
+            with thread.atomic:
+                with thread.exclusive_atomic:
+                    pass
+        except thread.error, e:
+            assert e.message == "exclusive_atomic block can't be entered inside another atomic block"

pypy/module/thread/__init__.py

 
 class Module(MixedModule):
     appleveldefs = {
-        'atomic':                 'app_atomic.atomic',
-        'exclusive_atomic':       'app_atomic.exclusive_atomic',
     }
 
     interpleveldefs = {
         'LockType':               'os_lock.Lock',
         '_local':                 'os_local.Local',
         'error':                  'space.fromcache(error.Cache).w_error',
-        '_atomic_enter':          'atomic.atomic_enter',
-        '_exclusive_atomic_enter': 'atomic.exclusive_atomic_enter',
-        '_atomic_exit':           'atomic.atomic_exit',
     }
 
     def __init__(self, space, *args):

pypy/module/thread/app_atomic.py

-import thread
-
-class Atomic(object):
-    __enter__ = thread._atomic_enter
-    __exit__  = thread._atomic_exit
-
-class ExclusiveAtomic(object):
-    __enter__ = thread._exclusive_atomic_enter
-    __exit__ = thread._atomic_exit
-
-atomic = Atomic()
-exclusive_atomic = ExclusiveAtomic()

pypy/module/thread/atomic.py

-from pypy.interpreter.error import OperationError
-from pypy.module.thread.error import wrap_thread_error
-
-
-
-def exclusive_atomic_enter(space):
-    if space.config.translation.stm:
-        from rpython.rlib.rstm import is_atomic
-        count = is_atomic()
-    else:
-        giltl = space.threadlocals
-        count = giltl.is_atomic
-    if count:
-        raise wrap_thread_error(space,
-            "exclusive_atomic block can't be entered inside another atomic block")
-
-    atomic_enter(space)
-
-def atomic_enter(space):
-    if space.config.translation.stm:
-        from rpython.rlib.rstm import increment_atomic
-        increment_atomic()
-    else:
-        giltl = space.threadlocals
-        giltl.is_atomic += 1
-        space.threadlocals.set_gil_releasing_calls()
-
-def atomic_exit(space, w_ignored1=None, w_ignored2=None, w_ignored3=None):
-    if space.config.translation.stm:
-        from rpython.rlib.rstm import decrement_atomic, is_atomic
-        if is_atomic():
-            decrement_atomic()
-            return
-    else:
-        giltl = space.threadlocals
-        if giltl.is_atomic > 0:
-            giltl.is_atomic -= 1
-            space.threadlocals.set_gil_releasing_calls()
-            return
-    raise wrap_thread_error(space,
-        "atomic.__exit__(): more exits than enters")

pypy/module/thread/test/test_atomic.py

-from __future__ import with_statement
-from pypy.module.thread.test.support import GenericTestThread
-
-
-class AppTestAtomic(GenericTestThread):
-
-    def test_simple(self):
-        import thread
-        for atomic in thread.atomic, thread.exclusive_atomic:
-            with atomic:
-                pass
-            try:
-                with atomic:
-                    raise ValueError
-            except ValueError:
-                pass
-
-    def test_nest_composable_atomic(self):
-        import thread
-        with thread.atomic:
-            with thread.atomic:
-                pass
-
-    def test_nest_composable_below_exclusive(self):
-        import thread
-        with thread.exclusive_atomic:
-            with thread.atomic:
-                with thread.atomic:
-                    pass
-
-    def test_nest_exclusive_fails(self):
-        import thread
-        try:
-            with thread.exclusive_atomic:
-                with thread.exclusive_atomic:
-                    pass
-        except thread.error, e:
-            assert e.message == "exclusive_atomic block can't be entered inside another atomic block"
-
-    def test_nest_exclusive_fails2(self):
-        import thread
-        try:
-            with thread.atomic:
-                with thread.exclusive_atomic:
-                    pass
-        except thread.error, e:
-            assert e.message == "exclusive_atomic block can't be entered inside another atomic block"