[pypy-svn] r74211 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

exarkun at codespeak.net exarkun at codespeak.net
Thu Apr 29 01:41:31 CEST 2010


Author: exarkun
Date: Thu Apr 29 01:41:30 2010
New Revision: 74211

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_thread.py
   pypy/branch/cpython-extension/pypy/module/cpyext/thread.py
Log:
Avoid the unnecessary wrapping in get_thread_ident; try to implement acquire_lock, and fail.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_thread.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_thread.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_thread.py	Thu Apr 29 01:41:30 2010
@@ -1,6 +1,7 @@
 
 import thread, threading
 
+from pypy.module.thread.ll_thread import allocate_ll_lock
 from pypy.module.cpyext.test.test_api import BaseApiTest
 
 
@@ -8,8 +9,8 @@
     def test_get_thread_ident(self, space, api):
         results = []
         def some_thread():
-            w_res = api.PyThread_get_thread_ident(space)
-            results.append((space.int_w(w_res), thread.get_ident()))
+            res = api.PyThread_get_thread_ident(space)
+            results.append((res, thread.get_ident()))
 
         some_thread()
         assert results[0][0] == results[0][1]
@@ -18,3 +19,18 @@
         th.start()
         th.join()
         assert results[1][0] == results[1][1]
+
+        assert results[0][0] != results[1][0]
+
+
+    # def test_acquire_lock(self, space, api):
+    #     lock = allocate_ll_lock()
+    #     assert api.PyThread_acquire_lock(lock, space.w_int(0)) == 1
+    #     assert api.PyThread_acquire_lock(lock, space.w_int(1)) == 0
+
+
+    # def test_release_lock(self, space, api):
+    #     lock = allocate_ll_lock()
+    #     api.PyThread_acquire_lock(lock, space.w_int(0))
+    #     api.PyThread_release_lock(lock)
+    #     assert api.PyThread_acquire_lock(lock, space.w_int(0)) == 1

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/thread.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/thread.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/thread.py	Thu Apr 29 01:41:30 2010
@@ -1,8 +1,13 @@
 
-from pypy.module.thread import os_thread
+from pypy.module.thread import ll_thread
 from pypy.module.cpyext.api import CANNOT_FAIL, cpython_api
 from pypy.rpython.lltypesystem import rffi
 
 @cpython_api([], rffi.LONG, error=CANNOT_FAIL)
 def PyThread_get_thread_ident(space):
-    return os_thread.get_ident(space)
+    return ll_thread.get_ident()
+
+
+# @cpython_api([ll_thread.TLOCKP, rffi.INT], rffi.INT, error=CANNOT_FAIL)
+# def PyThread_acquire_lock(space, lock, waitflag):
+#     return ll_thread.Lock(lock).acquire(waitflag)



More information about the Pypy-commit mailing list