Commit e7998c26 authored by Armin Rigo's avatar Armin Rigo

Test and fix on Windows: if we pass a timeout larger than 49 days, we

used to get an abort in thread_nt.c.
parent 7ec1d360
import gc, time
from rpython.rlib.rthread import *
from rpython.rlib.rarithmetic import r_longlong
from rpython.translator.c.test.test_boehm import AbstractGCTestClass
from rpython.rtyper.lltypesystem import lltype, rffi
import py
......@@ -188,6 +189,15 @@ class AbstractThreadTests(AbstractGCTestClass):
res = fn()
assert res < -1.0
def test_acquire_timed_huge_timeout(self):
t = r_longlong(2 ** 61)
def f():
l = allocate_lock()
return l.acquire_timed(t)
fn = self.getcompiled(f, [])
res = fn()
assert res == 1 # RPY_LOCK_ACQUIRED
def test_acquire_timed_alarm(self):
import sys
if not sys.platform.startswith('linux'):
......
......@@ -103,12 +103,14 @@ long RPyThreadSetStackSize(long newsize)
/************************************************************/
static
BOOL InitializeNonRecursiveMutex(PNRMUTEX mutex)
{
mutex->sem = CreateSemaphore(NULL, 1, 1, NULL);
return !!mutex->sem;
}
static
VOID DeleteNonRecursiveMutex(PNRMUTEX mutex)
{
/* No in-use check */
......@@ -116,11 +118,24 @@ VOID DeleteNonRecursiveMutex(PNRMUTEX mutex)
mutex->sem = NULL ; /* Just in case */
}
DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds)
static
DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, RPY_TIMEOUT_T milliseconds)
{
return WaitForSingleObject(mutex->sem, milliseconds);
DWORD res;
if (milliseconds < 0)
return WaitForSingleObject(mutex->sem, INFINITE);
while (milliseconds >= (RPY_TIMEOUT_T)INFINITE) {
res = WaitForSingleObject(mutex->sem, INFINITE - 1);
if (res != WAIT_TIMEOUT)
return res;
milliseconds -= (RPY_TIMEOUT_T)(INFINITE - 1);
}
return WaitForSingleObject(mutex->sem, (DWORD)milliseconds);
}
static
BOOL LeaveNonRecursiveMutex(PNRMUTEX mutex)
{
return ReleaseSemaphore(mutex->sem, 1, NULL);
......@@ -162,17 +177,9 @@ RPyThreadAcquireLockTimed(struct RPyOpaque_ThreadLock *lock,
milliseconds = microseconds / 1000;
if (microseconds % 1000 > 0)
++milliseconds;
if ((DWORD) milliseconds != milliseconds) {
fprintf(stderr, "Timeout too large for a DWORD, "
"please check RPY_TIMEOUT_MAX");
abort();
}
}
else
milliseconds = INFINITE;
if (lock && EnterNonRecursiveMutex(
lock, (DWORD)milliseconds) == WAIT_OBJECT_0) {
if (lock && EnterNonRecursiveMutex(lock, milliseconds) == WAIT_OBJECT_0) {
success = RPY_LOCK_ACQUIRED;
}
else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment