From 0fd5f6b676bed803321f2519a7201b3a4b1c7368 Mon Sep 17 00:00:00 2001 From: Shane Bryldt Date: Mon, 27 Mar 2017 16:52:07 -0600 Subject: [PATCH] FS-10167: Fixed issue with eating processor when ks_sleep() is called on windows, testthreadmutex is now fully functional on windows as well, all tests are passing --- libs/libks/libks.sln | 12 +- libs/libks/src/ks_mutex.c | 2 +- libs/libks/src/ks_time.c | 1 + libs/libks/test/testmmap.vcxproj | 182 ++++++++++++++++++++++++++++++ libs/libks/test/testthreadmutex.c | 10 +- 5 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 libs/libks/test/testmmap.vcxproj diff --git a/libs/libks/libks.sln b/libs/libks/libks.sln index e0c1b4869f..72a14904b4 100644 --- a/libs/libks/libks.sln +++ b/libs/libks/libks.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libks", "libks.vcxproj", "{70D178D8-1100-4152-86C0-809A91CFF832}" EndProject @@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsock", "test\testsock.v EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testtime", "test\testtime.vcxproj", "{B74812A1-C67D-4568-AF84-26CE2004D8BF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testmmap", "test\testmmap.vcxproj", "{7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -81,6 +83,14 @@ Global {B74812A1-C67D-4568-AF84-26CE2004D8BF}.Release|x64.Build.0 = Release|x64 {B74812A1-C67D-4568-AF84-26CE2004D8BF}.Release|x86.ActiveCfg = Release|Win32 {B74812A1-C67D-4568-AF84-26CE2004D8BF}.Release|x86.Build.0 = Release|Win32 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Debug|x64.ActiveCfg = Debug|x64 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Debug|x64.Build.0 = Debug|x64 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Debug|x86.ActiveCfg = Debug|Win32 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Debug|x86.Build.0 = Debug|Win32 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Release|x64.ActiveCfg = Release|x64 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Release|x64.Build.0 = Release|x64 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Release|x86.ActiveCfg = Release|Win32 + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/libks/src/ks_mutex.c b/libs/libks/src/ks_mutex.c index b21f696343..cea52e6f2e 100644 --- a/libs/libks/src/ks_mutex.c +++ b/libs/libks/src/ks_mutex.c @@ -558,7 +558,7 @@ KS_DECLARE(ks_status_t) ks_rwl_try_read_lock(ks_rwl_t *rwlock) { #ifdef WIN32 if (ks_mutex_trylock(rwlock->write_lock_mutex) != KS_STATUS_SUCCESS) { - return KS_STATUS_FALSE; + return KS_STATUS_FAIL; } ks_mutex_lock(rwlock->read_lock_mutex); diff --git a/libs/libks/src/ks_time.c b/libs/libks/src/ks_time.c index 8e5166884f..6e7c0ec18b 100644 --- a/libs/libks/src/ks_time.c +++ b/libs/libks/src/ks_time.c @@ -178,6 +178,7 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec) do { QueryPerformanceCounter((LARGE_INTEGER*) &now); + SwitchToThread(); } while ((now.QuadPart - start.QuadPart) / (float)(perfCnt.QuadPart) * 1000 * 1000 < (DWORD)microsec); } diff --git a/libs/libks/test/testmmap.vcxproj b/libs/libks/test/testmmap.vcxproj new file mode 100644 index 0000000000..d795d27d05 --- /dev/null +++ b/libs/libks/test/testmmap.vcxproj @@ -0,0 +1,182 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {7BA42C3F-B5F6-4C48-AFED-B50EB35C4F03} + Win32Proj + testmmap + 8.1 + + + + Application + true + v140_xp + Unicode + + + Application + false + v140_xp + true + Unicode + + + Application + true + v140_xp + Unicode + + + Application + false + v140_xp + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)$(Platform)\$(Configuration)\ + $(SolutionDir);$(SolutionDir)\crypt;$(SolutionDir)\openssl\include;$(IncludePath) + $(SolutionDir)\openssl\lib;$(LibraryPath) + + + true + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir);$(SolutionDir)\crypt;$(SolutionDir)\openssl\include64;$(IncludePath) + $(SolutionDir)\openssl\lib64;$(LibraryPath) + + + false + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)$(Platform)\$(Configuration)\ + $(SolutionDir);$(SolutionDir)\crypt;$(SolutionDir)\openssl\include;$(IncludePath) + $(SolutionDir)\openssl\lib;$(LibraryPath) + + + false + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir);$(SolutionDir)\crypt;$(SolutionDir)\openssl\include64;$(IncludePath) + $(SolutionDir)\openssl\lib64;$(LibraryPath) + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../src/include;. + 4090 + + + Console + true + + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../src/include;. + 4090 + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../src/include;. + 4090 + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../src/include;. + 4090 + + + Console + true + true + true + + + + + {70d178d8-1100-4152-86c0-809a91cff832} + + + + + + + + + + \ No newline at end of file diff --git a/libs/libks/test/testthreadmutex.c b/libs/libks/test/testthreadmutex.c index 02e666db73..e51a855c78 100644 --- a/libs/libks/test/testthreadmutex.c +++ b/libs/libks/test/testthreadmutex.c @@ -131,7 +131,6 @@ static void check_rwl(void) ok( (ks_thread_create(&threads[i], thread_test_rwlock_func, NULL, pool) == KS_STATUS_SUCCESS) ); } - for(i = 0; i < cpu_count; i++) { ks_thread_join(threads[i]); } @@ -321,15 +320,12 @@ static void test_non_recursive_mutex(void) int main(int argc, char **argv) { ks_init(); - //cpu_count = ks_cpu_count() * 4; - //cpu_count = ks_cpu_count(); - cpu_count = 1; + cpu_count = ks_cpu_count() * 4; plan(21 + cpu_count * 6); - diag("Starting testing for %d tests\n", 21 + cpu_count * 6); - + create_pool(); create_mutex(); create_mutex_non_recursive(); @@ -347,7 +343,7 @@ int main(int argc, char **argv) check_cleanup(); check_rwl(); check_cond(); - + ks_shutdown(); done_testing(); }