Author: Armin Rigo <[email protected]>
Branch: stm-thread-2
Changeset: r60782:49a1afc2949f
Date: 2013-01-31 17:40 +0100
http://bitbucket.org/pypy/pypy/changeset/49a1afc2949f/

Log:    hg merge default

diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -130,10 +130,11 @@
         return bool(res)
 
     def acquire_timed(self, timeout):
-        "timeout is in microseconds."
+        """Timeout is in microseconds.  Returns 0 in case of failure,
+        1 in case it works, 2 if interrupted by a signal."""
         res = c_thread_acquirelock_timed(self._lock, timeout, 1)
         res = rffi.cast(lltype.Signed, res)
-        return bool(res)
+        return res
 
     def release(self):
         # Sanity check: the lock must be locked
diff --git a/rpython/rlib/test/test_rthread.py 
b/rpython/rlib/test/test_rthread.py
--- a/rpython/rlib/test/test_rthread.py
+++ b/rpython/rlib/test/test_rthread.py
@@ -159,17 +159,46 @@
             l = allocate_lock()
             l.acquire(True)
             t1 = time.time()
-            ok = l.acquire_timed(1000000)
+            ok = l.acquire_timed(1000001)
             t2 = time.time()
             delay = t2 - t1
-            if ok:
+            if ok == 0:        # RPY_LOCK_FAILURE
+                return -delay
+            elif ok == 2:      # RPY_LOCK_INTR
                 return delay
-            else:
-                return -delay
+            else:              # RPY_LOCK_ACQUIRED
+                return 0.0
         fn = self.getcompiled(f, [])
         res = fn()
         assert res < -1.0
 
+    def test_acquire_timed_alarm(self):
+        import sys
+        if not sys.platform.startswith('linux'):
+            py.test.skip("skipped on non-linux")
+        import time
+        from rpython.rlib import rsignal
+        def f():
+            l = allocate_lock()
+            l.acquire(True)
+            #
+            rsignal.pypysig_setflag(rsignal.SIGALRM)
+            rsignal.c_alarm(1)
+            #
+            t1 = time.time()
+            ok = l.acquire_timed(2500000)
+            t2 = time.time()
+            delay = t2 - t1
+            if ok == 0:        # RPY_LOCK_FAILURE
+                return -delay
+            elif ok == 2:      # RPY_LOCK_INTR
+                return delay
+            else:              # RPY_LOCK_ACQUIRED
+                return 0.0
+        fn = self.getcompiled(f, [])
+        res = fn()
+        assert res >= 0.95
+
 #class TestRunDirectly(AbstractThreadTests):
 #    def getcompiled(self, f, argtypes):
 #        return f
diff --git a/rpython/translator/c/src/thread.h 
b/rpython/translator/c/src/thread.h
--- a/rpython/translator/c/src/thread.h
+++ b/rpython/translator/c/src/thread.h
@@ -7,7 +7,7 @@
 typedef enum RPyLockStatus {
     RPY_LOCK_FAILURE = 0,
     RPY_LOCK_ACQUIRED = 1,
-    RPY_LOCK_INTR
+    RPY_LOCK_INTR = 2
 } RPyLockStatus;
 
 #ifdef _WIN32
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to