Commit a95488a9 authored by Jean-Claude Beaudoin's avatar Jean-Claude Beaudoin
Browse files

Merge branch 'master' of github.com:jcbeaudoin/MKCL

parents 64089c75 aa665813
......@@ -2394,7 +2394,7 @@ interrupt_thread_internal(MKCL, mkcl_object thread, mkcl_object function, mkcl_i
} MKCL_UNWIND_PROTECT_END;
if ( !(success || failure) )
sched_yield();
MKCL_LIBC_NO_INTR(env, sched_yield());
} while ( !(retry_count >= MAX_INTERRUPT_RETRIES || success || failure) );
if ( retry_count >= MAX_INTERRUPT_RETRIES)
......@@ -2723,10 +2723,10 @@ mk_mt_thread_join(MKCL, mkcl_object thread)
mkcl_object
mk_mt_thread_yield(MKCL)
{
#ifdef HAVE_SCHED_YIELD
MKCL_LIBC_NO_INTR(env, sched_yield());
#elif MKCL_WINDOWS
#if MKCL_WINDOWS
MKCL_LIBC_NO_INTR(env, SwitchToThread());
#elif defined(HAVE_SCHED_YIELD)
MKCL_LIBC_NO_INTR(env, sched_yield());
#else
MKCL_LIBC_NO_INTR(env, sleep(0)); /* Use sleep(0) to yield to a >= priority thread */
#endif
......
......@@ -167,7 +167,50 @@ mk_cl_sleep(MKCL, mkcl_object z)
if (fe_inexact_on)
fedisableexcept(FE_INEXACT);
#ifdef HAVE_NANOSLEEP
#if MKCL_WINDOWS
{
double r = mkcl_to_double(env, z) * 1000;
long long now_ms;
long long target_ms;
FILETIME system_time;
ULARGE_INTEGER uli_system_time; /* in multiples of 100 nanoseconds. */
DWORD val;
MKCL_LIBC_NO_INTR(env, GetSystemTimeAsFileTime(&system_time));
uli_system_time.LowPart = system_time.dwLowDateTime;
uli_system_time.HighPart = system_time.dwHighDateTime;
now_ms = uli_system_time.QuadPart / 10000;
target_ms = now_ms + ((long long) round(r)); /* used to be llround() but mingw with gcc 4.8.1 foobared on it. */
if (fe_inexact_on)
{
feclearexcept(FE_INEXACT);
feenableexcept(FE_INEXACT);
}
do {
DWORD duration;
if (now_ms >= target_ms)
duration = 0;
if ((target_ms - now_ms) > MAXDWORD)
duration = MAXDWORD;
else
duration = target_ms - now_ms;
MKCL_LIBC_Zzz(env, @':io', val = SleepEx(duration, TRUE)); /* The "alertable" version. */
MKCL_LIBC_NO_INTR(env, GetSystemTimeAsFileTime(&system_time));
uli_system_time.LowPart = system_time.dwLowDateTime;
uli_system_time.HighPart = system_time.dwHighDateTime;
now_ms = uli_system_time.QuadPart / 10000;
} while ((val == WAIT_IO_COMPLETION) && (now_ms < target_ms));
mk_mt_test_for_thread_shutdown(env);
}
#elif defined(HAVE_NANOSLEEP)
{
struct timespec tm;
double r = mkcl_to_double(env, z);
......@@ -194,73 +237,6 @@ mk_cl_sleep(MKCL, mkcl_object z)
mkcl_FElibc_error(env, "mk_cl_sleep() failed on nanosleep().", 0);
}
}
#elif MKCL_WINDOWS
{
double r = mkcl_to_double(env, z) * 1000;
#if 0
DWORD duration = (DWORD) r; /* This limits sleep duration to about 49,7 days */
if (fe_inexact_on)
{
feclearexcept(FE_INEXACT);
feenableexcept(FE_INEXACT);
}
#endif
#if 0
Sleep(duration); /* This one sleeps hard and cannot be interrupted. JCB */
#else
{
long long now_ms;
long long target_ms;
FILETIME system_time;
ULARGE_INTEGER uli_system_time; /* in multiples of 100 nanoseconds. */
DWORD val;
MKCL_LIBC_NO_INTR(env, GetSystemTimeAsFileTime(&system_time));
uli_system_time.LowPart = system_time.dwLowDateTime;
uli_system_time.HighPart = system_time.dwHighDateTime;
now_ms = uli_system_time.QuadPart / 10000;
#if 0
target_ms = now_ms + llround(r);
#else
target_ms = now_ms + ((long long) round(r)); /* used to be llround() but mingw with gcc 4.8.1 foobared on it. */
#endif
if (fe_inexact_on)
{
feclearexcept(FE_INEXACT);
feenableexcept(FE_INEXACT);
}
do {
DWORD duration;
if (now_ms >= target_ms)
duration = 0;
if ((target_ms - now_ms) > MAXDWORD)
duration = MAXDWORD;
else
duration = target_ms - now_ms;
#if 0
fprintf(stderr, "\nMKCL: sleep duration = %lu ms.\n", duration); fflush(stderr);
#endif
MKCL_LIBC_Zzz(env, @':io', val = SleepEx(duration, TRUE)); /* The "alertable" version. */
MKCL_LIBC_NO_INTR(env, GetSystemTimeAsFileTime(&system_time));
uli_system_time.LowPart = system_time.dwLowDateTime;
uli_system_time.HighPart = system_time.dwHighDateTime;
now_ms = uli_system_time.QuadPart / 10000;
} while ((val == WAIT_IO_COMPLETION) && (now_ms < target_ms));
mk_mt_test_for_thread_shutdown(env);
}
#endif
}
#else
z = mkcl_round1(z);
if (fe_inexact_on)
......
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