[pypy-commit] pypy stmgc-c7: Attempt to regroup the stm functions in a single built-in module
arigo
noreply at buildbot.pypy.org
Fri Jan 30 10:34:26 CET 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r75584:708ba48c7890
Date: 2015-01-30 10:33 +0100
http://bitbucket.org/pypy/pypy/changeset/708ba48c7890/
Log: Attempt to regroup the stm functions in a single built-in module
called 'pypystm'. Also kill 'lib_pypy/atomic.py'.
diff --git a/lib_pypy/atomic.py b/lib_pypy/atomic.py
deleted file mode 100644
--- a/lib_pypy/atomic.py
+++ /dev/null
@@ -1,24 +0,0 @@
-"""
-API for accessing the multithreading extensions of PyPy
-"""
-import thread
-
-try:
- from __pypy__ import thread as _thread
- from __pypy__.thread import (atomic, getsegmentlimit,
- hint_commit_soon, is_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,
- # an atomic block in thread X will not prevent running thread Y, if
- # thread Y is not within an atomic block at all.
- atomic = thread.allocate_lock()
-
- def getsegmentlimit():
- return 1
-
- def hint_commit_soon():
- pass
-
- def is_atomic():
- return atomic.locked()
diff --git a/lib_pypy/transaction.py b/lib_pypy/transaction.py
--- a/lib_pypy/transaction.py
+++ b/lib_pypy/transaction.py
@@ -15,7 +15,7 @@
import sys, thread, collections, cStringIO, linecache
try:
- from __pypy__.thread import atomic, is_atomic
+ from pypystm import atomic, is_atomic
except ImportError:
# Not a STM-enabled PyPy. We can use a regular lock for 'atomic',
# which is good enough for our purposes. With this limited version,
@@ -37,7 +37,7 @@
signals_enabled = _SignalsEnabled()
try:
- from __pypy__.thread import hint_commit_soon
+ from pypystm import hint_commit_soon
except ImportError:
# Not a STM-enabled PyPy.
def hint_commit_soon():
@@ -102,7 +102,7 @@
def __init__(self):
try:
- from __pypy__.thread import getsegmentlimit
+ from pypystm import getsegmentlimit
self.num_threads = getsegmentlimit()
except ImportError:
self.num_threads = 4
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -226,9 +226,10 @@
# expose the following variables to ease debugging
global space, entry_point
- if config.translation.stm:
+ if config.translation.stm or config.objspace.usemodules.pypystm:
+ config.translation.stm = True
config.translation.thread = True
- config.objspace.usemodules._stm = True
+ config.objspace.usemodules.pypystm = True
if config.objspace.allworkingmodules:
from pypy.config.pypyoption import enable_allworkingmodules
diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -34,7 +34,7 @@
self.w_profilefuncarg = None
#
if self.space.config.translation.stm:
- from pypy.module._stm.ec import initialize_execution_context
+ from pypy.module.pypystm.ec import initialize_execution_context
initialize_execution_context(self)
self.thread_disappeared = False # might be set to True after os.fork()
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -29,22 +29,11 @@
class ThreadModule(MixedModule):
appleveldefs = {
'signals_enabled': 'app_signal.signals_enabled',
- 'atomic': 'app_atomic.atomic',
- 'exclusive_atomic': 'app_atomic.exclusive_atomic',
}
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',
- 'getsegmentlimit': 'interp_atomic.getsegmentlimit',
- 'hint_commit_soon': 'interp_atomic.hint_commit_soon',
- 'is_atomic': 'interp_atomic.is_atomic',
- 'error': 'space.fromcache(pypy.module.thread.error.Cache).w_error',
}
- def activate(self, space):
- return self.space.config.objspace.usemodules.thread
class IntOpModule(MixedModule):
diff --git a/pypy/module/_stm/__init__.py b/pypy/module/pypystm/__init__.py
rename from pypy/module/_stm/__init__.py
rename to pypy/module/pypystm/__init__.py
--- a/pypy/module/_stm/__init__.py
+++ b/pypy/module/pypystm/__init__.py
@@ -4,9 +4,19 @@
class Module(MixedModule):
appleveldefs = {
+ 'atomic': 'app_atomic.atomic',
+ 'exclusive_atomic': 'app_atomic.exclusive_atomic',
}
interpleveldefs = {
+ '_atomic_enter': 'interp_atomic.atomic_enter',
+ '_exclusive_atomic_enter': 'interp_atomic.exclusive_atomic_enter',
+ '_atomic_exit': 'interp_atomic.atomic_exit',
+ 'getsegmentlimit': 'interp_atomic.getsegmentlimit',
+ 'hint_commit_soon': 'interp_atomic.hint_commit_soon',
+ 'is_atomic': 'interp_atomic.is_atomic',
+ 'error': 'space.fromcache(pypy.module.thread.error.Cache).w_error',
+
'local': 'local.STMLocal',
'count': 'count.count',
'hashtable': 'hashtable.W_Hashtable',
diff --git a/pypy/module/__pypy__/app_atomic.py b/pypy/module/pypystm/app_atomic.py
rename from pypy/module/__pypy__/app_atomic.py
rename to pypy/module/pypystm/app_atomic.py
--- a/pypy/module/__pypy__/app_atomic.py
+++ b/pypy/module/pypystm/app_atomic.py
@@ -1,12 +1,12 @@
-from __pypy__ import thread
+import pypystm
class Atomic(object):
- __enter__ = thread._atomic_enter
- __exit__ = thread._atomic_exit
+ __enter__ = pypystm._atomic_enter
+ __exit__ = pypystm._atomic_exit
class ExclusiveAtomic(object):
- __enter__ = thread._exclusive_atomic_enter
- __exit__ = thread._atomic_exit
+ __enter__ = pypystm._exclusive_atomic_enter
+ __exit__ = pypystm._atomic_exit
atomic = Atomic()
exclusive_atomic = ExclusiveAtomic()
diff --git a/pypy/module/_stm/count.py b/pypy/module/pypystm/count.py
rename from pypy/module/_stm/count.py
rename to pypy/module/pypystm/count.py
--- a/pypy/module/_stm/count.py
+++ b/pypy/module/pypystm/count.py
@@ -1,5 +1,5 @@
"""
-_stm.count()
+pypystm.count()
"""
from rpython.rlib import rstm
diff --git a/pypy/module/_stm/ec.py b/pypy/module/pypystm/ec.py
rename from pypy/module/_stm/ec.py
rename to pypy/module/pypystm/ec.py
--- a/pypy/module/_stm/ec.py
+++ b/pypy/module/pypystm/ec.py
@@ -20,7 +20,7 @@
"""Called from ExecutionContext.__init__()."""
if ec.space.config.translation.rweakref:
from rpython.rlib import rweakref
- from pypy.module._stm.local import STMLocal
+ from pypy.module.pypystm.local import STMLocal
ec._thread_local_dicts = rweakref.RWeakKeyDictionary(STMLocal, W_Root)
else:
ec._thread_local_dicts = FakeWeakKeyDictionary()
diff --git a/pypy/module/_stm/hashtable.py b/pypy/module/pypystm/hashtable.py
rename from pypy/module/_stm/hashtable.py
rename to pypy/module/pypystm/hashtable.py
--- a/pypy/module/_stm/hashtable.py
+++ b/pypy/module/pypystm/hashtable.py
@@ -1,5 +1,5 @@
"""
-The class _stm.hashtable, mapping integers to objects.
+The class pypystm.hashtable, mapping integers to objects.
"""
from pypy.interpreter.baseobjspace import W_Root
@@ -63,7 +63,7 @@
return space.wrap(r)
W_Hashtable.typedef = TypeDef(
- '_stm.hashtable',
+ 'pypystm.hashtable',
__new__ = interp2app(W_Hashtable___new__),
__getitem__ = interp2app(W_Hashtable.getitem_w),
__setitem__ = interp2app(W_Hashtable.setitem_w),
diff --git a/pypy/module/__pypy__/interp_atomic.py b/pypy/module/pypystm/interp_atomic.py
rename from pypy/module/__pypy__/interp_atomic.py
rename to pypy/module/pypystm/interp_atomic.py
diff --git a/pypy/module/_stm/local.py b/pypy/module/pypystm/local.py
rename from pypy/module/_stm/local.py
rename to pypy/module/pypystm/local.py
--- a/pypy/module/_stm/local.py
+++ b/pypy/module/pypystm/local.py
@@ -1,5 +1,5 @@
"""
-The '_stm.local' class, used for 'thread._local' with STM.
+The 'pypystm.local' class, used for 'thread._local' with STM.
"""
from pypy.interpreter.gateway import W_Root, interp2app
@@ -10,7 +10,7 @@
def _fill_untranslated(ec):
if not we_are_translated() and not hasattr(ec, '_thread_local_dicts'):
- from pypy.module._stm.ec import initialize_execution_context
+ from pypy.module.pypystm.ec import initialize_execution_context
initialize_execution_context(ec)
@@ -67,7 +67,7 @@
# No arguments allowed
pass
-STMLocal.typedef = TypeDef("_stm.local",
+STMLocal.typedef = TypeDef("pypystm.local",
__doc__ = "Thread-local data",
__new__ = interp2app(STMLocal.descr_local__new__.im_func),
__init__ = interp2app(STMLocal.descr_local__init__),
diff --git a/pypy/module/_stm/test/__init__.py b/pypy/module/pypystm/test/__init__.py
rename from pypy/module/_stm/test/__init__.py
rename to pypy/module/pypystm/test/__init__.py
diff --git a/pypy/module/__pypy__/test/test_atomic.py b/pypy/module/pypystm/test/test_atomic.py
rename from pypy/module/__pypy__/test/test_atomic.py
rename to pypy/module/pypystm/test/test_atomic.py
--- a/pypy/module/__pypy__/test/test_atomic.py
+++ b/pypy/module/pypystm/test/test_atomic.py
@@ -1,15 +1,13 @@
-from __future__ import with_statement
-from pypy.module.thread.test.support import GenericTestThread
-from rpython.rtyper.lltypesystem import rffi
-class AppTestAtomic(GenericTestThread):
+class AppTestAtomic:
+ spaceconfig = dict(usemodules=['pypystm', 'thread'])
def test_simple(self):
- from __pypy__ import thread
- for atomic in thread.atomic, thread.exclusive_atomic:
+ import pypystm
+ for atomic in pypystm.atomic, pypystm.exclusive_atomic:
with atomic:
- assert thread.is_atomic()
+ assert pypystm.is_atomic()
try:
with atomic:
raise ValueError
@@ -17,40 +15,40 @@
pass
def test_nest_composable_atomic(self):
- from __pypy__ import thread
- with thread.atomic:
- with thread.atomic:
- assert thread.is_atomic()
- assert thread.is_atomic()
- assert not thread.is_atomic()
+ import pypystm
+ with pypystm.atomic:
+ with pypystm.atomic:
+ assert pypystm.is_atomic()
+ assert pypystm.is_atomic()
+ assert not pypystm.is_atomic()
def test_nest_composable_below_exclusive(self):
- from __pypy__ import thread
- with thread.exclusive_atomic:
- with thread.atomic:
- with thread.atomic:
- assert thread.is_atomic()
- assert thread.is_atomic()
- assert thread.is_atomic()
- assert not thread.is_atomic()
+ import pypystm
+ with pypystm.exclusive_atomic:
+ with pypystm.atomic:
+ with pypystm.atomic:
+ assert pypystm.is_atomic()
+ assert pypystm.is_atomic()
+ assert pypystm.is_atomic()
+ assert not pypystm.is_atomic()
def test_nest_exclusive_fails(self):
- from __pypy__ import thread
+ import pypystm
try:
- with thread.exclusive_atomic:
- with thread.exclusive_atomic:
- assert thread.is_atomic()
- except thread.error, e:
- assert not thread.is_atomic()
+ with pypystm.exclusive_atomic:
+ with pypystm.exclusive_atomic:
+ assert pypystm.is_atomic()
+ except pypystm.error, e:
+ assert not pypystm.is_atomic()
assert e.message == "exclusive_atomic block can't be entered inside another atomic block"
def test_nest_exclusive_fails2(self):
- from __pypy__ import thread
+ import pypystm
try:
- with thread.atomic:
- with thread.exclusive_atomic:
- assert thread.is_atomic()
- assert thread.is_atomic()
- except thread.error, e:
- assert not thread.is_atomic()
+ with pypystm.atomic:
+ with pypystm.exclusive_atomic:
+ assert pypystm.is_atomic()
+ assert pypystm.is_atomic()
+ except pypystm.error, e:
+ assert not pypystm.is_atomic()
assert e.message == "exclusive_atomic block can't be entered inside another atomic block"
diff --git a/pypy/module/_stm/test/test_count.py b/pypy/module/pypystm/test/test_count.py
rename from pypy/module/_stm/test/test_count.py
rename to pypy/module/pypystm/test/test_count.py
--- a/pypy/module/_stm/test/test_count.py
+++ b/pypy/module/pypystm/test/test_count.py
@@ -1,10 +1,10 @@
class AppTestCount:
- spaceconfig = dict(usemodules=['_stm'])
+ spaceconfig = dict(usemodules=['pypystm'])
def test_count(self):
- import _stm
- x = _stm.count()
- y = _stm.count()
+ import pypystm
+ x = pypystm.count()
+ y = pypystm.count()
assert y == x + 1
diff --git a/pypy/module/_stm/test/test_hashtable.py b/pypy/module/pypystm/test/test_hashtable.py
rename from pypy/module/_stm/test/test_hashtable.py
rename to pypy/module/pypystm/test/test_hashtable.py
--- a/pypy/module/_stm/test/test_hashtable.py
+++ b/pypy/module/pypystm/test/test_hashtable.py
@@ -1,11 +1,11 @@
class AppTestHashtable:
- spaceconfig = dict(usemodules=['_stm'])
+ spaceconfig = dict(usemodules=['pypystm'])
def test_simple(self):
- import _stm
- h = _stm.hashtable()
+ import pypystm
+ h = pypystm.hashtable()
h[42+65536] = "bar"
raises(KeyError, "h[42]")
h[42] = "foo"
@@ -18,8 +18,8 @@
raises(KeyError, "del h[42]")
def test_get_setdefault(self):
- import _stm
- h = _stm.hashtable()
+ import pypystm
+ h = pypystm.hashtable()
assert h.get(42) is None
assert h.get(-43, None) is None
assert h.get(44, 81) == 81
diff --git a/pypy/module/_stm/test/test_local.py b/pypy/module/pypystm/test/test_local.py
rename from pypy/module/_stm/test/test_local.py
rename to pypy/module/pypystm/test/test_local.py
--- a/pypy/module/_stm/test/test_local.py
+++ b/pypy/module/pypystm/test/test_local.py
@@ -3,11 +3,11 @@
class AppTestSTMLocal(test_local.AppTestLocal):
spaceconfig = test_local.AppTestLocal.spaceconfig.copy()
- spaceconfig['usemodules'] += ('_stm',)
+ spaceconfig['usemodules'] += ('pypystm',)
def setup_class(cls):
test_local.AppTestLocal.setup_class.im_func(cls)
cls.w__local = cls.space.appexec([], """():
- import _stm
- return _stm.local
+ import pypystm
+ return pypystm.local
""")
diff --git a/pypy/module/_stm/test/test_time.py b/pypy/module/pypystm/test/test_time.py
rename from pypy/module/_stm/test/test_time.py
rename to pypy/module/pypystm/test/test_time.py
--- a/pypy/module/_stm/test/test_time.py
+++ b/pypy/module/pypystm/test/test_time.py
@@ -1,13 +1,13 @@
class AppTestHashtable:
- spaceconfig = dict(usemodules=['_stm'])
+ spaceconfig = dict(usemodules=['pypystm'])
def test_simple(self):
- import _stm
- t1 = _stm.time()
- t2 = _stm.time()
+ import pypystm
+ t1 = pypystm.time()
+ t2 = pypystm.time()
assert t1 < t2 < t1 + 1
- t1 = _stm.clock()
- t2 = _stm.clock()
+ t1 = pypystm.clock()
+ t2 = pypystm.clock()
assert t1 < t2 < t1 + 1
diff --git a/pypy/module/_stm/threadlocals.py b/pypy/module/pypystm/threadlocals.py
rename from pypy/module/_stm/threadlocals.py
rename to pypy/module/pypystm/threadlocals.py
diff --git a/pypy/module/_stm/time.py b/pypy/module/pypystm/time.py
rename from pypy/module/_stm/time.py
rename to pypy/module/pypystm/time.py
--- a/pypy/module/_stm/time.py
+++ b/pypy/module/pypystm/time.py
@@ -1,5 +1,5 @@
"""
-_stm.time(), _stm.clock()
+pypystm.time(), pypystm.clock()
"""
from rpython.rtyper.lltypesystem import lltype, rffi
@@ -43,7 +43,7 @@
"""Similar to time.time(), but works without conflict.
The drawback is that the returned times may appear out of order:
this thread's transaction may commit before or after another thread's,
-while _stm.time() called by both may return results in the opposite
+while pypystm.time() called by both may return results in the opposite
order (or even exactly equal results if you are unlucky)."""
return space.wrap(pypy_clock_get_time())
@@ -51,6 +51,6 @@
"""Similar to time.clock(), but works without conflict.
The drawback is that the returned times may appear out of order:
this thread's transaction may commit before or after another thread's,
-while _stm.time() called by both may return results in the opposite
+while pypystm.time() called by both may return results in the opposite
order (or even exactly equal results if you are unlucky)."""
return space.wrap(pypy_clock_get_clock())
diff --git a/pypy/module/thread/stm.py b/pypy/module/thread/stm.py
--- a/pypy/module/thread/stm.py
+++ b/pypy/module/thread/stm.py
@@ -1,8 +1,8 @@
"""
-Redirect some classes from pypy.module._stm.
+Redirect some classes from pypy.module.pypystm.
"""
-from pypy.module._stm import threadlocals, local
+from pypy.module.pypystm import threadlocals, local
STMThreadLocals = threadlocals.STMThreadLocals
STMLocal = local.STMLocal
More information about the pypy-commit
mailing list