[pypy-svn] r23808 - in pypy/branch/njriley-trans/pypy: lib module/trans rpython rpython/module translator/c translator/c/src
njriley at codespeak.net
njriley at codespeak.net
Wed Mar 1 02:08:57 CET 2006
Author: njriley
Date: Wed Mar 1 02:08:56 2006
New Revision: 23808
Modified:
pypy/branch/njriley-trans/pypy/lib/imp.py
pypy/branch/njriley-trans/pypy/module/trans/__init__.py
pypy/branch/njriley-trans/pypy/module/trans/interp_trans.py
pypy/branch/njriley-trans/pypy/module/trans/rtrans.py
pypy/branch/njriley-trans/pypy/rpython/extfunctable.py
pypy/branch/njriley-trans/pypy/rpython/module/ll_trans.py
pypy/branch/njriley-trans/pypy/translator/c/extfunc.py
pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h
Log:
Add trans.is_active, wrapping magic instruction to query if we are in
a transaction.
Modified: pypy/branch/njriley-trans/pypy/lib/imp.py
==============================================================================
--- pypy/branch/njriley-trans/pypy/lib/imp.py (original)
+++ pypy/branch/njriley-trans/pypy/lib/imp.py Wed Mar 1 02:08:56 2006
@@ -160,6 +160,7 @@
else:
del _please_provide_import_lock
import thread
+ import trans
class _ImportLock:
def __init__(self):
@@ -169,6 +170,8 @@
def held(self):
"""Return True if the import lock is currently held, else False."""
+ if trans.is_active():
+ return True
return self.in_thread is not None
def acquire(self):
@@ -176,6 +179,8 @@
This lock should be used by import hooks to ensure thread-safety
when importing modules.
"""
+ if trans.is_active():
+ return
myident = thread.get_ident()
if self.in_thread == myident:
self.recursions += 1
@@ -186,6 +191,8 @@
def release(self):
"""Release the interpreter's import lock."""
+ if trans.is_active():
+ return
myident = thread.get_ident()
if self.in_thread != myident:
raise RuntimeError("not holding the import lock")
Modified: pypy/branch/njriley-trans/pypy/module/trans/__init__.py
==============================================================================
--- pypy/branch/njriley-trans/pypy/module/trans/__init__.py (original)
+++ pypy/branch/njriley-trans/pypy/module/trans/__init__.py Wed Mar 1 02:08:56 2006
@@ -7,10 +7,11 @@
}
interpleveldefs = {
- 'begin' : 'interp_trans.begin',
- 'end' : 'interp_trans.end',
- 'abort' : 'interp_trans.abort',
- 'pause' : 'interp_trans.pause',
- 'unpause' : 'interp_trans.unpause',
- 'verbose' : 'interp_trans.verbose',
+ 'begin' : 'interp_trans.begin',
+ 'end' : 'interp_trans.end',
+ 'abort' : 'interp_trans.abort',
+ 'pause' : 'interp_trans.pause',
+ 'unpause' : 'interp_trans.unpause',
+ 'verbose' : 'interp_trans.verbose',
+ 'is_active' : 'interp_trans.is_active',
}
Modified: pypy/branch/njriley-trans/pypy/module/trans/interp_trans.py
==============================================================================
--- pypy/branch/njriley-trans/pypy/module/trans/interp_trans.py (original)
+++ pypy/branch/njriley-trans/pypy/module/trans/interp_trans.py Wed Mar 1 02:08:56 2006
@@ -25,3 +25,6 @@
def verbose(space):
rtrans.verbose()
return space.w_None
+
+def is_active(space):
+ return space.wrap(rtrans.is_active())
Modified: pypy/branch/njriley-trans/pypy/module/trans/rtrans.py
==============================================================================
--- pypy/branch/njriley-trans/pypy/module/trans/rtrans.py (original)
+++ pypy/branch/njriley-trans/pypy/module/trans/rtrans.py Wed Mar 1 02:08:56 2006
@@ -25,3 +25,7 @@
def disable():
os.write(2, '= rtrans.disable\n')
+
+def is_active():
+ os.write(2, '= rtrans.is_active\n')
+ return False
Modified: pypy/branch/njriley-trans/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/branch/njriley-trans/pypy/rpython/extfunctable.py (original)
+++ pypy/branch/njriley-trans/pypy/rpython/extfunctable.py Wed Mar 1 02:08:56 2006
@@ -250,6 +250,7 @@
declare(rtrans.verbose, noneannotation, 'll_trans/verbose')
declare(rtrans.enable, noneannotation, 'll_trans/enable')
declare(rtrans.disable, noneannotation, 'll_trans/disable')
+declare(rtrans.is_active, bool, 'll_trans/is_active')
# ___________________________________________________________
# javascript
Modified: pypy/branch/njriley-trans/pypy/rpython/module/ll_trans.py
==============================================================================
--- pypy/branch/njriley-trans/pypy/rpython/module/ll_trans.py (original)
+++ pypy/branch/njriley-trans/pypy/rpython/module/ll_trans.py Wed Mar 1 02:08:56 2006
@@ -29,3 +29,7 @@
def ll_trans_disable():
pass
ll_trans_disable.suggested_primitive = True
+
+def ll_trans_is_active():
+ return False
+ll_trans_is_active.suggested_primitive = True
Modified: pypy/branch/njriley-trans/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/branch/njriley-trans/pypy/translator/c/extfunc.py (original)
+++ pypy/branch/njriley-trans/pypy/translator/c/extfunc.py Wed Mar 1 02:08:56 2006
@@ -63,6 +63,7 @@
ll_trans.ll_trans_verbose: 'LL_trans_verbose',
ll_trans.ll_trans_enable: 'LL_trans_enable',
ll_trans.ll_trans_disable: 'LL_trans_disable',
+ ll_trans.ll_trans_is_active: 'LL_trans_is_active',
ll_tsc.ll_tsc_read: 'LL_tsc_read',
ll_tsc.ll_tsc_read_diff: 'LL_tsc_read_diff',
ll_tsc.ll_tsc_reset_diff:'LL_tsc_reset_diff',
Modified: pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h
==============================================================================
--- pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h (original)
+++ pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h Wed Mar 1 02:08:56 2006
@@ -103,4 +103,15 @@
set_auto_xact(0);
}
+int
+LL_trans_is_active(void)
+{
+ int ret_val;
+
+ XACT_ACTIVE(ret_val);
+ assert(ret_val == 0 || ret_val == 1);
+
+ return ret_val;
+}
+
#endif /* PYPY_NOT_MAIN_FILE */
More information about the Pypy-commit
mailing list