From: Lars Op den Kamp Date: Sun, 15 Jan 2012 13:32:26 +0000 (+0100) Subject: cec: refactored threading/locking - added windows native instead of pthread-win32... X-Git-Tag: upstream/2.2.0~1^2~39^2~29 X-Git-Url: https://git.piment-noir.org/?p=deb_libcec.git;a=commitdiff_plain;h=f00ff009cfc5dfefdf09ca241b9560e74575b3f5 cec: refactored threading/locking - added windows native instead of pthread-win32, so we can compile native x64 too --- diff --git a/.gitignore b/.gitignore index 9abd286..6ec51bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,13 @@ -.project -.cproject -*.ilk -*.manifest -*.metagen -*.pdb +/.project +/.cproject +/*.dll +/*.exe +/*.exp +/*.ilk +/*.lib +/*.manifest +/*.metagen +/*.pdb aclocal.m4 autom4te.cache @@ -21,24 +25,6 @@ Makefile Makefile.in missing -libcec.dll -libcec.exp -libcec.ilk -libcec.lib -libcec.pdb -cec-client.exe -cec-client.ilk -cec-client.pdb -CecSharpClient.exe -CecSharpClient.pdb -CecSharpClient.vshost.exe -CecSharpClient.vshost.exe.manifest - -LibCecSharp.dll -LibCecSharp.Net2.dll -LibCecSharp.ilk -LibCecSharp.pdb - build include/boost @@ -55,6 +41,7 @@ project/*.opensdf project/Properties project/*.suo project/*.user +project/x64 src/lib/.deps src/lib/.libs diff --git a/include/cecloader.h b/include/cecloader.h index 49efbd7..1e6d716 100644 --- a/include/cecloader.h +++ b/include/cecloader.h @@ -1,3 +1,4 @@ +#pragma once /* * This file is part of the libCEC(R) library. * @@ -45,7 +46,11 @@ HINSTANCE g_libCEC = NULL; CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS, const char *strLib = NULL) { if (!g_libCEC) +#if defined(_WIN64) + g_libCEC = LoadLibrary(strLib ? strLib : "libcec.x64.dll"); +#else g_libCEC = LoadLibrary(strLib ? strLib : "libcec.dll"); +#endif if (!g_libCEC) return NULL; @@ -67,7 +72,11 @@ CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogi CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_list types, const char *strLib = NULL) { if (!g_libCEC) +#if defined(_WIN64) + g_libCEC = LoadLibrary(strLib ? strLib : "libcec.x64.dll"); +#else g_libCEC = LoadLibrary(strLib ? strLib : "libcec.dll"); +#endif if (!g_libCEC) return NULL; diff --git a/project/LibCecSharp.Net2.sln b/project/LibCecSharp.Net2.sln index b50b423..ac97f5f 100644 --- a/project/LibCecSharp.Net2.sln +++ b/project/LibCecSharp.Net2.sln @@ -6,13 +6,19 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|Win32.ActiveCfg = Debug|Win32 {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|Win32.Build.0 = Debug|Win32 + {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|x64.ActiveCfg = Debug|x64 + {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|x64.Build.0 = Debug|x64 {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|Win32.ActiveCfg = Release|Win32 {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|Win32.Build.0 = Release|Win32 + {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|x64.ActiveCfg = Release|x64 + {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/project/LibCecSharp.Net2.vcproj b/project/LibCecSharp.Net2.vcproj index 3fdfcae..e65be24 100644 --- a/project/LibCecSharp.Net2.vcproj +++ b/project/LibCecSharp.Net2.vcproj @@ -13,6 +13,9 @@ + @@ -91,6 +94,82 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - diff --git a/project/LibCecSharp.vcxproj b/project/LibCecSharp.vcxproj index 0a3e575..8b23d1e 100644 --- a/project/LibCecSharp.vcxproj +++ b/project/LibCecSharp.vcxproj @@ -5,10 +5,18 @@ Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7} @@ -23,39 +31,83 @@ true Unicode + + DynamicLibrary + true + true + Unicode + DynamicLibrary false true Unicode + + DynamicLibrary + false + true + MultiByte + + + + + + + - true $(SolutionDir)\..\include;$(IncludePath) $(ProjectName) $(SolutionDir)..\ $(SolutionDir)LibCecSharp.Net2-dev.snk + + true + $(SolutionDir)\..\include;$(IncludePath) + $(ProjectName).x64 + $(SolutionDir)..\ + $(SolutionDir)LibCecSharp.Net2-dev.snk + - false $(SolutionDir)\..\include;$(IncludePath) $(SolutionDir)LibCecSharp.Net2-dev.snk + $(SolutionDir)..\ + + + $(SolutionDir)\..\include;$(IncludePath) + $(SolutionDir)LibCecSharp.Net2-dev.snk + $(ProjectName).x64 + $(SolutionDir)..\ Level3 Disabled - WIN32;_DEBUG;%(PreprocessorDefinitions) + _DEBUG;%(PreprocessorDefinitions) + NotUsing + + + true + + + MachineX86 + + + + + Level3 + Disabled + _WIN64;_DEBUG;%(PreprocessorDefinitions) NotUsing @@ -67,7 +119,19 @@ Level3 - WIN32;NDEBUG;%(PreprocessorDefinitions) + NDEBUG;%(PreprocessorDefinitions) + NotUsing + + + true + + + + + + + Level3 + _WIN64;NDEBUG;%(PreprocessorDefinitions) NotUsing diff --git a/project/create-installer.cmd b/project/create-installer.cmd index 78daa7e..369e408 100644 --- a/project/create-installer.cmd +++ b/project/create-installer.cmd @@ -18,13 +18,24 @@ IF "%VS100COMNTOOLS%"=="" ( ) echo Cleaning libCEC -%COMPILER10% libcec.sln /clean Release +%COMPILER10% libcec.sln /clean "Release|Win32" echo Compiling libCEC -%COMPILER10% libcec.sln /build Release /project libcec +%COMPILER10% libcec.sln /build "Release|Win32" /project libcec echo Compiling cec-client -%COMPILER10% libcec.sln /build Release /project testclient +%COMPILER10% libcec.sln /build "Release|Win32" /project testclient echo Compiling LibCecSharp -%COMPILER10% libcec.sln /build Release /project LibCecSharp +%COMPILER10% libcec.sln /build "Release|Win32" /project LibCecSharp + +IF EXIST "%ProgramFiles(x86)%" ( +echo Cleaning libCEC x64 +%COMPILER10% libcec.sln /clean "Release|x64" +echo Compiling libCEC x64 +%COMPILER10% libcec.sln /build "Release|x64" /project libcec +echo Compiling cec-client x64 +%COMPILER10% libcec.sln /build "Release|x64" /project testclient +echo Compiling LibCecSharp x64 +%COMPILER10% libcec.sln /build "Release|x64" /project LibCecSharp +) IF "%VS90COMNTOOLS%"=="" ( set COMPILER9="%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\VCExpress.exe" @@ -34,8 +45,17 @@ IF "%VS90COMNTOOLS%"=="" ( set COMPILER9="%VS90COMNTOOLS%\..\IDE\devenv.exe" ) ELSE GOTO NOSDK9 +echo Cleaning LibCecSharp.Net2 +%COMPILER9% LibCecSharp.Net2.sln /clean "Release|Win32" echo Compiling LibCecSharp.Net2 -%COMPILER9% LibCecSharp.Net2.sln /build Release +%COMPILER9% LibCecSharp.Net2.sln /build "Release|Win32" + +IF EXIST "%ProgramFiles(x86)%" ( +echo Cleaning LibCecSharp.Net2 x64 +%COMPILER9% LibCecSharp.Net2.sln /clean "Release|x64" +echo Compiling LibCecSharp.Net2 x64 +%COMPILER9% LibCecSharp.Net2.sln /build "Release|x64" +) :NOSDK9 echo Copying driver installer @@ -56,4 +76,4 @@ GOTO EXIT :NODDK echo Windows DDK could not be found on your system -:EXIT \ No newline at end of file +:EXIT diff --git a/project/libCEC.nsi b/project/libCEC.nsi index 065544a..2ec8c06 100644 --- a/project/libCEC.nsi +++ b/project/libCEC.nsi @@ -47,12 +47,12 @@ Section "libCEC" SecLibCEC SectionIn 1 #section is in installtype Full SetOutPath "$INSTDIR" File "..\AUTHORS" - File "..\cec-client.exe" + File "..\cec*.exe" File "..\ChangeLog" File "..\COPYING" - File "..\*.dll" - File "..\libcec.lib" - File "Release\LibCecSharp.dll" + File "..\libcec*.dll" + File "..\libcec*.lib" + File "..\LibCecSharp*.dll" File "..\README" ; Copy to XBMC\system @@ -82,6 +82,11 @@ Section "libCEC" SecLibCEC CreateShortCut "$SMPROGRAMS\$StartMenuFolder\CEC Test client.lnk" "$INSTDIR\cec-client.exe" \ "" "$INSTDIR\cec-client.exe" 0 SW_SHOWNORMAL \ "" "Start the CEC Test client." + ${If} ${RunningX64} + CreateShortCut "$SMPROGRAMS\$StartMenuFolder\CEC Test client (x64).lnk" "$INSTDIR\cec-client.x64.exe" \ + "" "$INSTDIR\cec-client.x64.exe" 0 SW_SHOWNORMAL \ + "" "Start the CEC Test client (x64)." + ${EndIf} CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall libCEC.lnk" "$INSTDIR\Uninstall.exe" \ "" "$INSTDIR\Uninstall.exe" 0 SW_SHOWNORMAL \ "" "Uninstall libCEC." @@ -131,12 +136,12 @@ Section "Uninstall" ExecWait '"$INSTDIR\driver\dpinst-x64.exe" /u "$INSTDIR\driver\OEM001.inf"' ${EndIf} Delete "$INSTDIR\AUTHORS" - Delete "$INSTDIR\cec-client.exe" + Delete "$INSTDIR\cec*.exe" Delete "$INSTDIR\ChangeLog" Delete "$INSTDIR\COPYING" Delete "$INSTDIR\*.dll" - Delete "$INSTDIR\libcec.lib" - Delete "$INSTDIR\libcec.pdb" + Delete "$INSTDIR\*.lib" + Delete "$INSTDIR\*.pdb" Delete "$INSTDIR\README" Delete "$INSTDIR\driver\OEM001.inf" Delete "$INSTDIR\driver\dpinst-amd64.exe" @@ -148,6 +153,9 @@ Section "Uninstall" !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder Delete "$SMPROGRAMS\$StartMenuFolder\CEC Test client.lnk" + ${If} ${RunningX64} + Delete "$SMPROGRAMS\$StartMenuFolder\CEC Test client (x64).lnk" + ${EndIf} Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall libCEC.lnk" Delete "$SMPROGRAMS\$StartMenuFolder\Visit Pulse-Eight.url" RMDir "$SMPROGRAMS\$StartMenuFolder" diff --git a/project/libcec.sln b/project/libcec.sln index df298f4..b1969d7 100644 --- a/project/libcec.sln +++ b/project/libcec.sln @@ -15,22 +15,36 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibCecSharp", "LibCecSharp. EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 + Debug|x64 = Debug|x64 + Debug|Win32 = Debug|Win32 + Release|x64 = Release|x64 + Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|x86.ActiveCfg = Debug|Win32 - {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|x86.Build.0 = Debug|Win32 - {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|x86.ActiveCfg = Release|Win32 - {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|x86.Build.0 = Release|Win32 - {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|x86.ActiveCfg = Debug|Win32 - {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|x86.Build.0 = Debug|Win32 - {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|x86.ActiveCfg = Release|Win32 - {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|x86.Build.0 = Release|Win32 - {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|x86.ActiveCfg = Debug|Win32 - {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|x86.Build.0 = Debug|Win32 - {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|x86.ActiveCfg = Release|Win32 - {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|x86.Build.0 = Release|Win32 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|x64.ActiveCfg = Debug|x64 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|x64.Build.0 = Debug|x64 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Win32.ActiveCfg = Debug|Win32 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Win32.Build.0 = Debug|Win32 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|x64.ActiveCfg = Release|x64 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|x64.Build.0 = Release|x64 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Win32.ActiveCfg = Release|Win32 + {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Win32.Build.0 = Release|Win32 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|x64.ActiveCfg = Debug|x64 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|x64.Build.0 = Debug|x64 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Win32.ActiveCfg = Debug|Win32 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Win32.Build.0 = Debug|Win32 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|x64.ActiveCfg = Release|x64 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|x64.Build.0 = Release|x64 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Win32.ActiveCfg = Release|Win32 + {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Win32.Build.0 = Release|Win32 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|x64.ActiveCfg = Debug|x64 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|x64.Build.0 = Debug|x64 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|Win32.ActiveCfg = Debug|Win32 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|Win32.Build.0 = Debug|Win32 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|x64.ActiveCfg = Release|x64 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|x64.Build.0 = Release|x64 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|Win32.ActiveCfg = Release|Win32 + {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/project/libcec.vcxproj b/project/libcec.vcxproj index d1a8ea0..4d320b3 100644 --- a/project/libcec.vcxproj +++ b/project/libcec.vcxproj @@ -5,10 +5,18 @@ Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + @@ -29,20 +37,16 @@ - - - - - - - - + + + + + + + - - - - - + + @@ -61,10 +65,6 @@ - - - - @@ -81,26 +81,49 @@ true MultiByte + + DynamicLibrary + true + MultiByte + DynamicLibrary false MultiByte + + DynamicLibrary + false + MultiByte + + + + + + + $(SolutionDir)..\ + + $(SolutionDir)..\ + - libcec + $(ProjectName) + .dll + + + $(ProjectName).x64 .dll @@ -109,27 +132,59 @@ false true + + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.dll + $(SolutionDir)..\include;$(IncludePath) + false + true + $(SolutionDir)..\ libcec .dll *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.dll $(SolutionDir)..\include;$(IncludePath) - true + + + $(SolutionDir)..\ + $(ProjectName).x64 + .dll + *.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.dll + $(SolutionDir)..\include;$(IncludePath) Level4 Disabled - _CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;DLL_EXPORT;%(PreprocessorDefinitions) - $(SolutionDir)..\src\lib\platform\pthread_win32;$(SolutionDir)..\include;%(AdditionalIncludeDirectories) - 4996;4100;4309;4505 + _USE_32BIT_TIME_T;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions) + $(SolutionDir)..\include;%(AdditionalIncludeDirectories) + + true true - $(SolutionDir)..\libcec.dll - %(AdditionalDependencies);setupapi.lib;$(SolutionDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib + $(SolutionDir)..\$(TargetName)$(TargetExt) + %(AdditionalDependencies);setupapi.lib + libcmtd + + + + + + + Level4 + Disabled + _WIN64;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions) + $(SolutionDir)..\include;%(AdditionalIncludeDirectories) + + + true + + + true + $(SolutionDir)..\$(TargetName)$(TargetExt) + %(AdditionalDependencies);setupapi.lib libcmtd @@ -142,8 +197,9 @@ true true $(SolutionDir)..\src\lib\platform\pthread_win32;$(SolutionDir)..\include;%(AdditionalIncludeDirectories) - _CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;DLL_EXPORT;%(PreprocessorDefinitions) - 4100;4309 + _USE_32BIT_TIME_T;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions) + + true Speed @@ -152,7 +208,31 @@ true true $(SolutionDir)..\libcec.dll - %(AdditionalDependencies);setupapi.lib;$(SolutionDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib + %(AdditionalDependencies);setupapi.lib + libcmt + + + + + + + Level4 + Full + true + true + $(SolutionDir)..\include;%(AdditionalIncludeDirectories) + _WIN64;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions) + + + true + Speed + + + false + true + true + $(SolutionDir)..\$(TargetName)$(TargetExt) + %(AdditionalDependencies);setupapi.lib libcmt diff --git a/project/libcec.vcxproj.filters b/project/libcec.vcxproj.filters index 6eb8310..1298c5c 100644 --- a/project/libcec.vcxproj.filters +++ b/project/libcec.vcxproj.filters @@ -1,9 +1,6 @@  - - {4171e8da-4c9d-40dd-97a3-755ba5535ca6} - {cc48ddc0-be11-43ec-a805-3a9434f443ed} @@ -16,42 +13,24 @@ {bfc43a58-636d-4c1a-b191-486cb8509c7c} - - {61b13ee2-8a5b-4f05-9796-08138ee6ebc1} + + {fa3d5953-d288-45e9-93f4-8419e6b701c7} + + + {e3945145-efa2-4393-b201-f50e1e775008} + + + {38a27e9e-86ad-46f6-a4fb-e1e524267b74} - - util - - - util - - - platform - - - platform - - - platform - - - platform - platform - - platform - - - platform - exports @@ -76,7 +55,6 @@ devices - implementations @@ -95,17 +73,32 @@ devices - + platform - - platform\pthread_win32 + + platform\windows + + + platform\windows - - platform\pthread_win32 + + platform\serialport - - platform\pthread_win32 + + platform\serialport + + + platform\threads + + + platform\threads + + + platform + + + platform @@ -115,18 +108,6 @@ - - platform - - - platform - - - platform - - - platform - implementations @@ -157,8 +138,8 @@ devices - - platform + + platform\serialport diff --git a/project/testclient.vcxproj b/project/testclient.vcxproj index 3397574..1d1a9bd 100644 --- a/project/testclient.vcxproj +++ b/project/testclient.vcxproj @@ -5,10 +5,18 @@ Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + {F01222BF-6B3D-43BD-B254-434031CB9887} @@ -21,47 +29,93 @@ true MultiByte + + Application + true + MultiByte + Application false MultiByte + + Application + false + MultiByte + + + + + + + true $(SolutionDir)..\ cec-client - + true + $(SolutionDir)..\ + cec-client.x64 + + $(SolutionDir)..\ cec-client + + $(SolutionDir)..\ + cec-client.x64 + Level4 Disabled - WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;%(PreprocessorDefinitions) + _USE_32BIT_TIME_T;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions) + true + + + $(SolutiontDir)..\include;%(AdditionalIncludeDirectories) + + + Console + true + %(AdditionalDependencies) + $(SolutionDir)..\$(TargetName)$(TargetExt) + + + + + + + + + Level4 + Disabled + _WIN64;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions) true - 4100;4309;4505 + + $(SolutiontDir)..\include;%(AdditionalIncludeDirectories) Console true - $(ProjectDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib;%(AdditionalDependencies) - $(SolutionDir)..\cec-client.exe + %(AdditionalDependencies) + $(SolutionDir)..\$(TargetName)$(TargetExt) @@ -74,9 +128,34 @@ Full false true - _WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;%(PreprocessorDefinitions) + _USE_32BIT_TIME_T;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions) + true + + + $(SolutionDir)..\include;%(AdditionalIncludeDirectories) + + + Console + false + true + true + %(AdditionalDependencies) + + + + + + + Level4 + + + Full + false + true + _WIN64;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions) true - 4100;4309 + + $(SolutionDir)..\include;%(AdditionalIncludeDirectories) @@ -84,25 +163,25 @@ false true true - $(ProjectDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib;%(AdditionalDependencies) + %(AdditionalDependencies) + $(SolutionDir)..\$(TargetName)$(TargetExt) - - - - - - + + + + + + + - - - + diff --git a/project/testclient.vcxproj.filters b/project/testclient.vcxproj.filters index 4dcb38c..45e1fe0 100644 --- a/project/testclient.vcxproj.filters +++ b/project/testclient.vcxproj.filters @@ -1,62 +1,55 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + {cc0a01c1-e1e7-4af8-9656-fa9463140613} - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd + + {f08c0a80-22d9-4bdd-90de-b9cf5fa88f99} - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {fb28e188-b2a5-48d3-9010-b56024b19850} + + + {a8b22b54-3252-44fb-a499-e42f9bac0e15} - - Header Files + + exports - - Header Files + + exports - - Header Files + + platform - - Header Files + + platform - - Header Files + + platform\windows - - Header Files + + platform\windows - - Header Files + + platform\windows - - Header Files + + platform\threads + + + platform\threads - - Source Files - - - Source Files - - - Source Files - - - Source Files + + + platform\windows - - Resource Files - + \ No newline at end of file diff --git a/pthreadVC2.dll b/pthreadVC2.dll deleted file mode 100644 index fdea676..0000000 Binary files a/pthreadVC2.dll and /dev/null differ diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 9697759..faa15aa 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -33,11 +33,11 @@ #include "AdapterCommunication.h" #include "CECProcessor.h" -#include "platform/os-dependent.h" -#include "platform/serialport.h" +#include "platform/serialport/serialport.h" using namespace std; using namespace CEC; +using namespace PLATFORM; CCECAdapterMessage::CCECAdapterMessage(const cec_command &command) { @@ -248,7 +248,7 @@ CAdapterCommunication::CAdapterCommunication(CCECProcessor *processor) : m_processor(processor), m_iLineTimeout(0) { - m_port = new CSerialPort; + m_port = new PLATFORM::CSerialPort; } CAdapterCommunication::~CAdapterCommunication(void) @@ -267,7 +267,7 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 uint64_t iNow = GetTimeMs(); uint64_t iTimeout = iNow + iTimeoutMs; - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (!m_port) { @@ -307,7 +307,7 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 if (CreateThread()) { - m_startCondition.Wait(&m_mutex); + m_startCondition.Wait(m_mutex); m_processor->AddLog(CEC_LOG_DEBUG, "communication thread started"); return true; } @@ -321,7 +321,7 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 void CAdapterCommunication::Close(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_startCondition.Broadcast(); m_rcvCondition.Broadcast(); StopThread(); @@ -330,7 +330,7 @@ void CAdapterCommunication::Close(void) void *CAdapterCommunication::Process(void) { { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_startCondition.Signal(); } @@ -371,7 +371,7 @@ bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout) void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); for (uint8_t iPtr = 0; iPtr < iLen; iPtr++) m_inBuffer.Push(data[iPtr]); @@ -387,8 +387,8 @@ void CAdapterCommunication::WriteNextCommand(void) void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg) { - CLockObject lock(&msg->mutex); - if (m_port->Write(msg) != (int32_t) msg->size()) + CLockObject lock(msg->mutex); + if (m_port->Write(msg->packet.data, msg->size()) != (int32_t) msg->size()) { CStdString strError; strError.Format("error writing to serial port: %s", m_port->GetError().c_str()); @@ -412,7 +412,7 @@ bool CAdapterCommunication::Write(CCECAdapterMessage *data) bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); msg.clear(); uint64_t iNow = GetTimeMs(); @@ -426,7 +426,7 @@ bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout) uint8_t buf = 0; if (!m_inBuffer.Pop(buf)) { - if (!m_rcvCondition.Wait(&m_mutex, (uint32_t) (iTarget - iNow))) + if (!m_rcvCondition.Wait(m_mutex, (uint32_t) (iTarget - iNow))) return false; } @@ -483,9 +483,9 @@ bool CAdapterCommunication::StartBootloader(void) output->push_escaped(MSGCODE_START_BOOTLOADER); output->push_back(MSGEND); - CLockObject lock(&output->mutex); + CLockObject lock(output->mutex); if (Write(output)) - output->condition.Wait(&output->mutex); + output->condition.Wait(output->mutex); bReturn = output->state == ADAPTER_MESSAGE_STATE_SENT; delete output; @@ -505,9 +505,9 @@ bool CAdapterCommunication::PingAdapter(void) output->push_escaped(MSGCODE_PING); output->push_back(MSGEND); - CLockObject lock(&output->mutex); + CLockObject lock(output->mutex); if (Write(output)) - output->condition.Wait(&output->mutex); + output->condition.Wait(output->mutex); bReturn = output->state == ADAPTER_MESSAGE_STATE_SENT; delete output; @@ -535,7 +535,7 @@ bool CAdapterCommunication::SetLineTimeout(uint8_t iTimeout) return bReturn; } -bool CAdapterCommunication::IsOpen(void) const +bool CAdapterCommunication::IsOpen(void) { return !IsStopped() && m_port->IsOpen() && IsRunning(); } diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index d076a2f..97cd18d 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -32,9 +32,12 @@ */ #include -#include "util/buffer.h" -#include -#include "util/StdString.h" +#include "platform/os.h" + +namespace PLATFORM +{ + class CSerialPort; +} namespace CEC { @@ -85,14 +88,13 @@ namespace CEC cec_datapacket packet; cec_adapter_message_state state; int32_t transmit_timeout; - CMutex mutex; - CCondition condition; + PLATFORM::CMutex mutex; + PLATFORM::CCondition condition; }; - class CSerialPort; class CCECProcessor; - class CAdapterCommunication : private CThread + class CAdapterCommunication : private PLATFORM::CThread { public: CAdapterCommunication(CCECProcessor *processor); @@ -103,7 +105,7 @@ namespace CEC bool Write(CCECAdapterMessage *data); bool PingAdapter(void); void Close(void); - bool IsOpen(void) const; + bool IsOpen(void); std::string GetError(void) const; void *Process(void); @@ -117,13 +119,13 @@ namespace CEC void AddData(uint8_t *data, uint8_t iLen); bool ReadFromDevice(uint32_t iTimeout); - CSerialPort * m_port; - CCECProcessor * m_processor; - CecBuffer m_inBuffer; - CecBuffer m_outBuffer; - CMutex m_mutex; - CCondition m_rcvCondition; - CCondition m_startCondition; - uint8_t m_iLineTimeout; + PLATFORM::CSerialPort * m_port; + CCECProcessor * m_processor; + PLATFORM::SyncedBuffer m_inBuffer; + PLATFORM::SyncedBuffer m_outBuffer; + PLATFORM::CMutex m_mutex; + PLATFORM::CCondition m_rcvCondition; + PLATFORM::CCondition m_startCondition; + uint8_t m_iLineTimeout; }; }; diff --git a/src/lib/AdapterDetection.cpp b/src/lib/AdapterDetection.cpp index f068099..168f1a4 100644 --- a/src/lib/AdapterDetection.cpp +++ b/src/lib/AdapterDetection.cpp @@ -31,8 +31,7 @@ */ #include "AdapterDetection.h" -#include "platform/os-dependent.h" -#include "util/StdString.h" +#include "platform/os.h" #if defined(__APPLE__) #include diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 798c38a..9ed9b23 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -41,11 +41,10 @@ #include "devices/CECTV.h" #include "implementations/CECCommandHandler.h" #include "LibCEC.h" -#include "util/StdString.h" -#include "platform/timeutils.h" using namespace CEC; using namespace std; +using namespace PLATFORM; CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : m_bStarted(false), @@ -134,7 +133,7 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, bool bReturn(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); /* check for an already opened connection */ if (!m_communication || m_communication->IsOpen()) @@ -151,7 +150,7 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, } /* create the processor thread */ - if (!CreateThread() || !m_startCondition.Wait(&m_mutex) || !m_bStarted) + if (!CreateThread() || !m_startCondition.Wait(m_mutex) || !m_bStarted) { m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); return bReturn; @@ -240,7 +239,7 @@ bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to) strLog.Format("changing device type '%s' into '%s'", ToString(from), ToString(to)); AddLog(CEC_LOG_NOTICE, strLog); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CCECBusDevice *previousDevice = GetDeviceByType(from); m_logicalAddresses.primary = CECDEVICE_UNKNOWN; @@ -354,7 +353,7 @@ void *CCECProcessor::Process(void) CCECAdapterMessage msg; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_bStarted = true; m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); m_startCondition.Signal(); @@ -367,7 +366,7 @@ void *CCECProcessor::Process(void) msg.clear(); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_commandBuffer.Pop(command)) { bParseFrame = true; @@ -447,13 +446,13 @@ bool CCECProcessor::SetActiveSource(uint16_t iStreamPath) void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_iStandardLineTimeout = iTimeout; } void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_iRetryLineTimeout = iTimeout; } @@ -497,7 +496,7 @@ bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true * bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */) { bool bReturn(false); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_iBaseDevice = iBaseDevice; m_iHDMIPort = iPort; @@ -511,7 +510,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, uint16_t iPhysicalAddress(0); if (iBaseDevice > CECDEVICE_TV) { - lock.Leave(); + lock.Unlock(); iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress(); lock.Lock(); } @@ -534,7 +533,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, m_controller->AddLog(CEC_LOG_ERROR, "failed to set the physical address"); else { - lock.Leave(); + lock.Unlock(); SetPhysicalAddress(iPhysicalAddress); } @@ -575,7 +574,7 @@ void CCECProcessor::LogOutput(const cec_command &data) bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_logicalAddresses.primary != iLogicalAddress) { CStdString strLog; @@ -610,7 +609,7 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpda cec_logical_addresses sendUpdatesTo; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (!m_logicalAddresses.IsEmpty()) { bool bWasActiveSource(false); @@ -646,7 +645,7 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable) m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_bMonitor = bEnable; } @@ -827,7 +826,7 @@ bool CCECProcessor::Transmit(const cec_command &data) bool CCECProcessor::Transmit(CCECAdapterMessage *output) { bool bReturn(false); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); { m_iLastTransmission = GetTimeMs(); m_communication->SetLineTimeout(m_iStandardLineTimeout); @@ -838,12 +837,12 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) if (output->tries > 0) m_communication->SetLineTimeout(m_iRetryLineTimeout); - CLockObject msgLock(&output->mutex); + CLockObject msgLock(output->mutex); if (!m_communication || !m_communication->Write(output)) return bReturn; else { - output->condition.Wait(&output->mutex); + output->condition.Wait(output->mutex); if (output->state != ADAPTER_MESSAGE_STATE_SENT) { m_controller->AddLog(CEC_LOG_ERROR, "command was not sent"); diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 5064b9c..8e6fae9 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -34,9 +34,7 @@ #include #include #include "AdapterCommunication.h" -#include "platform/os-dependent.h" -#include "util/buffer.h" -#include "util/StdString.h" +#include "platform/os.h" class CSerialPort; @@ -46,7 +44,7 @@ namespace CEC class CAdapterCommunication; class CCECBusDevice; - class CCECProcessor : public CThread + class CCECProcessor : public PLATFORM::CThread { public: CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); @@ -132,8 +130,8 @@ namespace CEC virtual bool StartBootloader(void); virtual bool PingAdapter(void); - CCECBusDevice *m_busDevices[16]; - CMutex m_transmitMutex; + CCECBusDevice * m_busDevices[16]; + PLATFORM::CMutex m_transmitMutex; private: void ReplaceHandlers(void); @@ -150,30 +148,30 @@ namespace CEC bool ParseMessage(const CCECAdapterMessage &msg); void ParseCommand(cec_command &command); - bool m_bStarted; - bool m_bInitialised; - uint8_t m_iHDMIPort; - cec_logical_address m_iBaseDevice; - cec_command m_currentframe; - cec_logical_addresses m_logicalAddresses; - cec_logical_address m_lastInitiator; - std::string m_strDeviceName; - cec_device_type_list m_types; - CMutex m_mutex; - CCondition m_startCondition; - CAdapterCommunication* m_communication; - CLibCEC* m_controller; - bool m_bMonitor; - CecBuffer m_commandBuffer; - cec_keypress m_previousKey; - CThread * m_busScan; - uint8_t m_iLineTimeout; - uint8_t m_iStandardLineTimeout; - uint8_t m_iRetryLineTimeout; - uint64_t m_iLastTransmission; + bool m_bStarted; + bool m_bInitialised; + uint8_t m_iHDMIPort; + cec_logical_address m_iBaseDevice; + cec_command m_currentframe; + cec_logical_addresses m_logicalAddresses; + cec_logical_address m_lastInitiator; + std::string m_strDeviceName; + cec_device_type_list m_types; + PLATFORM::CMutex m_mutex; + PLATFORM::CCondition m_startCondition; + CAdapterCommunication* m_communication; + CLibCEC* m_controller; + bool m_bMonitor; + PLATFORM::SyncedBuffer m_commandBuffer; + cec_keypress m_previousKey; + PLATFORM::CThread * m_busScan; + uint8_t m_iLineTimeout; + uint8_t m_iStandardLineTimeout; + uint8_t m_iRetryLineTimeout; + uint64_t m_iLastTransmission; }; - class CCECBusScan : public CThread + class CCECBusScan : public PLATFORM::CThread { public: CCECBusScan(CCECProcessor *processor) { m_processor = processor; } diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 52dfa51..29cc3f4 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -36,11 +36,11 @@ #include "AdapterDetection.h" #include "CECProcessor.h" #include "devices/CECBusDevice.h" -#include "util/StdString.h" #include "platform/timeutils.h" using namespace std; using namespace CEC; +using namespace PLATFORM; CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types) : m_iStartTime(GetTimeMs()), @@ -93,7 +93,7 @@ void CLibCEC::Close(void) bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_cec) { m_cbParam = cbParam; @@ -343,7 +343,7 @@ cec_osd_name CLibCEC::GetDeviceOSDName(cec_logical_address iAddress) void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_cec) { cec_log_message message; @@ -360,7 +360,7 @@ void CLibCEC::AddLog(cec_log_level level, const string &strMessage) void CLibCEC::AddKey(cec_keypress &key) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_callbacks) m_callbacks->CBCecKeyPress(m_cbParam, key); else @@ -371,7 +371,7 @@ void CLibCEC::AddKey(cec_keypress &key) void CLibCEC::AddKey(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN) { cec_keypress key; @@ -390,7 +390,7 @@ void CLibCEC::AddKey(void) void CLibCEC::AddCommand(const cec_command &command) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_callbacks) { m_callbacks->CBCecCommand(m_cbParam, command); diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index ef1ded2..20b6ccd 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -33,7 +33,7 @@ #include #include -#include "util/buffer.h" +#include "platform/os.h" namespace CEC { @@ -120,15 +120,15 @@ namespace CEC virtual void SetCurrentButton(cec_user_control_code iButtonCode); protected: - int64_t m_iStartTime; - cec_user_control_code m_iCurrentButton; - int64_t m_buttontime; - CCECProcessor *m_cec; - CecBuffer m_logBuffer; - CecBuffer m_keyBuffer; - CecBuffer m_commandBuffer; - ICECCallbacks *m_callbacks; - void *m_cbParam; - CMutex m_mutex; + int64_t m_iStartTime; + cec_user_control_code m_iCurrentButton; + int64_t m_buttontime; + CCECProcessor * m_cec; + PLATFORM::SyncedBuffer m_logBuffer; + PLATFORM::SyncedBuffer m_keyBuffer; + PLATFORM::SyncedBuffer m_commandBuffer; + ICECCallbacks * m_callbacks; + void * m_cbParam; + PLATFORM::CMutex m_mutex; }; }; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index adcbafa..9ccd4c7 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -23,9 +23,7 @@ libcec_la_SOURCES = AdapterCommunication.cpp \ implementations/CECCommandHandler.cpp \ implementations/SLCommandHandler.cpp \ implementations/VLCommandHandler.cpp \ - platform/posix/serialport.cpp \ - platform/posix/pthreads.cpp \ - platform/threads.cpp + platform/posix/serialport.cpp libcec_la_LDFLAGS = @LIBS@ -version-info @VERSION@ libcec_la_CPPFLAGS = -I@abs_top_srcdir@/include diff --git a/src/lib/devices/CECAudioSystem.cpp b/src/lib/devices/CECAudioSystem.cpp index 87b4505..7bdb091 100644 --- a/src/lib/devices/CECAudioSystem.cpp +++ b/src/lib/devices/CECAudioSystem.cpp @@ -35,6 +35,7 @@ #include "../implementations/CECCommandHandler.h" using namespace CEC; +using namespace PLATFORM; #define ToString(p) m_processor->ToString(p) @@ -48,7 +49,7 @@ CCECAudioSystem::CCECAudioSystem(CCECProcessor *processor, cec_logical_address a bool CCECAudioSystem::SetAudioStatus(uint8_t status) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_audioStatus != status) { CStdString strLog; @@ -64,7 +65,7 @@ bool CCECAudioSystem::SetAudioStatus(uint8_t status) bool CCECAudioSystem::SetSystemAudioModeStatus(const cec_system_audio_status mode) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_systemAudioStatus != mode) { CStdString strLog; @@ -82,7 +83,7 @@ bool CCECAudioSystem::TransmitAudioStatus(cec_logical_address dest) { uint8_t state; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %x -> %x: audio status '%2x'", m_iLogicalAddress, dest, m_audioStatus); AddLog(CEC_LOG_NOTICE, strLog); @@ -96,7 +97,7 @@ bool CCECAudioSystem::TransmitSetSystemAudioMode(cec_logical_address dest) { cec_system_audio_status state; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %x -> %x: set system audio mode '%2x'", m_iLogicalAddress, dest, m_audioStatus); AddLog(CEC_LOG_NOTICE, strLog); @@ -110,7 +111,7 @@ bool CCECAudioSystem::TransmitSystemAudioModeStatus(cec_logical_address dest) { cec_system_audio_status state; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %x -> %x: system audio mode '%s'", m_iLogicalAddress, dest, ToString(m_systemAudioStatus)); AddLog(CEC_LOG_NOTICE, strLog); @@ -125,7 +126,7 @@ uint8_t CCECAudioSystem::VolumeUp(bool bSendRelease /* = true */) if (TransmitKeypress(CEC_USER_CONTROL_CODE_VOLUME_UP) && bSendRelease) TransmitKeyRelease(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_audioStatus; } @@ -134,7 +135,7 @@ uint8_t CCECAudioSystem::VolumeDown(bool bSendRelease /* = true */) if (TransmitKeypress(CEC_USER_CONTROL_CODE_VOLUME_DOWN) && bSendRelease) TransmitKeyRelease(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_audioStatus; } @@ -143,6 +144,6 @@ uint8_t CCECAudioSystem::MuteAudio(bool bSendRelease /* = true */) if (TransmitKeypress(CEC_USER_CONTROL_CODE_MUTE) && bSendRelease) TransmitKeyRelease(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_audioStatus; } diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index d6e447f..a907fc8 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -36,9 +36,9 @@ #include "../implementations/CECCommandHandler.h" #include "../implementations/SLCommandHandler.h" #include "../implementations/VLCommandHandler.h" -#include "../platform/timeutils.h" using namespace CEC; +using namespace PLATFORM; #define ToString(p) m_processor->ToString(p) @@ -56,8 +56,7 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi m_iLastActive(0), m_iLastPowerStateUpdate(0), m_cecVersion(CEC_VERSION_UNKNOWN), - m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN), - m_handlerMutex(false) + m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN) { m_handler = new CCECCommandHandler(this); @@ -85,7 +84,7 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) /* update "last active" */ { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_iLastActive = GetTimeMs(); if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) @@ -98,7 +97,7 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) /* change status to present */ if (bHandled) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) { if (m_deviceStatus != CEC_DEVICE_STATUS_PRESENT) @@ -123,7 +122,7 @@ bool CCECBusDevice::PowerOn(void) if (m_handler->TransmitImageViewOn(GetMyLogicalAddress(), m_iLogicalAddress)) { { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); // m_powerStatus = CEC_POWER_STATUS_UNKNOWN; m_powerStatus = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON; } @@ -159,7 +158,7 @@ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */) { bool bRequestUpdate(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN)); } @@ -167,7 +166,7 @@ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */) if (bRequestUpdate) RequestCecVersion(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_cecVersion; } @@ -197,7 +196,7 @@ cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */) { bool bRequestUpdate(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && (bUpdate || !strcmp(m_menuLanguage.language, "???"))); } @@ -205,7 +204,7 @@ cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */) if (bRequestUpdate) RequestMenuLanguage(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_menuLanguage; } @@ -228,7 +227,7 @@ bool CCECBusDevice::RequestMenuLanguage(void) cec_menu_state CCECBusDevice::GetMenuState(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_menuState; } @@ -246,7 +245,7 @@ CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */) { bool bRequestUpdate(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) && m_type != CEC_DEVICE_TYPE_TV); @@ -255,7 +254,7 @@ CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */) if (bRequestUpdate) RequestOSDName(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_strDeviceName; } @@ -280,7 +279,7 @@ uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */) { bool bRequestUpdate(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && (m_iPhysicalAddress == 0xFFFF || bUpdate)); } @@ -288,7 +287,7 @@ uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */) if (bRequestUpdate && !RequestPhysicalAddress()) AddLog(CEC_LOG_ERROR, "failed to request the physical address (1)"); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_iPhysicalAddress; } @@ -312,7 +311,7 @@ cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */) { bool bRequestUpdate(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN || m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON || @@ -323,7 +322,7 @@ cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */) if (bRequestUpdate) RequestPowerStatus(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_powerStatus; } @@ -348,7 +347,7 @@ cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */) { bool bRequestUpdate(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT && (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN)); } @@ -356,7 +355,7 @@ cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */) if (bRequestUpdate) RequestVendorId(); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_vendor; } @@ -437,11 +436,11 @@ bool CCECBusDevice::NeedsPoll(void) cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll)) { - lock.Leave(); + lock.Unlock(); bool bPollAcked(false); if (bForcePoll || NeedsPoll()) bPollAcked = m_processor->PollDevice(m_iLogicalAddress); @@ -468,7 +467,7 @@ void CCECBusDevice::SetCecVersion(const cec_version newVersion) void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (language.device == m_iLogicalAddress) { CStdString strLog; @@ -480,7 +479,7 @@ void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) void CCECBusDevice::SetOSDName(CStdString strName) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_strDeviceName != strName) { CStdString strLog; @@ -492,7 +491,7 @@ void CCECBusDevice::SetOSDName(CStdString strName) void CCECBusDevice::SetMenuState(const cec_menu_state state) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_menuState != state) { CStdString strLog; @@ -505,7 +504,7 @@ void CCECBusDevice::SetMenuState(const cec_menu_state state) void CCECBusDevice::SetInactiveSource(void) { { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_bActiveSource = false; } @@ -515,7 +514,7 @@ void CCECBusDevice::SetInactiveSource(void) void CCECBusDevice::SetActiveSource(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (!m_bActiveSource) { CStdString strLog; @@ -555,7 +554,7 @@ bool CCECBusDevice::TryLogicalAddress(void) void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); switch (newStatus) { case CEC_DEVICE_STATUS_UNKNOWN: @@ -587,7 +586,7 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus) void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress) { CStdString strLog; @@ -600,7 +599,7 @@ void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (iNewAddress > 0) { CStdString strLog; @@ -611,7 +610,7 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* if (iNewAddress > 0) { - lock.Leave(); + lock.Unlock(); SetPowerStatus(CEC_POWER_STATUS_ON); } } @@ -619,7 +618,7 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_powerStatus != powerStatus) { m_iLastPowerStateUpdate = GetTimeMs(); @@ -632,8 +631,8 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) { - CLockObject lock(&m_mutex); - CLockObject handlerLock(&m_handlerMutex); + CLockObject lock(m_mutex); + CLockObject handlerLock(m_handlerMutex); if (m_vendor != m_handler->GetVendorId()) { @@ -683,7 +682,7 @@ bool CCECBusDevice::SetVendorId(uint64_t iVendorId) bool bVendorChanged(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); bVendorChanged = (m_vendor != (cec_vendor_id)iVendorId); m_vendor = (cec_vendor_id)iVendorId; } @@ -703,7 +702,7 @@ bool CCECBusDevice::TransmitActiveSource(void) bool bSendActiveSource(false); { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_powerStatus != CEC_POWER_STATUS_ON) { CStdString strLog; @@ -739,7 +738,7 @@ bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest) { cec_version version; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion)); AddLog(CEC_LOG_NOTICE, strLog); @@ -753,7 +752,7 @@ bool CCECBusDevice::TransmitInactiveSource(void) { uint16_t iPhysicalAddress; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress); AddLog(CEC_LOG_NOTICE, strLog); @@ -767,7 +766,7 @@ bool CCECBusDevice::TransmitMenuState(cec_logical_address dest) { cec_menu_state menuState; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); AddLog(CEC_LOG_NOTICE, strLog); @@ -781,7 +780,7 @@ bool CCECBusDevice::TransmitOSDName(cec_logical_address dest) { CStdString strDeviceName; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str()); AddLog(CEC_LOG_NOTICE, strLog.c_str()); @@ -809,7 +808,7 @@ bool CCECBusDevice::TransmitPhysicalAddress(void) uint16_t iPhysicalAddress; cec_device_type type; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_iPhysicalAddress == 0xffff) return false; @@ -840,7 +839,7 @@ bool CCECBusDevice::TransmitPoll(cec_logical_address dest) bReturn = m_handler->TransmitPoll(m_iLogicalAddress, dest); AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (bReturn) { m_iLastActive = GetTimeMs(); @@ -856,7 +855,7 @@ bool CCECBusDevice::TransmitPowerState(cec_logical_address dest) { cec_power_status state; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus)); AddLog(CEC_LOG_NOTICE, strLog.c_str()); @@ -870,7 +869,7 @@ bool CCECBusDevice::TransmitVendorID(cec_logical_address dest, bool bSendAbort / { uint64_t iVendorId; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); iVendorId = (uint64_t)m_vendor; } @@ -918,7 +917,7 @@ void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode) bool CCECBusDevice::ActivateSource(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_handler->ActivateSource(); } diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 5d835c7..412504e 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -33,8 +33,7 @@ #include #include -#include "../platform/os-dependent.h" -#include "../util/StdString.h" +#include "../platform/os.h" namespace CEC { @@ -136,7 +135,7 @@ namespace CEC cec_version m_cecVersion; cec_bus_device_status m_deviceStatus; std::set m_unsupportedFeatures; - CMutex m_mutex; - CMutex m_handlerMutex; + PLATFORM::CMutex m_mutex; + PLATFORM::CMutex m_handlerMutex; }; }; diff --git a/src/lib/devices/CECPlaybackDevice.cpp b/src/lib/devices/CECPlaybackDevice.cpp index 4969de5..f9689cb 100644 --- a/src/lib/devices/CECPlaybackDevice.cpp +++ b/src/lib/devices/CECPlaybackDevice.cpp @@ -35,6 +35,7 @@ #include "../CECProcessor.h" using namespace CEC; +using namespace PLATFORM; #define ToString(p) m_processor->ToString(p) @@ -48,13 +49,13 @@ CCECPlaybackDevice::CCECPlaybackDevice(CCECProcessor *processor, cec_logical_add cec_deck_info CCECPlaybackDevice::GetDeckStatus(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_deckStatus; } void CCECPlaybackDevice::SetDeckStatus(cec_deck_info deckStatus) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_deckStatus != deckStatus && m_deckStatus != CEC_DECK_INFO_OTHER_STATUS_LG) { CStdString strLog; @@ -67,13 +68,13 @@ void CCECPlaybackDevice::SetDeckStatus(cec_deck_info deckStatus) cec_deck_control_mode CCECPlaybackDevice::GetDeckControlMode(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_deckControlMode; } void CCECPlaybackDevice::SetDeckControlMode(cec_deck_control_mode mode) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_deckControlMode != mode) { CStdString strLog; @@ -88,7 +89,7 @@ bool CCECPlaybackDevice::TransmitDeckStatus(cec_logical_address dest) { cec_deck_info state; { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): deck status '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_deckStatus)); AddLog(CEC_LOG_NOTICE, strLog); diff --git a/src/lib/implementations/ANCommandHandler.cpp b/src/lib/implementations/ANCommandHandler.cpp index 248a959..bf9dea5 100644 --- a/src/lib/implementations/ANCommandHandler.cpp +++ b/src/lib/implementations/ANCommandHandler.cpp @@ -33,7 +33,6 @@ #include "ANCommandHandler.h" #include "../devices/CECBusDevice.h" #include "../CECProcessor.h" -#include "../util/StdString.h" using namespace CEC; diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 5df30f4..d407e40 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -38,6 +38,7 @@ using namespace CEC; using namespace std; +using namespace PLATFORM; CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) : m_busDevice(busDevice), @@ -55,8 +56,8 @@ CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) : CCECCommandHandler::~CCECCommandHandler(void) { - CLockObject lock(&m_processor->m_transmitMutex); - CLockObject receiveLock(&m_receiveMutex); + CLockObject lock(m_processor->m_transmitMutex); + CLockObject receiveLock(m_receiveMutex); m_condition.Broadcast(); } @@ -194,7 +195,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) if (bHandled) { - CLockObject lock(&m_receiveMutex); + CLockObject lock(m_receiveMutex); if (m_expectedResponse == CEC_OPCODE_NONE || m_expectedResponse == command.opcode) m_condition.Signal(); @@ -426,7 +427,7 @@ bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); vector devices; - for (int iDevicePtr = GetMyDevices(devices) - 1; iDevicePtr >=0; iDevicePtr--) + for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++) devices[iDevicePtr]->TransmitActiveSource(); return true; @@ -964,8 +965,8 @@ bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* { uint8_t iTries(0), iMaxTries(command.opcode == CEC_OPCODE_NONE ? 1 : m_iTransmitRetries + 1); - CLockObject writeLock(&m_processor->m_transmitMutex); - CLockObject receiveLock(&m_receiveMutex); + CLockObject writeLock(m_processor->m_transmitMutex); + CLockObject receiveLock(m_receiveMutex); ++m_iUseCounter; while (!bReturn && ++iTries <= iMaxTries) { @@ -974,7 +975,7 @@ bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* { m_processor->AddLog(CEC_LOG_DEBUG, "command transmitted"); bReturn = bExpectResponse ? - m_condition.Wait(&m_receiveMutex, m_iTransmitWait) : + m_condition.Wait(m_receiveMutex, m_iTransmitWait) : true; } } @@ -1005,18 +1006,18 @@ bool CCECCommandHandler::ActivateSource(void) void CCECCommandHandler::MarkBusy(void) { - CLockObject receiveLock(&m_receiveMutex); + CLockObject receiveLock(m_receiveMutex); ++m_iUseCounter; } bool CCECCommandHandler::MarkReady(void) { - CLockObject receiveLock(&m_receiveMutex); + CLockObject receiveLock(m_receiveMutex); return m_iUseCounter > 0 ? (--m_iUseCounter == 0) : true; } bool CCECCommandHandler::InUse(void) { - CLockObject receiveLock(&m_receiveMutex); + CLockObject receiveLock(m_receiveMutex); return m_iUseCounter > 0; } diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index f3d3d0c..f1e0924 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -33,8 +33,7 @@ #include #include -#include "../util/StdString.h" -#include "../platform/os-dependent.h" +#include "../platform/os.h" namespace CEC { @@ -135,17 +134,17 @@ namespace CEC virtual bool Transmit(cec_command &command, bool bExpectResponse = true, cec_opcode expectedResponse = CEC_OPCODE_NONE); - CCECBusDevice *m_busDevice; - CCECProcessor *m_processor; - int32_t m_iTransmitTimeout; - int32_t m_iTransmitWait; - int8_t m_iTransmitRetries; - bool m_bHandlerInited; - uint8_t m_iUseCounter; - cec_opcode m_expectedResponse; - bool m_bOPTSendDeckStatusUpdateOnActiveSource; - cec_vendor_id m_vendorId; - CMutex m_receiveMutex; - CCondition m_condition; + CCECBusDevice * m_busDevice; + CCECProcessor * m_processor; + int32_t m_iTransmitTimeout; + int32_t m_iTransmitWait; + int8_t m_iTransmitRetries; + bool m_bHandlerInited; + uint8_t m_iUseCounter; + cec_opcode m_expectedResponse; + bool m_bOPTSendDeckStatusUpdateOnActiveSource; + cec_vendor_id m_vendorId; + PLATFORM::CMutex m_receiveMutex; + PLATFORM::CCondition m_condition; }; }; diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index 7a357d3..67018a8 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -34,8 +34,6 @@ #include "../devices/CECBusDevice.h" #include "../devices/CECPlaybackDevice.h" #include "../CECProcessor.h" -#include "../platform/timeutils.h" -#include "../platform/threads.h" using namespace CEC; diff --git a/src/lib/util/StdString.h b/src/lib/platform/StdString.h similarity index 100% rename from src/lib/util/StdString.h rename to src/lib/platform/StdString.h diff --git a/src/lib/util/buffer.h b/src/lib/platform/buffer.h similarity index 89% rename from src/lib/util/buffer.h rename to src/lib/platform/buffer.h index e0afddf..227b756 100644 --- a/src/lib/util/buffer.h +++ b/src/lib/platform/buffer.h @@ -31,22 +31,23 @@ * http://www.pulse-eight.net/ */ -#include "../platform/os-dependent.h" +#include "os.h" #include -namespace CEC +namespace PLATFORM { template - struct CecBuffer + struct SyncedBuffer { public: - CecBuffer(size_t iMaxSize = 100) + SyncedBuffer(size_t iMaxSize = 100) { m_maxSize = iMaxSize; } - virtual ~CecBuffer(void) + virtual ~SyncedBuffer(void) { + CLockObject lock(m_mutex, true); Clear(); } @@ -60,7 +61,7 @@ namespace CEC bool Push(_BType entry) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_buffer.size() == m_maxSize) return false; @@ -71,7 +72,7 @@ namespace CEC bool Pop(_BType &entry) { bool bReturn(false); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (!m_buffer.empty()) { entry = m_buffer.front(); diff --git a/src/lib/platform/os-dependent.h b/src/lib/platform/os-dependent.h deleted file mode 100644 index 90e42ab..0000000 --- a/src/lib/platform/os-dependent.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once -/* - * Copyright (C) 2005-2011 Team XBMC - * http://www.xbmc.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#if defined(_WIN32) || defined(_WIN64) -#ifndef __WINDOWS__ -#define __WINDOWS__ -#endif -#endif - -#if defined(__WINDOWS__) -#include "windows/os_windows.h" -#else -#include "posix/os_posix.h" -#endif - -#if !defined(TRUE) -#define TRUE 1 -#endif - -#if !defined(FALSE) -#define FALSE 0 -#endif - -#include "timeutils.h" diff --git a/src/lib/platform/threads.cpp b/src/lib/platform/os.h similarity index 52% rename from src/lib/platform/threads.cpp rename to src/lib/platform/os.h index c9f6c16..fbe0903 100644 --- a/src/lib/platform/threads.cpp +++ b/src/lib/platform/os.h @@ -1,3 +1,4 @@ +#pragma once /* * This file is part of the libCEC(R) library. * @@ -30,74 +31,18 @@ * http://www.pulse-eight.net/ */ -#include "threads.h" -#include "timeutils.h" -#include "os-dependent.h" - -using namespace CEC; - -CLockObject::CLockObject(IMutex *mutex, bool bTryLock /* = false */) : - m_mutex(mutex) -{ - if (m_mutex) - m_bLocked = bTryLock ? m_mutex->TryLock() : m_mutex->Lock(); -} - -CLockObject::~CLockObject(void) -{ - Leave(); - m_mutex = NULL; -} - -void CLockObject::Leave(void) -{ - if (m_mutex && m_bLocked) - { - m_bLocked = false; - m_mutex->Unlock(); - } -} - -void CLockObject::Lock(void) -{ - if (m_mutex) - m_bLocked = m_mutex->Lock(); -} +#if defined(_WIN32) || defined(_WIN64) +#ifndef __WINDOWS__ +#define __WINDOWS__ +#endif +#include "windows/os-types.h" +#include "windows/os-threads.h" +#else +#include "posix/os-types.h" +#include "posix/os-threads.h" +#endif -void ICondition::Sleep(uint32_t iTimeout) -{ - CCondition w; - CMutex m; - CLockObject lock(&m); - w.Wait(&m, iTimeout); -} - -IThread::IThread(void) : - m_bStop(false), - m_bRunning(false) -{ - m_threadCondition = new CCondition(); - m_threadMutex = new CMutex(); -} - -IThread::~IThread(void) -{ - StopThread(); - delete m_threadCondition; - delete m_threadMutex; -} - -bool IThread::StopThread(bool bWaitForExit /* = true */) -{ - m_bStop = true; - m_threadCondition->Broadcast(); - bWaitForExit = true; - - return false; -} - -bool IThread::Sleep(uint32_t iTimeout) -{ - CLockObject lock(m_threadMutex); - return m_bStop ? false : m_threadCondition->Wait(m_threadMutex, iTimeout); -} +#include "timeutils.h" +#include "threads/threads.h" +#include "buffer.h" +#include "StdString.h" diff --git a/src/lib/platform/posix/os-threads.h b/src/lib/platform/posix/os-threads.h new file mode 100644 index 0000000..9f7a688 --- /dev/null +++ b/src/lib/platform/posix/os-threads.h @@ -0,0 +1,87 @@ +#pragma once +/* + * This file is part of the libCEC(R) library. + * + * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is an original work, containing original code. + * + * libCEC(R) is a trademark of Pulse-Eight Limited. + * + * This program is dual-licensed; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * Alternatively, you can license this library under a commercial license, + * please contact Pulse-Eight Licensing for more information. + * + * For more information contact: + * Pulse-Eight Licensing + * http://www.pulse-eight.com/ + * http://www.pulse-eight.net/ + */ + +namespace PLATFORM +{ + inline pthread_mutexattr_t *GetRecursiveMutexAttribute(void) + { + static pthread_mutexattr_t g_mutexAttr; + static bool bAttributeInitialised = false; + if (!bAttributeInitialised) + { + pthread_mutexattr_init(&g_mutexAttr); + pthread_mutexattr_settype(&g_mutexAttr, PTHREAD_MUTEX_RECURSIVE); + bAttributeInitialised = true; + } + return &g_mutexAttr; + } + + inline struct timespec GetAbsTime(uint64_t iIncreaseBy = 0) + { + struct timespec abstime; + struct timeval now; + gettimeofday(&now, NULL); + iIncreaseBy += now.tv_usec / 1000; + abstime.tv_sec = now.tv_sec + (time_t)(iIncreaseBy / 1000); + abstime.tv_nsec = (int32_t)((iIncreaseBy % (uint32_t)1000) * (uint32_t)1000000); + return abstime; + } + + typedef pthread_t thread_t; + + #define ThreadsCreate(thread, func, arg) (pthread_create(&thread, NULL, (void *(*) (void *))func, (void *)arg) == 0) + #define ThreadsWait(thread, retval) (pthread_join(thread, retval) == 0) + + typedef pthread_mutex_t mutex_t; + #define MutexCreate(mutex) pthread_mutex_init(&mutex, GetRecursiveMutexAttribute()); + #define MutexDelete(mutex) pthread_mutex_destroy(&mutex); + #define MutexLock(mutex) (pthread_mutex_lock(&mutex) == 0) + #define MutexTryLock(mutex) (pthread_mutex_trylock(&mutex) == 0) + #define MutexUnlock(mutex) pthread_mutex_unlock(&mutex) + + typedef pthread_cond_t condition_t; + #define ConditionCreate(cond) pthread_cond_init(&cond, NULL) + #define ConditionDelete(cond) pthread_cond_destroy(&cond) + #define ConditionSignal(cond) pthread_cond_signal(&cond) + #define ConditionBroadcast(cond) pthread_cond_broadcast(&cond) + inline bool ConditionWait(condition_t &cond, mutex_t &mutex, uint32_t iTimeout) + { + sched_yield(); + if (iTimeout > 0) + { + struct timespec timeout = GetAbsTime(iTimeout); + return (pthread_cond_timedwait(&cond, &mutex, &timeout) == 0); + } + return (pthread_cond_wait(&cond, &mutex) == 0); + } +} diff --git a/src/lib/platform/posix/os_posix.h b/src/lib/platform/posix/os-types.h similarity index 95% rename from src/lib/platform/posix/os_posix.h rename to src/lib/platform/posix/os-types.h index 65d2f27..99bacb3 100644 --- a/src/lib/platform/posix/os_posix.h +++ b/src/lib/platform/posix/os-types.h @@ -23,12 +23,13 @@ #include #include #ifndef __APPLE__ -#include +#include #endif #include #include #include +#include #define LIBTYPE #define DECLSPEC -#include "pthreads.h" + diff --git a/src/lib/platform/posix/pthreads.cpp b/src/lib/platform/posix/pthreads.cpp deleted file mode 100644 index e5b4cf1..0000000 --- a/src/lib/platform/posix/pthreads.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * This file is part of the libCEC(R) library. - * - * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. - * libCEC(R) is an original work, containing original code. - * - * libCEC(R) is a trademark of Pulse-Eight Limited. - * - * This program is dual-licensed; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * Alternatively, you can license this library under a commercial license, - * please contact Pulse-Eight Licensing for more information. - * - * For more information contact: - * Pulse-Eight Licensing - * http://www.pulse-eight.com/ - * http://www.pulse-eight.net/ - */ - -#include "../threads.h" -#include "../timeutils.h" - -using namespace CEC; - -CMutex::CMutex(bool bRecursive /* = true */) : - IMutex(bRecursive) -{ - pthread_mutex_init(&m_mutex, bRecursive ? GetMutexAttribute() : NULL); -} - -CMutex::~CMutex(void) -{ - pthread_mutex_destroy(&m_mutex); -} - -bool CMutex::TryLock(void) -{ - return (pthread_mutex_trylock(&m_mutex) == 0); -} - -bool CMutex::Lock(void) -{ - return (pthread_mutex_lock(&m_mutex) == 0); -} - -void CMutex::Unlock(void) -{ - pthread_mutex_unlock(&m_mutex); -} - -static pthread_mutexattr_t g_mutexAttr; -pthread_mutexattr_t *CMutex::GetMutexAttribute() -{ - static bool bAttributeInitialised = false; - if (!bAttributeInitialised) - { - pthread_mutexattr_init(&g_mutexAttr); - pthread_mutexattr_settype(&g_mutexAttr, PTHREAD_MUTEX_RECURSIVE); - bAttributeInitialised = true; - } - return &g_mutexAttr; -} - -CCondition::CCondition(void) -{ - pthread_cond_init(&m_cond, NULL); -} - -CCondition::~CCondition(void) -{ - pthread_cond_broadcast(&m_cond); - pthread_cond_destroy(&m_cond); -} - -void CCondition::Broadcast(void) -{ - pthread_cond_broadcast(&m_cond); -} - -void CCondition::Signal(void) -{ - pthread_cond_signal(&m_cond); -} - -bool CCondition::Wait(IMutex *mutex, uint32_t iTimeout /* = 0 */) -{ - bool bReturn(false); - sched_yield(); - CMutex *pmutex = static_cast(mutex); - if (pmutex) - { - if (iTimeout > 0) - { - struct timespec abstime; - struct timeval now; - gettimeofday(&now, NULL); - iTimeout += now.tv_usec / 1000; - abstime.tv_sec = now.tv_sec + (time_t)(iTimeout / 1000); - abstime.tv_nsec = (int32_t)((iTimeout % (uint32_t)1000) * (uint32_t)1000000); - bReturn = (pthread_cond_timedwait(&m_cond, &pmutex->m_mutex, &abstime) == 0); - } - else - { - bReturn = (pthread_cond_wait(&m_cond, &pmutex->m_mutex) == 0); - } - } - return bReturn; -} - -bool CThread::CreateThread(bool bWait /* = true */) -{ - bool bReturn(false); - CLockObject lock(m_threadMutex); - m_bStop = false; - if (!m_bRunning && pthread_create(&m_thread, NULL, (void *(*) (void *))&CThread::ThreadHandler, (void *)this) == 0) - { - if (bWait) - m_threadCondition->Wait(m_threadMutex); - bReturn = true; - } - return bReturn; -} - -bool CThread::StopThread(bool bWaitForExit /* = true */) -{ - bool bReturn = IThread::StopThread(bWaitForExit); - - void *retVal; - if (bWaitForExit && m_bRunning) - bReturn = (pthread_join(m_thread, &retVal) == 0); - - return bReturn; -} - -void *CThread::ThreadHandler(CThread *thread) -{ - void *retVal = NULL; - - if (thread) - { - CLockObject lock(thread->m_threadMutex); - thread->m_bRunning = true; - lock.Leave(); - thread->m_threadCondition->Broadcast(); - - retVal = thread->Process(); - - lock.Lock(); - thread->m_bRunning = false; - lock.Leave(); - thread->m_threadCondition->Broadcast(); - } - - return retVal; -} diff --git a/src/lib/platform/posix/serialport.cpp b/src/lib/platform/posix/serialport.cpp index f040857..ec8a5c1 100644 --- a/src/lib/platform/posix/serialport.cpp +++ b/src/lib/platform/posix/serialport.cpp @@ -32,8 +32,8 @@ #include #include -#include "../serialport.h" -#include "../baudrate.h" +#include "../serialport/serialport.h" +#include "../serialport/baudrate.h" #include "../timeutils.h" #if defined(__APPLE__) @@ -48,7 +48,7 @@ #endif #endif using namespace std; -using namespace CEC; +using namespace PLATFORM; CSerialPort::CSerialPort() { @@ -61,32 +61,33 @@ CSerialPort::~CSerialPort() Close(); } -int8_t CSerialPort::Write(CCECAdapterMessage *data) +int64_t CSerialPort::Write(uint8_t* data, uint32_t len) { fd_set port; - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_fd == -1) { m_error = "port closed"; return -1; } - int32_t byteswritten = 0; - - struct timeval timeout, *tv; - if (data->transmit_timeout <= 0) - { + int64_t byteswritten = 0; + struct timeval *tv; +//TODO +// struct timeval timeout, *tv; +// if (data->transmit_timeout <= 0) +// { tv = NULL; - } - else - { - timeout.tv_sec = (long int)data->transmit_timeout / (long int)1000.; - timeout.tv_usec = (long int)data->transmit_timeout % (long int)1000.; - tv = &timeout; - } - - while (byteswritten < (int32_t) data->size()) +// } +// else +// { +// timeout.tv_sec = (long int)data->transmit_timeout / (long int)1000.; +// timeout.tv_usec = (long int)data->transmit_timeout % (long int)1000.; +// tv = &timeout; +// } + + while (byteswritten < len) { FD_ZERO(&port); FD_SET(m_fd, &port); @@ -102,7 +103,7 @@ int8_t CSerialPort::Write(CCECAdapterMessage *data) return -1; } - returnv = write(m_fd, data->packet.data + byteswritten, data->size() - byteswritten); + returnv = write(m_fd, data + byteswritten, len - byteswritten); if (returnv == -1) { m_error = strerror(errno); @@ -116,7 +117,7 @@ int8_t CSerialPort::Write(CCECAdapterMessage *data) { printf("%s write:", m_name.c_str()); for (int i = 0; i < byteswritten; i++) - printf(" %02x", data->at(i)); + printf(" %02x", data[i]); printf("\n"); } @@ -131,7 +132,7 @@ int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /*= 0 int64_t now(0), target(0); int32_t bytesread = 0; - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_fd == -1) { m_error = "port closed"; @@ -202,7 +203,7 @@ bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits /* = 8 * { m_name = name; m_error = strerror(errno); - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (databits < 5 || databits > 8) { @@ -290,7 +291,7 @@ bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits /* = 8 * void CSerialPort::Close() { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_fd != -1) { close(m_fd); @@ -335,6 +336,6 @@ bool CSerialPort::SetBaudRate(uint32_t baudrate) bool CSerialPort::IsOpen() { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_fd != -1; } diff --git a/src/lib/platform/pthread_win32/pthread.h b/src/lib/platform/pthread_win32/pthread.h deleted file mode 100644 index a3140e1..0000000 --- a/src/lib/platform/pthread_win32/pthread.h +++ /dev/null @@ -1,1368 +0,0 @@ -/* This is an implementation of the threads API of POSIX 1003.1-2001. - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#if !defined( PTHREAD_H ) -#define PTHREAD_H - -/* - * See the README file for an explanation of the pthreads-win32 version - * numbering scheme and how the DLL is named etc. - */ -#define PTW32_VERSION 2,8,0,0 -#define PTW32_VERSION_STRING "2, 8, 0, 0\0" - -/* There are three implementations of cancel cleanup. - * Note that pthread.h is included in both application - * compilation units and also internally for the library. - * The code here and within the library aims to work - * for all reasonable combinations of environments. - * - * The three implementations are: - * - * WIN32 SEH - * C - * C++ - * - * Please note that exiting a push/pop block via - * "return", "exit", "break", or "continue" will - * lead to different behaviour amongst applications - * depending upon whether the library was built - * using SEH, C++, or C. For example, a library built - * with SEH will call the cleanup routine, while both - * C++ and C built versions will not. - */ - -/* - * Define defaults for cleanup code. - * Note: Unless the build explicitly defines one of the following, then - * we default to standard C style cleanup. This style uses setjmp/longjmp - * in the cancelation and thread exit implementations and therefore won't - * do stack unwinding if linked to applications that have it (e.g. - * C++ apps). This is currently consistent with most/all commercial Unix - * POSIX threads implementations. - */ -#if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C ) -# define __CLEANUP_C -#endif - -#if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC)) -#error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler. -#endif - -/* - * Stop here if we are being included by the resource compiler. - */ -#ifndef RC_INVOKED - -#undef PTW32_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_LEVEL 0 -/* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_LEVEL -#define PTW32_LEVEL 1 -/* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_LEVEL -#define PTW32_LEVEL 2 -/* Include Non-Portable extensions */ -#endif - -#define PTW32_LEVEL_MAX 3 - -#if !defined(PTW32_LEVEL) -#define PTW32_LEVEL PTW32_LEVEL_MAX -/* Include everything */ -#endif - -#ifdef _UWIN -# define HAVE_STRUCT_TIMESPEC 1 -# define HAVE_SIGNAL_H 1 -# undef HAVE_CONFIG_H -# pragma comment(lib, "pthread") -#endif - -/* - * ------------------------------------------------------------- - * - * - * Module: pthread.h - * - * Purpose: - * Provides an implementation of PThreads based upon the - * standard: - * - * POSIX 1003.1-2001 - * and - * The Single Unix Specification version 3 - * - * (these two are equivalent) - * - * in order to enhance code portability between Windows, - * various commercial Unix implementations, and Linux. - * - * See the ANNOUNCE file for a full list of conforming - * routines and defined constants, and a list of missing - * routines and constants not defined in this implementation. - * - * Authors: - * There have been many contributors to this library. - * The initial implementation was contributed by - * John Bossom, and several others have provided major - * sections or revisions of parts of the implementation. - * Often significant effort has been contributed to - * find and fix important bugs and other problems to - * improve the reliability of the library, which sometimes - * is not reflected in the amount of code which changed as - * result. - * As much as possible, the contributors are acknowledged - * in the ChangeLog file in the source code distribution - * where their changes are noted in detail. - * - * Contributors are listed in the CONTRIBUTORS file. - * - * As usual, all bouquets go to the contributors, and all - * brickbats go to the project maintainer. - * - * Maintainer: - * The code base for this project is coordinated and - * eventually pre-tested, packaged, and made available by - * - * Ross Johnson - * - * QA Testers: - * Ultimately, the library is tested in the real world by - * a host of competent and demanding scientists and - * engineers who report bugs and/or provide solutions - * which are then fixed or incorporated into subsequent - * versions of the library. Each time a bug is fixed, a - * test case is written to prove the fix and ensure - * that later changes to the code don't reintroduce the - * same error. The number of test cases is slowly growing - * and therefore so is the code reliability. - * - * Compliance: - * See the file ANNOUNCE for the list of implemented - * and not-implemented routines and defined options. - * Of course, these are all defined is this file as well. - * - * Web site: - * The source code and other information about this library - * are available from - * - * http://sources.redhat.com/pthreads-win32/ - * - * ------------------------------------------------------------- - */ - -/* Try to avoid including windows.h */ -#if defined(__MINGW32__) && defined(__cplusplus) -#define PTW32_INCLUDE_WINDOWS_H -#endif - -#ifdef PTW32_INCLUDE_WINDOWS_H -#include -#endif - -#if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__) -/* - * VC++6.0 or early compiler's header has no DWORD_PTR type. - */ -typedef unsigned long DWORD_PTR; -#endif -/* - * ----------------- - * autoconf switches - * ----------------- - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#ifndef NEED_FTIME -#include -#else /* NEED_FTIME */ -/* use native WIN32 time API */ -#endif /* NEED_FTIME */ - -#if HAVE_SIGNAL_H -#include -#endif /* HAVE_SIGNAL_H */ - -#include -#include - -/* - * Boolean values to make us independent of system includes. - */ -enum { - PTW32_FALSE = 0, - PTW32_TRUE = (! PTW32_FALSE) -}; - -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. - */ - -#ifndef PTW32_CONFIG_H -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# endif -# if defined(_UWIN) || defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -/* - * - */ - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -#ifdef NEED_ERRNO -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -/* - * Several systems don't define some error numbers. - */ -#ifndef ENOTSUP -# define ENOTSUP 48 /* This is the value in Solaris. */ -#endif - -#ifndef ETIMEDOUT -# define ETIMEDOUT 10060 /* This is the value in winsock.h. */ -#endif - -#ifndef ENOSYS -# define ENOSYS 140 /* Semi-arbitrary value */ -#endif - -#ifndef EDEADLK -# ifdef EDEADLOCK -# define EDEADLK EDEADLOCK -# else -# define EDEADLK 36 /* This is the value in MSVC. */ -# endif -#endif - -#include "sched.h" - -/* - * To avoid including windows.h we define only those things that we - * actually need from it. - */ -#ifndef PTW32_INCLUDE_WINDOWS_H -#ifndef HANDLE -# define PTW32__HANDLE_DEF -# define HANDLE void * -#endif -#ifndef DWORD -# define PTW32__DWORD_DEF -# define DWORD unsigned long -#endif -#endif - -#ifndef HAVE_STRUCT_TIMESPEC -#define HAVE_STRUCT_TIMESPEC 1 -struct timespec { - long tv_sec; - long tv_nsec; -}; -#endif /* HAVE_STRUCT_TIMESPEC */ - -#ifndef SIG_BLOCK -#define SIG_BLOCK 0 -#endif /* SIG_BLOCK */ - -#ifndef SIG_UNBLOCK -#define SIG_UNBLOCK 1 -#endif /* SIG_UNBLOCK */ - -#ifndef SIG_SETMASK -#define SIG_SETMASK 2 -#endif /* SIG_SETMASK */ - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/* - * ------------------------------------------------------------- - * - * POSIX 1003.1-2001 Options - * ========================= - * - * Options are normally set in , which is not provided - * with pthreads-win32. - * - * For conformance with the Single Unix Specification (version 3), all of the - * options below are defined, and have a value of either -1 (not supported) - * or 200112L (supported). - * - * These options can neither be left undefined nor have a value of 0, because - * either indicates that sysconf(), which is not implemented, may be used at - * runtime to check the status of the option. - * - * _POSIX_THREADS (== 200112L) - * If == 200112L, you can use threads - * - * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L) - * If == 200112L, you can control the size of a thread's - * stack - * pthread_attr_getstacksize - * pthread_attr_setstacksize - * - * _POSIX_THREAD_ATTR_STACKADDR (== -1) - * If == 200112L, you can allocate and control a thread's - * stack. If not supported, the following functions - * will return ENOSYS, indicating they are not - * supported: - * pthread_attr_getstackaddr - * pthread_attr_setstackaddr - * - * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1) - * If == 200112L, you can use realtime scheduling. - * This option indicates that the behaviour of some - * implemented functions conforms to the additional TPS - * requirements in the standard. E.g. rwlocks favour - * writers over readers when threads have equal priority. - * - * _POSIX_THREAD_PRIO_INHERIT (== -1) - * If == 200112L, you can create priority inheritance - * mutexes. - * pthread_mutexattr_getprotocol + - * pthread_mutexattr_setprotocol + - * - * _POSIX_THREAD_PRIO_PROTECT (== -1) - * If == 200112L, you can create priority ceiling mutexes - * Indicates the availability of: - * pthread_mutex_getprioceiling - * pthread_mutex_setprioceiling - * pthread_mutexattr_getprioceiling - * pthread_mutexattr_getprotocol + - * pthread_mutexattr_setprioceiling - * pthread_mutexattr_setprotocol + - * - * _POSIX_THREAD_PROCESS_SHARED (== -1) - * If set, you can create mutexes and condition - * variables that can be shared with another - * process.If set, indicates the availability - * of: - * pthread_mutexattr_getpshared - * pthread_mutexattr_setpshared - * pthread_condattr_getpshared - * pthread_condattr_setpshared - * - * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L) - * If == 200112L you can use the special *_r library - * functions that provide thread-safe behaviour - * - * _POSIX_READER_WRITER_LOCKS (== 200112L) - * If == 200112L, you can use read/write locks - * - * _POSIX_SPIN_LOCKS (== 200112L) - * If == 200112L, you can use spin locks - * - * _POSIX_BARRIERS (== 200112L) - * If == 200112L, you can use barriers - * - * + These functions provide both 'inherit' and/or - * 'protect' protocol, based upon these macro - * settings. - * - * ------------------------------------------------------------- - */ - -/* - * POSIX Options - */ -#undef _POSIX_THREADS -#define _POSIX_THREADS 200112L - -#undef _POSIX_READER_WRITER_LOCKS -#define _POSIX_READER_WRITER_LOCKS 200112L - -#undef _POSIX_SPIN_LOCKS -#define _POSIX_SPIN_LOCKS 200112L - -#undef _POSIX_BARRIERS -#define _POSIX_BARRIERS 200112L - -#undef _POSIX_THREAD_SAFE_FUNCTIONS -#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L - -#undef _POSIX_THREAD_ATTR_STACKSIZE -#define _POSIX_THREAD_ATTR_STACKSIZE 200112L - -/* - * The following options are not supported - */ -#undef _POSIX_THREAD_ATTR_STACKADDR -#define _POSIX_THREAD_ATTR_STACKADDR -1 - -#undef _POSIX_THREAD_PRIO_INHERIT -#define _POSIX_THREAD_PRIO_INHERIT -1 - -#undef _POSIX_THREAD_PRIO_PROTECT -#define _POSIX_THREAD_PRIO_PROTECT -1 - -/* TPS is not fully supported. */ -#undef _POSIX_THREAD_PRIORITY_SCHEDULING -#define _POSIX_THREAD_PRIORITY_SCHEDULING -1 - -#undef _POSIX_THREAD_PROCESS_SHARED -#define _POSIX_THREAD_PROCESS_SHARED -1 - - -/* - * POSIX 1003.1-2001 Limits - * =========================== - * - * These limits are normally set in , which is not provided with - * pthreads-win32. - * - * PTHREAD_DESTRUCTOR_ITERATIONS - * Maximum number of attempts to destroy - * a thread's thread-specific data on - * termination (must be at least 4) - * - * PTHREAD_KEYS_MAX - * Maximum number of thread-specific data keys - * available per process (must be at least 128) - * - * PTHREAD_STACK_MIN - * Minimum supported stack size for a thread - * - * PTHREAD_THREADS_MAX - * Maximum number of threads supported per - * process (must be at least 64). - * - * SEM_NSEMS_MAX - * The maximum number of semaphores a process can have. - * (must be at least 256) - * - * SEM_VALUE_MAX - * The maximum value a semaphore can have. - * (must be at least 32767) - * - */ -#undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS -#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 - -#undef PTHREAD_DESTRUCTOR_ITERATIONS -#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS - -#undef _POSIX_THREAD_KEYS_MAX -#define _POSIX_THREAD_KEYS_MAX 128 - -#undef PTHREAD_KEYS_MAX -#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX - -#undef PTHREAD_STACK_MIN -#define PTHREAD_STACK_MIN 0 - -#undef _POSIX_THREAD_THREADS_MAX -#define _POSIX_THREAD_THREADS_MAX 64 - - /* Arbitrary value */ -#undef PTHREAD_THREADS_MAX -#define PTHREAD_THREADS_MAX 2019 - -#undef _POSIX_SEM_NSEMS_MAX -#define _POSIX_SEM_NSEMS_MAX 256 - - /* Arbitrary value */ -#undef SEM_NSEMS_MAX -#define SEM_NSEMS_MAX 1024 - -#undef _POSIX_SEM_VALUE_MAX -#define _POSIX_SEM_VALUE_MAX 32767 - -#undef SEM_VALUE_MAX -#define SEM_VALUE_MAX INT_MAX - - -#if __GNUC__ && ! defined (__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -/* - * When building the DLL code, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the DLL, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. - */ -#ifndef PTW32_STATIC_LIB -# ifdef PTW32_BUILD -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT -#endif - -/* - * The Open Watcom C/C++ compiler uses a non-standard calling convention - * that passes function args in registers unless __cdecl is explicitly specified - * in exposed function prototypes. - * - * We force all calls to cdecl even though this could slow Watcom code down - * slightly. If you know that the Watcom compiler will be used to build both - * the DLL and application, then you can probably define this as a null string. - * Remember that pthread.h (this file) is used for both the DLL and application builds. - */ -#define PTW32_CDECL __cdecl - -#if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX -# include -#else -/* - * Generic handle type - intended to extend uniqueness beyond - * that available with a simple pointer. It should scale for either - * IA-32 or IA-64. - */ -typedef struct { - void * p; /* Pointer to actual object */ - unsigned int x; /* Extra information - reuse count etc */ -} ptw32_handle_t; - -typedef ptw32_handle_t pthread_t; -typedef struct pthread_attr_t_ * pthread_attr_t; -typedef struct pthread_once_t_ pthread_once_t; -typedef struct pthread_key_t_ * pthread_key_t; -typedef struct pthread_mutex_t_ * pthread_mutex_t; -typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t; -typedef struct pthread_cond_t_ * pthread_cond_t; -typedef struct pthread_condattr_t_ * pthread_condattr_t; -#endif -typedef struct pthread_rwlock_t_ * pthread_rwlock_t; -typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t; -typedef struct pthread_spinlock_t_ * pthread_spinlock_t; -typedef struct pthread_barrier_t_ * pthread_barrier_t; -typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t; - -/* - * ==================== - * ==================== - * POSIX Threads - * ==================== - * ==================== - */ - -enum { -/* - * pthread_attr_{get,set}detachstate - */ - PTHREAD_CREATE_JOINABLE = 0, /* Default */ - PTHREAD_CREATE_DETACHED = 1, - -/* - * pthread_attr_{get,set}inheritsched - */ - PTHREAD_INHERIT_SCHED = 0, - PTHREAD_EXPLICIT_SCHED = 1, /* Default */ - -/* - * pthread_{get,set}scope - */ - PTHREAD_SCOPE_PROCESS = 0, - PTHREAD_SCOPE_SYSTEM = 1, /* Default */ - -/* - * pthread_setcancelstate paramters - */ - PTHREAD_CANCEL_ENABLE = 0, /* Default */ - PTHREAD_CANCEL_DISABLE = 1, - -/* - * pthread_setcanceltype parameters - */ - PTHREAD_CANCEL_ASYNCHRONOUS = 0, - PTHREAD_CANCEL_DEFERRED = 1, /* Default */ - -/* - * pthread_mutexattr_{get,set}pshared - * pthread_condattr_{get,set}pshared - */ - PTHREAD_PROCESS_PRIVATE = 0, - PTHREAD_PROCESS_SHARED = 1, - -/* - * pthread_barrier_wait - */ - PTHREAD_BARRIER_SERIAL_THREAD = -1 -}; - -/* - * ==================== - * ==================== - * Cancelation - * ==================== - * ==================== - */ -#define PTHREAD_CANCELED ((void *) -1) - - -/* - * ==================== - * ==================== - * Once Key - * ==================== - * ==================== - */ -#define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0} - -struct pthread_once_t_ -{ - int done; /* indicates if user function has been executed */ - void * lock; - int reserved1; - int reserved2; -}; - - -/* - * ==================== - * ==================== - * Object initialisers - * ==================== - * ==================== - */ -#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1) -#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2) -#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3) - -/* - * Compatibility with LinuxThreads - */ -#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER -#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER - -#define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1) - -#define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1) - -#define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1) - - -/* - * Mutex types. - */ -enum -{ - /* Compatibility with LinuxThreads */ - PTHREAD_MUTEX_FAST_NP, - PTHREAD_MUTEX_RECURSIVE_NP, - PTHREAD_MUTEX_ERRORCHECK_NP, - PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP, - PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP, - /* For compatibility with POSIX */ - PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP, - PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, - PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, - PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL -}; - - -typedef struct ptw32_cleanup_t ptw32_cleanup_t; - -#if defined(_MSC_VER) -/* Disable MSVC 'anachronism used' warning */ -#pragma warning( disable : 4229 ) -#endif - -typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *); - -#if defined(_MSC_VER) -#pragma warning( default : 4229 ) -#endif - -struct ptw32_cleanup_t -{ - ptw32_cleanup_callback_t routine; - void *arg; - struct ptw32_cleanup_t *prev; -}; - -#ifdef __CLEANUP_SEH - /* - * WIN32 SEH version of cancel cleanup. - */ - -#define pthread_cleanup_push( _rout, _arg ) \ - { \ - ptw32_cleanup_t _cleanup; \ - \ - _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \ - _cleanup.arg = (_arg); \ - __try \ - { \ - -#define pthread_cleanup_pop( _execute ) \ - } \ - __finally \ - { \ - if( _execute || AbnormalTermination()) \ - { \ - (*(_cleanup.routine))( _cleanup.arg ); \ - } \ - } \ - } - -#else /* __CLEANUP_SEH */ - -#ifdef __CLEANUP_C - - /* - * C implementation of PThreads cancel cleanup - */ - -#define pthread_cleanup_push( _rout, _arg ) \ - { \ - ptw32_cleanup_t _cleanup; \ - \ - ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \ - -#define pthread_cleanup_pop( _execute ) \ - (void) ptw32_pop_cleanup( _execute ); \ - } - -#else /* __CLEANUP_C */ - -#ifdef __CLEANUP_CXX - - /* - * C++ version of cancel cleanup. - * - John E. Bossom. - */ - - class PThreadCleanup { - /* - * PThreadCleanup - * - * Purpose - * This class is a C++ helper class that is - * used to implement pthread_cleanup_push/ - * pthread_cleanup_pop. - * The destructor of this class automatically - * pops the pushed cleanup routine regardless - * of how the code exits the scope - * (i.e. such as by an exception) - */ - ptw32_cleanup_callback_t cleanUpRout; - void * obj; - int executeIt; - - public: - PThreadCleanup() : - cleanUpRout( 0 ), - obj( 0 ), - executeIt( 0 ) - /* - * No cleanup performed - */ - { - } - - PThreadCleanup( - ptw32_cleanup_callback_t routine, - void * arg ) : - cleanUpRout( routine ), - obj( arg ), - executeIt( 1 ) - /* - * Registers a cleanup routine for 'arg' - */ - { - } - - ~PThreadCleanup() - { - if ( executeIt && ((void *) cleanUpRout != (void *) 0) ) - { - (void) (*cleanUpRout)( obj ); - } - } - - void execute( int exec ) - { - executeIt = exec; - } - }; - - /* - * C++ implementation of PThreads cancel cleanup; - * This implementation takes advantage of a helper - * class who's destructor automatically calls the - * cleanup routine if we exit our scope weirdly - */ -#define pthread_cleanup_push( _rout, _arg ) \ - { \ - PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \ - (void *) (_arg) ); - -#define pthread_cleanup_pop( _execute ) \ - cleanup.execute( _execute ); \ - } - -#else - -#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined. - -#endif /* __CLEANUP_CXX */ - -#endif /* __CLEANUP_C */ - -#endif /* __CLEANUP_SEH */ - -/* - * =============== - * =============== - * Methods - * =============== - * =============== - */ - -/* - * PThread Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr, - int *detachstate); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr, - void **stackaddr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr, - size_t * stacksize); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr, - int detachstate); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr, - void *stackaddr); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr, - size_t stacksize); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr, - struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr, - const struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *, - int); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (pthread_attr_t *, - int *); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr, - int inheritsched); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(pthread_attr_t * attr, - int * inheritsched); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *, - int); - -PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *, - int *); - -/* - * PThread Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid, - const pthread_attr_t * attr, - void *(*start) (void *), - void *arg); - -PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid); - -PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1, - pthread_t t2); - -PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr); - -PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread, - void **value_ptr); - -PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void); - -PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread); - -PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state, - int *oldstate); - -PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type, - int *oldtype); - -PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void); - -PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control, - void (*init_routine) (void)); - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute); - -PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup, - void (*routine) (void *), - void *arg); -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -/* - * Thread Specific Data Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key, - void (*destructor) (void *)); - -PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key); - -PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key, - const void *value); - -PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key); - - -/* - * Mutex Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t - * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, - int pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind); - -/* - * Barrier Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t - * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr, - int pshared); - -/* - * Mutex Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex, - const pthread_mutexattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t *mutex, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex); - -/* - * Spinlock Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock); - -/* - * Barrier Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier, - const pthread_barrierattr_t * attr, - unsigned int count); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier); - -PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier); - -/* - * Condition Variable Attribute Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr, - int pshared); - -/* - * Condition Variable Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond, - const pthread_condattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond, - pthread_mutex_t * mutex); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond, - pthread_mutex_t * mutex, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond); - -PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond); - -/* - * Scheduling - */ -PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread, - int policy, - const struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread, - int *policy, - struct sched_param *param); - -PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int); - -PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void); - -/* - * Read-Write Lock Functions - */ -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock, - const pthread_rwlockattr_t *attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock, - const struct timespec *abstime); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr, - int *pshared); - -PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr, - int pshared); - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 - -/* - * Signal Functions. Should be defined in but MSVC and MinGW32 - * already have signal.h that don't define these. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig); - -/* - * Non-portable functions - */ - -/* - * Compatibility with Linux. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr, - int kind); -PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr, - int *kind); - -/* - * Possibly supported by other POSIX threads implementations - */ -PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval); -PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void); - -/* - * Useful if an application wants to statically link - * the lib rather than load the DLL at run-time. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void); -PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void); - -/* - * Features that are auto-detected at load/run time. - */ -PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int); -enum ptw32_features { - PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */ - PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */ -}; - -/* - * Register a system time change with the library. - * Causes the library to perform various functions - * in response to the change. Should be called whenever - * the application's top level window receives a - * WM_TIMECHANGE message. It can be passed directly to - * pthread_create() as a new thread if desired. - */ -PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *); - -#endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */ - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX - -/* - * Returns the Win32 HANDLE for the POSIX thread. - */ -PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread); - - -/* - * Protected Methods - * - * This function blocks until the given WIN32 handle - * is signaled or pthread_cancel had been called. - * This function allows the caller to hook into the - * PThreads cancel mechanism. It is implemented using - * - * WaitForMultipleObjects - * - * on 'waitHandle' and a manually reset WIN32 Event - * used to implement pthread_cancel. The 'timeout' - * argument to TimedWait is simply passed to - * WaitForMultipleObjects. - */ -PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle); -PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle, - DWORD timeout); - -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -/* - * Thread-Safe C Runtime Library Mappings. - */ -#ifndef _UWIN -# if defined(NEED_ERRNO) - PTW32_DLLPORT int * PTW32_CDECL _errno( void ); -# else -# ifndef errno -# if (defined(_MT) || defined(_DLL)) - __declspec(dllimport) extern int * __cdecl _errno(void); -# define errno (*_errno()) -# endif -# endif -# endif -#endif - -/* - * WIN32 C runtime library had been made thread-safe - * without affecting the user interface. Provide - * mappings from the UNIX thread-safe versions to - * the standard C runtime library calls. - * Only provide function mappings for functions that - * actually exist on WIN32. - */ - -#if !defined(__MINGW32__) -#define strtok_r( _s, _sep, _lasts ) \ - ( *(_lasts) = strtok( (_s), (_sep) ) ) -#endif /* !__MINGW32__ */ - -#define asctime_r( _tm, _buf ) \ - ( strcpy( (_buf), asctime( (_tm) ) ), \ - (_buf) ) - -#define ctime_r( _clock, _buf ) \ - ( strcpy( (_buf), ctime( (_clock) ) ), \ - (_buf) ) - -#define gmtime_r( _clock, _result ) \ - ( *(_result) = *gmtime( (_clock) ), \ - (_result) ) - -#define localtime_r( _clock, _result ) \ - ( *(_result) = *localtime( (_clock) ), \ - (_result) ) - -#define rand_r( _seed ) \ - ( _seed == _seed? rand() : rand() ) - - -/* - * Some compiler environments don't define some things. - */ -#if defined(__BORLANDC__) -# define _ftime ftime -# define _timeb timeb -#endif - -#ifdef __cplusplus - -/* - * Internal exceptions - */ -class ptw32_exception {}; -class ptw32_exception_cancel : public ptw32_exception {}; -class ptw32_exception_exit : public ptw32_exception {}; - -#endif - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX - -/* FIXME: This is only required if the library was built using SEH */ -/* - * Get internal SEH tag - */ -PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void); - -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -#ifndef PTW32_BUILD - -#ifdef __CLEANUP_SEH - -/* - * Redefine the SEH __except keyword to ensure that applications - * propagate our internal exceptions up to the library's internal handlers. - */ -#define __except( E ) \ - __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \ - ? EXCEPTION_CONTINUE_SEARCH : ( E ) ) - -#endif /* __CLEANUP_SEH */ - -#ifdef __CLEANUP_CXX - -/* - * Redefine the C++ catch keyword to ensure that applications - * propagate our internal exceptions up to the library's internal handlers. - */ -#ifdef _MSC_VER - /* - * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll' - * if you want Pthread-Win32 cancelation and pthread_exit to work. - */ - -#ifndef PtW32NoCatchWarn - -#pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.") -#pragma message("------------------------------------------------------------------") -#pragma message("When compiling applications with MSVC++ and C++ exception handling:") -#pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads") -#pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread") -#pragma message(" cancelation and pthread_exit to work. For example:") -#pragma message("") -#pragma message(" #ifdef PtW32CatchAll") -#pragma message(" PtW32CatchAll") -#pragma message(" #else") -#pragma message(" catch(...)") -#pragma message(" #endif") -#pragma message(" {") -#pragma message(" /* Catchall block processing */") -#pragma message(" }") -#pragma message("------------------------------------------------------------------") - -#endif - -#define PtW32CatchAll \ - catch( ptw32_exception & ) { throw; } \ - catch( ... ) - -#else /* _MSC_VER */ - -#define catch( E ) \ - catch( ptw32_exception & ) { throw; } \ - catch( E ) - -#endif /* _MSC_VER */ - -#endif /* __CLEANUP_CXX */ - -#endif /* ! PTW32_BUILD */ - -#ifdef __cplusplus -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#ifdef PTW32__HANDLE_DEF -# undef HANDLE -#endif -#ifdef PTW32__DWORD_DEF -# undef DWORD -#endif - -#undef PTW32_LEVEL -#undef PTW32_LEVEL_MAX - -#endif /* ! RC_INVOKED */ - -#endif /* PTHREAD_H */ diff --git a/src/lib/platform/pthread_win32/pthreadVC2.lib b/src/lib/platform/pthread_win32/pthreadVC2.lib deleted file mode 100644 index bc36770..0000000 Binary files a/src/lib/platform/pthread_win32/pthreadVC2.lib and /dev/null differ diff --git a/src/lib/platform/pthread_win32/sched.h b/src/lib/platform/pthread_win32/sched.h deleted file mode 100644 index dfb8e93..0000000 --- a/src/lib/platform/pthread_win32/sched.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Module: sched.h - * - * Purpose: - * Provides an implementation of POSIX realtime extensions - * as defined in - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ -#ifndef _SCHED_H -#define _SCHED_H - -#undef PTW32_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_LEVEL 0 -/* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_LEVEL -#define PTW32_LEVEL 1 -/* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_LEVEL -#define PTW32_LEVEL 2 -/* Include Non-Portable extensions */ -#endif - -#define PTW32_LEVEL_MAX 3 - -#if !defined(PTW32_LEVEL) -#define PTW32_LEVEL PTW32_LEVEL_MAX -/* Include everything */ -#endif - - -#if __GNUC__ && ! defined (__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -/* - * When building the DLL code, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the DLL, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. - */ -#ifndef PTW32_STATIC_LIB -# ifdef PTW32_BUILD -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT -#endif - -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. - */ - -#ifndef PTW32_CONFIG_H -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# endif -# if defined(_UWIN) || defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -/* - * - */ - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -#ifdef NEED_ERRNO -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -#if defined(__MINGW32__) || defined(_UWIN) -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -/* For pid_t */ -# include -/* Required by Unix 98 */ -# include -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ -#else -typedef int pid_t; -#endif - -/* Thread scheduling policies */ - -enum { - SCHED_OTHER = 0, - SCHED_FIFO, - SCHED_RR, - SCHED_MIN = SCHED_OTHER, - SCHED_MAX = SCHED_RR -}; - -struct sched_param { - int sched_priority; -}; - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -PTW32_DLLPORT int __cdecl sched_yield (void); - -PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy); - -PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy); - -PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy); - -PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid); - -/* - * Note that this macro returns ENOTSUP rather than - * ENOSYS as might be expected. However, returning ENOSYS - * should mean that sched_get_priority_{min,max} are - * not implemented as well as sched_rr_get_interval. - * This is not the case, since we just don't support - * round-robin scheduling. Therefore I have chosen to - * return the same value as sched_setscheduler when - * SCHED_RR is passed to it. - */ -#define sched_rr_get_interval(_pid, _interval) \ - ( errno = ENOTSUP, (int) -1 ) - - -#ifdef __cplusplus -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#undef PTW32_LEVEL -#undef PTW32_LEVEL_MAX - -#endif /* !_SCHED_H */ - diff --git a/src/lib/platform/pthread_win32/semaphore.h b/src/lib/platform/pthread_win32/semaphore.h deleted file mode 100644 index a3330a6..0000000 --- a/src/lib/platform/pthread_win32/semaphore.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Module: semaphore.h - * - * Purpose: - * Semaphores aren't actually part of the PThreads standard. - * They are defined by the POSIX Standard: - * - * POSIX 1003.1b-1993 (POSIX.1b) - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ -#if !defined( SEMAPHORE_H ) -#define SEMAPHORE_H - -#undef PTW32_LEVEL - -#if defined(_POSIX_SOURCE) -#define PTW32_LEVEL 0 -/* Early POSIX */ -#endif - -#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 -#undef PTW32_LEVEL -#define PTW32_LEVEL 1 -/* Include 1b, 1c and 1d */ -#endif - -#if defined(INCLUDE_NP) -#undef PTW32_LEVEL -#define PTW32_LEVEL 2 -/* Include Non-Portable extensions */ -#endif - -#define PTW32_LEVEL_MAX 3 - -#if !defined(PTW32_LEVEL) -#define PTW32_LEVEL PTW32_LEVEL_MAX -/* Include everything */ -#endif - -#if __GNUC__ && ! defined (__declspec) -# error Please upgrade your GNU compiler to one that supports __declspec. -#endif - -/* - * When building the DLL code, you should define PTW32_BUILD so that - * the variables/functions are exported correctly. When using the DLL, - * do NOT define PTW32_BUILD, and then the variables/functions will - * be imported correctly. - */ -#ifndef PTW32_STATIC_LIB -# ifdef PTW32_BUILD -# define PTW32_DLLPORT __declspec (dllexport) -# else -# define PTW32_DLLPORT __declspec (dllimport) -# endif -#else -# define PTW32_DLLPORT -#endif - -/* - * This is a duplicate of what is in the autoconf config.h, - * which is only used when building the pthread-win32 libraries. - */ - -#ifndef PTW32_CONFIG_H -# if defined(WINCE) -# define NEED_ERRNO -# define NEED_SEM -# endif -# if defined(_UWIN) || defined(__MINGW32__) -# define HAVE_MODE_T -# endif -#endif - -/* - * - */ - -#if PTW32_LEVEL >= PTW32_LEVEL_MAX -#ifdef NEED_ERRNO -#include "need_errno.h" -#else -#include -#endif -#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */ - -#define _POSIX_SEMAPHORES - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#ifndef HAVE_MODE_T -typedef unsigned int mode_t; -#endif - - -typedef struct sem_t_ * sem_t; - -PTW32_DLLPORT int __cdecl sem_init (sem_t * sem, - int pshared, - unsigned int value); - -PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem); - -PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem); - -PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem); - -PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem, - const struct timespec * abstime); - -PTW32_DLLPORT int __cdecl sem_post (sem_t * sem); - -PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem, - int count); - -PTW32_DLLPORT int __cdecl sem_open (const char * name, - int oflag, - mode_t mode, - unsigned int value); - -PTW32_DLLPORT int __cdecl sem_close (sem_t * sem); - -PTW32_DLLPORT int __cdecl sem_unlink (const char * name); - -PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem, - int * sval); - -#ifdef __cplusplus -} /* End of extern "C" */ -#endif /* __cplusplus */ - -#undef PTW32_LEVEL -#undef PTW32_LEVEL_MAX - -#endif /* !SEMAPHORE_H */ diff --git a/src/lib/platform/baudrate.h b/src/lib/platform/serialport/baudrate.h similarity index 95% rename from src/lib/platform/baudrate.h rename to src/lib/platform/serialport/baudrate.h index 98521bb..bfdb2d7 100644 --- a/src/lib/platform/baudrate.h +++ b/src/lib/platform/serialport/baudrate.h @@ -34,19 +34,18 @@ //every baudrate I could find is in here in an #ifdef block //so it should compile on everything -#include "os-dependent.h" - #ifndef __WINDOWS__ #include #endif -namespace CEC +namespace PLATFORM { static struct sbaudrate { int32_t rate; int32_t symbol; } + baudrates[] = { #ifdef B50 @@ -199,9 +198,9 @@ namespace CEC { -1, -1} }; - static int32_t IntToBaudrate(uint32_t baudrate) + inline int32_t IntToBaudrate(uint32_t baudrate) { - for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(CEC::sbaudrate) - 1; i++) + for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(PLATFORM::sbaudrate) - 1; i++) { if (baudrates[i].rate == (int32_t) baudrate) return baudrates[i].symbol; diff --git a/src/lib/platform/serialport.h b/src/lib/platform/serialport/serialport.h similarity index 75% rename from src/lib/platform/serialport.h rename to src/lib/platform/serialport/serialport.h index f5035b9..3710bfe 100644 --- a/src/lib/platform/serialport.h +++ b/src/lib/platform/serialport/serialport.h @@ -31,20 +31,15 @@ * http://www.pulse-eight.net/ */ -#include "os-dependent.h" -#include +#include "../os.h" #include #include -#include "../AdapterCommunication.h" -#include "../platform/threads.h" #ifndef __WINDOWS__ #include -#else -#include "../util/buffer.h" #endif -namespace CEC +namespace PLATFORM { #define PAR_NONE 0 #define PAR_EVEN 1 @@ -60,7 +55,7 @@ namespace CEC bool IsOpen(); void Close(); - int8_t Write(CCECAdapterMessage *data); + int64_t Write(uint8_t* data, uint32_t len); int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0); std::string GetError() { return m_error; } @@ -69,23 +64,23 @@ namespace CEC private: bool SetBaudRate(uint32_t baudrate); - std::string m_error; - std::string m_name; - CMutex m_mutex; - bool m_tostdout; + std::string m_error; + std::string m_name; + CMutex m_mutex; + bool m_tostdout; #ifdef __WINDOWS__ bool SetTimeouts(bool bBlocking); - HANDLE m_handle; - bool m_bIsOpen; - uint32_t m_iBaudrate; - uint8_t m_iDatabits; - uint8_t m_iStopbits; - uint8_t m_iParity; - int64_t m_iTimeout; - CecBuffer m_buffer; - HANDLE m_ovHandle; + HANDLE m_handle; + bool m_bIsOpen; + uint32_t m_iBaudrate; + uint8_t m_iDatabits; + uint8_t m_iStopbits; + uint8_t m_iParity; + int64_t m_iTimeout; + SyncedBuffer m_buffer; + HANDLE m_ovHandle; #else struct termios m_options; int m_fd; diff --git a/src/lib/platform/threads.h b/src/lib/platform/threads.h deleted file mode 100644 index 2c3c2c5..0000000 --- a/src/lib/platform/threads.h +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once -/* - * This file is part of the libCEC(R) library. - * - * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. - * libCEC(R) is an original work, containing original code. - * - * libCEC(R) is a trademark of Pulse-Eight Limited. - * - * This program is dual-licensed; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * Alternatively, you can license this library under a commercial license, - * please contact Pulse-Eight Licensing for more information. - * - * For more information contact: - * Pulse-Eight Licensing - * http://www.pulse-eight.com/ - * http://www.pulse-eight.net/ - */ - -#include - -namespace CEC -{ - class IMutex - { - public: - IMutex(bool bRecursive = true) { m_bRecursive = bRecursive ; }; - virtual ~IMutex(void) {}; - - virtual bool TryLock(void) = 0; - virtual bool Lock(void) = 0; - virtual void Unlock(void) = 0; - - protected: - bool m_bRecursive; - }; - - class ICondition - { - public: - virtual void Broadcast(void) = 0; - virtual void Signal(void) = 0; - virtual bool Wait(IMutex *mutex, uint32_t iTimeout = 0) = 0; - - static void Sleep(uint32_t iTimeout); - }; - - class IThread - { - public: - IThread(void); - virtual ~IThread(void); - - virtual bool IsRunning(void) const { return m_bRunning; }; - virtual bool CreateThread(bool bWait = true) = 0; - virtual bool IsStopped(void) const { return m_bStop; }; - - virtual bool StopThread(bool bWaitForExit = true); - virtual bool Sleep(uint32_t iTimeout); - - virtual void *Process(void) = 0; - - protected: - bool m_bStop; - bool m_bRunning; - ICondition *m_threadCondition; - IMutex *m_threadMutex; - }; - - class CLockObject - { - public: - CLockObject(IMutex *mutex, bool bTryLock = false); - ~CLockObject(void); - - bool IsLocked(void) const { return m_bLocked; } - void Leave(void); - void Lock(void); - - private: - IMutex *m_mutex; - bool m_bLocked; - }; -}; diff --git a/src/lib/platform/threads/mutex.h b/src/lib/platform/threads/mutex.h new file mode 100644 index 0000000..4a2ad79 --- /dev/null +++ b/src/lib/platform/threads/mutex.h @@ -0,0 +1,188 @@ +#pragma once +/* + * This file is part of the libCEC(R) library. + * + * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is an original work, containing original code. + * + * libCEC(R) is a trademark of Pulse-Eight Limited. + * + * This program is dual-licensed; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * Alternatively, you can license this library under a commercial license, + * please contact Pulse-Eight Licensing for more information. + * + * For more information contact: + * Pulse-Eight Licensing + * http://www.pulse-eight.com/ + * http://www.pulse-eight.net/ + */ + +namespace PLATFORM +{ + class PreventCopy + { + public: + inline PreventCopy(void) {} + inline ~PreventCopy(void) {} + + private: + inline PreventCopy(const PreventCopy &c) { *this = c; } + inline PreventCopy &operator=(const PreventCopy &c){ *this = c; return *this; } + }; + + class CCondition; + + class CMutex : public PreventCopy + { + friend class CCondition; + public: + inline CMutex(void) : + m_iLockCount(0) + { + MutexCreate(m_mutex); + } + + inline ~CMutex(void) + { + Clear(); + MutexDelete(m_mutex); + } + + inline bool TryLock(void) + { + if (MutexTryLock(m_mutex)) + { + ++m_iLockCount; + return true; + } + return false; + } + + inline bool Lock(void) + { + MutexLock(m_mutex); + ++m_iLockCount; + return true; + } + + inline void Unlock(void) + { + --m_iLockCount; + MutexUnlock(m_mutex); + } + + inline bool Clear(void) + { + bool bReturn(false); + if (TryLock()) + { + unsigned int iLockCount = m_iLockCount; + for (unsigned int iPtr = 0; iPtr < iLockCount; iPtr++) + Unlock(); + bReturn = true; + } + return bReturn; + } + + private: + mutex_t m_mutex; + unsigned int m_iLockCount; + }; + + class CLockObject : public PreventCopy + { + public: + inline CLockObject(CMutex &mutex, bool bClearOnExit = false) : + m_mutex(mutex), + m_bClearOnExit(bClearOnExit) + { + m_mutex.Lock(); + } + + inline ~CLockObject(void) + { + if (m_bClearOnExit) + Clear(); + else + Unlock(); + } + + inline bool TryLock(void) + { + return m_mutex.TryLock(); + } + + inline void Unlock(void) + { + m_mutex.Unlock(); + } + + inline bool Clear(void) + { + return m_mutex.Clear(); + } + + inline bool Lock(void) + { + return m_mutex.Lock(); + } + + private: + CMutex &m_mutex; + bool m_bClearOnExit; + }; + + class CCondition : public PreventCopy + { + public: + inline CCondition(void) + { + ConditionCreate(m_condition); + } + + inline ~CCondition(void) + { + Broadcast(); + ConditionDelete(m_condition); + } + + inline void Broadcast(void) + { + ConditionBroadcast(m_condition); + } + + inline void Signal(void) + { + ConditionSignal(m_condition); + } + + inline bool Wait(CMutex &mutex, uint32_t iTimeout = 0) + { + return ConditionWait(m_condition, mutex.m_mutex, iTimeout); + } + + static void Sleep(uint32_t iTimeout) + { + CCondition w; + CMutex m; + CLockObject lock(m); + w.Wait(m, iTimeout); + } + + condition_t m_condition; + }; +} diff --git a/src/lib/platform/threads/threads.h b/src/lib/platform/threads/threads.h new file mode 100644 index 0000000..74d683f --- /dev/null +++ b/src/lib/platform/threads/threads.h @@ -0,0 +1,137 @@ +#pragma once +/* + * This file is part of the libCEC(R) library. + * + * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is an original work, containing original code. + * + * libCEC(R) is a trademark of Pulse-Eight Limited. + * + * This program is dual-licensed; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * Alternatively, you can license this library under a commercial license, + * please contact Pulse-Eight Licensing for more information. + * + * For more information contact: + * Pulse-Eight Licensing + * http://www.pulse-eight.com/ + * http://www.pulse-eight.net/ + */ + +#include "mutex.h" + +namespace PLATFORM +{ + class CThread + { + public: + CThread(void) : + m_bStop(false), + m_bRunning(false) {} + + virtual ~CThread(void) + { + StopThread(); + } + + static void *ThreadHandler(CThread *thread) + { + void *retVal = NULL; + + if (thread) + { + CLockObject lock(thread->m_threadMutex); + thread->m_bRunning = true; + lock.Unlock(); + thread->m_threadCondition.Broadcast(); + + retVal = thread->Process(); + + lock.Lock(); + thread->m_bRunning = false; + lock.Unlock(); + thread->m_threadCondition.Broadcast(); + } + + return retVal; + } + + inline bool IsRunning(void) + { + CLockObject lock(m_threadMutex); + return m_bRunning; + } + + inline bool IsStopped(void) + { + CLockObject lock(m_threadMutex); + return m_bStop; + } + + inline bool CreateThread(bool bWait = true) + { + bool bReturn(false); + CLockObject lock(m_threadMutex); + if (!IsRunning()) + { + if (ThreadsCreate(m_thread, CThread::ThreadHandler, ((void*)static_cast(this)))) + { + if (bWait) + m_threadCondition.Wait(m_threadMutex); + bReturn = true; + } + } + return bReturn; + } + + inline bool StopThread(bool bWaitForExit = true) + { + bool bReturn(true); + bool bRunning(false); + { + CLockObject lock(m_threadMutex); + bRunning = IsRunning(); + m_bStop = true; + m_threadCondition.Broadcast(); + } + + if (bRunning && bWaitForExit) + { + void *retVal = NULL; + bReturn = ThreadsWait(m_thread, &retVal); + } + return true; + } + + inline bool Sleep(uint32_t iTimeout) + { + CLockObject lock(m_threadMutex); + return m_bStop ? false : m_threadCondition.Wait(m_threadMutex, iTimeout); + } + + virtual void *Process(void) = 0; + + protected: + void SetRunning(bool bSetTo); + + private: + bool m_bStop; + bool m_bRunning; + CCondition m_threadCondition; + CMutex m_threadMutex; + thread_t m_thread; + }; +}; diff --git a/src/lib/platform/timeutils.h b/src/lib/platform/timeutils.h index f05f7e7..b2f613a 100644 --- a/src/lib/platform/timeutils.h +++ b/src/lib/platform/timeutils.h @@ -41,10 +41,41 @@ #include #endif -#include "os-dependent.h" +#include "os.h" -namespace CEC +namespace PLATFORM { + #if defined(__WINDOWS__) + struct timezone + { + int tz_minuteswest; + int tz_dsttime; + }; + + #define usleep(t) Sleep((DWORD)(t)/1000) + + inline int gettimeofday(struct timeval *pcur_time, struct timezone *tz) + { + if (pcur_time == NULL) + { + SetLastError(EFAULT); + return -1; + } + struct _timeb current; + + _ftime(¤t); + + pcur_time->tv_sec = (long) current.time; + pcur_time->tv_usec = current.millitm * 1000L; + if (tz) + { + tz->tz_minuteswest = current.timezone; /* minutes west of Greenwich */ + tz->tz_dsttime = current.dstflag; /* type of dst correction */ + } + return 0; + } + #endif + inline int64_t GetTimeMs() { #if defined(__APPLE__) diff --git a/src/lib/platform/windows/os-threads.h b/src/lib/platform/windows/os-threads.h new file mode 100644 index 0000000..0e73868 --- /dev/null +++ b/src/lib/platform/windows/os-threads.h @@ -0,0 +1,65 @@ +#pragma once +/* + * This file is part of the libCEC(R) library. + * + * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. + * libCEC(R) is an original work, containing original code. + * + * libCEC(R) is a trademark of Pulse-Eight Limited. + * + * This program is dual-licensed; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * Alternatively, you can license this library under a commercial license, + * please contact Pulse-Eight Licensing for more information. + * + * For more information contact: + * Pulse-Eight Licensing + * http://www.pulse-eight.com/ + * http://www.pulse-eight.net/ + */ + +namespace PLATFORM +{ + #define thread_t HANDLE + #define ThreadsWait(thread, retVal) (::WaitForSingleObject(thread, INFINITE) < 0) + #define ThreadsCreate(thread, func, arg) ((thread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, NULL)) == NULL ? false : true) + + typedef CRITICAL_SECTION* mutex_t; + #define MutexCreate(mutex) ::InitializeCriticalSection(mutex = new CRITICAL_SECTION) + #define MutexDelete(mutex) ::DeleteCriticalSection(mutex); delete mutex + #define MutexLock(mutex) ::EnterCriticalSection(mutex) + #define MutexTryLock(mutex) (::TryEnterCriticalSection(mutex) != 0) + #define MutexUnlock(mutex) ::LeaveCriticalSection(mutex) + + #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) + typedef CONDITION_VARIABLE* condition_t; + #define ConditionCreate(cond) ::InitializeConditionVariable(cond = new CONDITION_VARIABLE) + #define ConditionDelete(cond) delete cond + #define ConditionSignal(cond) ::WakeConditionVariable(cond) + #define ConditionBroadcast(cond) ::WakeAllConditionVariable(cond) + #define ConditionWait(cond, mutex, timeout) (::SleepConditionVariableCS(cond, mutex, timeout <= 0 ? INFINITE : timeout) ? true : false) + #else + typedef HANDLE condition_t; + #define ConditionCreate(cond) (cond = ::CreateEvent(NULL, TRUE, FALSE, NULL)) + #define ConditionDelete(cond) ::CloseHandle(cond) + #define ConditionSignal(cond) ::SetEvent(cond) + #define ConditionBroadcast(cond) ::SetEvent(cond) + #define ConditionWait(cond, mutex, timeout) ::ResetEvent(cond); \ + MutexUnlock(mutex); \ + ::WaitForSingleObject(cond, timeout <= 0 ? 1000 : timeout); \ + MutexLock(mutex) + #endif +} diff --git a/src/lib/platform/posix/pthreads.h b/src/lib/platform/windows/os-types.h similarity index 58% rename from src/lib/platform/posix/pthreads.h rename to src/lib/platform/windows/os-types.h index b39c1e9..3943510 100644 --- a/src/lib/platform/posix/pthreads.h +++ b/src/lib/platform/windows/os-types.h @@ -31,52 +31,36 @@ * http://www.pulse-eight.net/ */ -#include "../threads.h" +#pragma warning(disable:4005) // Disable "warning C4005: '_WINSOCKAPI_' : macro redefinition" +#include +#pragma warning(default:4005) -namespace CEC -{ - class CMutex : public IMutex - { - public: - CMutex(bool bRecursive = true); - virtual ~CMutex(void); +#include +#include +#include +#include +#include +#include - virtual bool TryLock(void); - virtual bool Lock(void); - virtual void Unlock(void); +typedef signed __int8 int8_t; +typedef signed __int16 int16_t; +typedef signed __int32 int32_t; +typedef signed __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; - pthread_mutex_t m_mutex; +#define snprintf _snprintf - private: - static pthread_mutexattr_t *GetMutexAttribute(); - }; +#if defined(_MSC_VER) +#pragma warning (push) +#endif - class CCondition : public ICondition - { - public: - CCondition(void); - virtual ~CCondition(void); +#define NOGDI +#if defined(_MSC_VER) /* prevent inclusion of wingdi.h */ +#pragma warning (pop) +#endif - virtual void Broadcast(void); - virtual void Signal(void); - virtual bool Wait(IMutex *mutex, uint32_t iTimeout = 0); - - private: - pthread_cond_t m_cond; - }; - - class CThread : public IThread - { - public: - CThread(void) { }; - virtual ~CThread(void) { }; - - virtual bool CreateThread(bool bWait = true); - virtual bool StopThread(bool bWaitForExit = true); - - static void *ThreadHandler(CThread *thread); - - private: - pthread_t m_thread; - }; -}; +#pragma warning(disable:4189) /* disable 'defined but not used' */ +#pragma warning(disable:4100) /* disable 'unreferenced formal parameter' */ diff --git a/src/lib/platform/windows/os_windows.cpp b/src/lib/platform/windows/os_windows.cpp deleted file mode 100644 index 429730d..0000000 --- a/src/lib/platform/windows/os_windows.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2005-2011 Team XBMC - * http://www.xbmc.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#include "os_windows.h" -#include - -int gettimeofday(struct timeval *pcur_time, struct timezone *tz) -{ - if (pcur_time == NULL) - { - SetLastError(EFAULT); - return -1; - } - struct _timeb current; - - _ftime(¤t); - - pcur_time->tv_sec = (long) current.time; - pcur_time->tv_usec = current.millitm * 1000L; - if (tz) - { - tz->tz_minuteswest = current.timezone; /* minutes west of Greenwich */ - tz->tz_dsttime = current.dstflag; /* type of dst correction */ - } - return 0; -} diff --git a/src/lib/platform/windows/os_windows.h b/src/lib/platform/windows/os_windows.h deleted file mode 100644 index 90cc75e..0000000 --- a/src/lib/platform/windows/os_windows.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once -/* - * Copyright (C) 2011 Team XBMC - * http://www.xbmc.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#pragma warning(disable:4005) // Disable "warning C4005: '_WINSOCKAPI_' : macro redefinition" -#include -#pragma warning(default:4005) - -#if defined(_WIN32) -#include "../pthread_win32/pthread.h" -#include "../posix/pthreads.h" -#endif - -#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 -# define __USE_FILE_OFFSET64 1 -#endif - -typedef signed __int32 int32_t; -typedef signed __int64 int64_t; -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; - -#if defined __USE_FILE_OFFSET64 -typedef int64_t off_t; -typedef uint64_t ino_t; -#endif - -#define usleep(t) Sleep((t)/1000) -#define snprintf _snprintf - -#include -#include -#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ -#pragma warning (push) -#endif -/* prevent inclusion of wingdi.h */ -#define NOGDI -#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ -#pragma warning (pop) -#endif -#include -#include -#include - -struct timezone -{ - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -/*! - \brief implements similar unix call under windows - \return 0 on success, -1 on failure (if pcur_time was NULL) - \param pcur_time points to a timeval structure, should not be NULL - \param tz points to a timezone structure, may be NULL - */ -extern int gettimeofday(struct timeval *pcur_time, struct timezone *tz); diff --git a/src/lib/platform/windows/serialport.cpp b/src/lib/platform/windows/serialport.cpp index 9e4cc48..8e513fc 100644 --- a/src/lib/platform/windows/serialport.cpp +++ b/src/lib/platform/windows/serialport.cpp @@ -30,12 +30,12 @@ * http://www.pulse-eight.net/ */ -#include "../serialport.h" -#include "../baudrate.h" +#include "../serialport/serialport.h" +#include "../serialport/baudrate.h" #include "../timeutils.h" using namespace std; -using namespace CEC; +using namespace PLATFORM; void FormatWindowsError(int iErrorCode, string &strMessage) { @@ -66,7 +66,7 @@ CSerialPort::~CSerialPort(void) bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity) { CStdString strComPath = "\\\\.\\" + name; - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); m_handle = CreateFile(strComPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (m_handle == INVALID_HANDLE_VALUE) { @@ -159,7 +159,7 @@ bool CSerialPort::SetTimeouts(bool bBlocking) void CSerialPort::Close(void) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); if (m_bIsOpen) { CloseHandle(m_handle); @@ -167,26 +167,26 @@ void CSerialPort::Close(void) } } -int8_t CSerialPort::Write(CCECAdapterMessage *data) +int64_t CSerialPort::Write(uint8_t* data, uint32_t len) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); DWORD iBytesWritten = 0; if (!m_bIsOpen) return -1; - if (!WriteFile(m_handle, data->packet.data, data->size(), &iBytesWritten, NULL)) + if (!WriteFile(m_handle, data, len, &iBytesWritten, NULL)) { m_error = "Error while writing to COM port"; FormatWindowsError(GetLastError(), m_error); return -1; } - return (int8_t)iBytesWritten; + return (int64_t)iBytesWritten; } int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /* = 0 */) { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); int32_t iReturn(-1); DWORD iBytesRead = 0; if (m_handle == 0) @@ -256,6 +256,6 @@ bool CSerialPort::SetBaudRate(uint32_t baudrate) bool CSerialPort::IsOpen() { - CLockObject lock(&m_mutex); + CLockObject lock(m_mutex); return m_bIsOpen; } diff --git a/src/testclient/Makefile.am b/src/testclient/Makefile.am index 14b36f8..726cf62 100644 --- a/src/testclient/Makefile.am +++ b/src/testclient/Makefile.am @@ -1,7 +1,5 @@ bin_PROGRAMS = cec-client -cec_client_SOURCES = main.cpp \ - ../lib/platform/threads.cpp \ - ../lib/platform/posix/pthreads.cpp +cec_client_SOURCES = main.cpp cec_client_CPPFLAGS = -I@abs_top_srcdir@/include cec_client_LDFLAGS = @LIBS_DL@ \ No newline at end of file diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 256a484..8178449 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -38,12 +38,12 @@ #include #include #include -#include "../lib/platform/threads.h" -#include "../lib/util/StdString.h" +#include "../lib/platform/os.h" #include "../lib/implementations/CECCommandHandler.h" using namespace CEC; using namespace std; +using namespace PLATFORM; #define CEC_TEST_CLIENT_VERSION 1 @@ -62,7 +62,7 @@ ICECCallbacks g_callbacks; inline void PrintToStdOut(const char *strOut) { - CLockObject lock(&g_outputMutex); + CLockObject lock(g_outputMutex); cout << strOut << endl; } @@ -207,7 +207,7 @@ void ListDevices(ICECAdapter *parser) void ShowHelpCommandLine(const char* strExec) { - CLockObject lock(&g_outputMutex); + CLockObject lock(g_outputMutex); cout << endl << strExec << " {-h|--help|-l|--list-devices|[COM PORT]}" << endl << endl << @@ -254,7 +254,7 @@ ICECAdapter *CreateParser(cec_device_type_list typeList) void ShowHelpConsole(void) { - CLockObject lock(&g_outputMutex); + CLockObject lock(g_outputMutex); cout << endl << "================================================================================" << endl << "Available commands:" << endl <<