[pypy-svn] pypy default: cpyext: expose PyThread_allocate_lock, PyThread_free_lock
amauryfa
commits-noreply at bitbucket.org
Mon Mar 21 23:21:22 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r42835:82c910237508
Date: 2011-03-21 23:21 +0100
http://bitbucket.org/pypy/pypy/changeset/82c910237508/
Log: cpyext: expose PyThread_allocate_lock, PyThread_free_lock
diff --git a/pypy/module/thread/ll_thread.py b/pypy/module/thread/ll_thread.py
--- a/pypy/module/thread/ll_thread.py
+++ b/pypy/module/thread/ll_thread.py
@@ -111,7 +111,7 @@
c_thread_releaselock(self._lock)
def __del__(self):
- lltype.free(self._lock, flavor='raw', track_allocation=False)
+ free_ll_lock(self._lock)
# ____________________________________________________________
#
@@ -138,6 +138,9 @@
raise error("out of resources")
return ll_lock
+def free_ll_lock(ll_lock):
+ lltype.free(ll_lock, flavor='raw', track_allocation=False)
+
def acquire_NOAUTO(ll_lock, flag):
flag = rffi.cast(rffi.INT, int(flag))
res = c_thread_acquirelock_NOAUTO(ll_lock, flag)
diff --git a/pypy/module/cpyext/thread.py b/pypy/module/cpyext/thread.py
--- a/pypy/module/cpyext/thread.py
+++ b/pypy/module/cpyext/thread.py
@@ -9,6 +9,16 @@
LOCKP = rffi.COpaquePtr(typedef='PyThread_type_lock')
+ at cpython_api([], LOCKP)
+def PyThread_allocate_lock(space):
+ lock = ll_thread.allocate_ll_lock()
+ return rffi.cast(LOCKP, lock)
+
+ at cpython_api([LOCKP], lltype.Void)
+def PyThread_free_lock(space, lock):
+ lock = rffi.cast(ll_thread.TLOCKP, lock)
+ ll_thread.free_ll_lock(lock)
+
@cpython_api([LOCKP, rffi.INT], rffi.INT, error=CANNOT_FAIL)
def PyThread_acquire_lock(space, lock, waitflag):
lock = rffi.cast(ll_thread.TLOCKP, lock)
diff --git a/pypy/module/cpyext/test/test_thread.py b/pypy/module/cpyext/test/test_thread.py
--- a/pypy/module/cpyext/test/test_thread.py
+++ b/pypy/module/cpyext/test/test_thread.py
@@ -26,13 +26,15 @@
def test_acquire_lock(self, space, api):
assert hasattr(api, 'PyThread_acquire_lock')
- lock = allocate_ll_lock()
+ lock = api.PyThread_allocate_lock()
assert api.PyThread_acquire_lock(lock, 1) == 1
assert api.PyThread_acquire_lock(lock, 0) == 0
+ api.PyThread_free_lock(lock)
def test_release_lock(self, space, api):
assert hasattr(api, 'PyThread_acquire_lock')
- lock = allocate_ll_lock()
+ lock = api.PyThread_allocate_lock()
api.PyThread_acquire_lock(lock, 1)
api.PyThread_release_lock(lock)
assert api.PyThread_acquire_lock(lock, 0) == 1
+ api.PyThread_free_lock(lock)
More information about the Pypy-commit
mailing list