From df29f9fc22fb7a2827ae5396aeb8127636f6ece4 Mon Sep 17 00:00:00 2001
From: Benoit Germain
- This document was revised on 05-Apr-13, and applies to version 3.6.1. + This document was revised on 20-May-13, and applies to version 3.6.2.
diff --git a/make-vc.cmd b/make-vc.cmd index 7711a44..910390a 100644 --- a/make-vc.cmd +++ b/make-vc.cmd @@ -84,7 +84,7 @@ goto ERR_NOLUA :BUILD @REM LuaBinaries: -@REM The current build system does not show 'lua51-lanes.dll' to +@REM The current build system does not show 'lanes/core.dll' to @REM be dependent on more than 'KERNEL32.DLL'. Good. @REM @REM Lua for Windows: @@ -113,13 +113,6 @@ goto ERR_NOLUA @goto EXIT :LUA_LIB_OK -@REM -@REM Embed src/keeper.lua -> .lch -@REM -@REM Note: we cannot use piping in Windows since we need binary output. -@REM -"%LUA_EXE%" tools/bin2c.lua -o src/keeper.lch src/keeper.lua - @if "%VCINSTALLDIR%"=="" goto ERR_NOVC @REM @@ -138,14 +131,14 @@ goto ERR_NOLUA @set FLAGS=/O2 /LD cl %WARN% %FLAGS% /I "%LUA51%\include" /Felua51-lanes.dll src\*.c "%LUA_LIB%\lua5.1.lib" -@REM cl %WARN% %FLAGS% /I "%LUA51%\include" /Felua51-lanes.dll src\*.c "%LUA_LIB%\lua5.1.lib" /link /NODEFAULTLIB:libcmt +@REM cl %WARN% %FLAGS% /I "%LUA51%\include" /Felanes\core.dll src\*.c "%LUA_LIB%\lua5.1.lib" /link /NODEFAULTLIB:libcmt -@del lua51-lanes.lib -@del lua51-lanes.exp +@del lanes\core.lib +@del lanes\core.exp @goto EXIT :CLEAN -if exist *.dll del *.dll +if exist lanes\*.dll del lanes\*.dll if exist delme del delme @goto EXIT diff --git a/src/lanes.c b/src/lanes.c index 2c6a3ba..08bdb9a 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -52,7 +52,7 @@ * ... */ -char const* VERSION = "3.6.1"; +char const* VERSION = "3.6.2"; /* =============================================================================== diff --git a/src/threading.c b/src/threading.c index 754b6d1..43e5f46 100644 --- a/src/threading.c +++ b/src/threading.c @@ -243,6 +243,8 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { #endif #if THREADAPI == THREADAPI_WINDOWS + +#if WINVER <= 0x0400 // Windows NT4: Use Mutexes with Events // void MUTEX_INIT( MUTEX_T *ref ) { *ref= CreateMutex( NULL /*security attr*/, FALSE /*not locked*/, NULL ); @@ -260,6 +262,8 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { if (!ReleaseMutex(*ref)) FAIL( "ReleaseMutex", GetLastError() ); } +#endif // Windows NT4 + /* MSDN: "If you would like to use the CRT in ThreadProc, use the _beginthreadex function instead (of CreateThread)." MSDN: "you can create at most 2028 threads" @@ -354,6 +358,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) #endif // !__GNUC__ } +#if WINVER <= 0x0400 // Windows NT4: Use PulseEvent, although it is unreliable, but then... // void SIGNAL_INIT( SIGNAL_T *ref ) { @@ -426,6 +431,66 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) if (!PulseEvent( *ref )) FAIL( "PulseEvent", GetLastError() ); } + +#else // Windows Vista and above: condition variables exist, use them + + // + void SIGNAL_INIT( SIGNAL_T *ref ) + { + InitializeConditionVariable( ref); + } + + void SIGNAL_FREE( SIGNAL_T *ref ) + { + // nothing to do + ref; + } + + bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu_ref, time_d abs_secs) + { + long ms; + + if( abs_secs < 0.0) + ms = INFINITE; + else if( abs_secs == 0.0) + ms = 0; + else + { + ms = (long) ((abs_secs - now_secs())*1000.0 + 0.5); + + // If the time already passed, still try once (ms==0). A short timeout + // may have turned negative or 0 because of the two time samples done. + // + if( ms < 0) + ms = 0; + } + + if( !SleepConditionVariableCS( ref, mu_ref, ms)) + { + if( GetLastError() == ERROR_TIMEOUT) + { + return FALSE; + } + else + { + FAIL( "SleepConditionVariableCS", GetLastError()); + } + } + return TRUE; + } + + void SIGNAL_ONE( SIGNAL_T *ref ) + { + WakeConditionVariable( ref); + } + + void SIGNAL_ALL( SIGNAL_T *ref ) + { + WakeAllConditionVariable( ref); + } + +#endif // Windows Vista and above + #else // THREADAPI == THREADAPI_PTHREAD // PThread (Linux, OS X, ...) // diff --git a/src/threading.h b/src/threading.h index 1b218b9..e559910 100644 --- a/src/threading.h +++ b/src/threading.h @@ -64,7 +64,7 @@ enum e_status { PENDING, RUNNING, WAITING, DONE, ERROR_ST, CANCELLED }; #else // !PLATFORM_XBOX #define WIN32_LEAN_AND_MEAN // 'SignalObjectAndWait' needs this (targets Windows 2000 and above) - #define _WIN32_WINNT 0x0400 + //#define _WIN32_WINNT 0x0500 Let the compiler decide depending on the host OS #include