fix line endings
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@896 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
0c4789ee11
commit
683474eff9
18 changed files with 5859 additions and 5859 deletions
|
@ -1,69 +1,69 @@
|
|||
[Project]
|
||||
FileName=CheckReturn.dev
|
||||
Name=CheckReturn
|
||||
UnitCount=2
|
||||
Type=1
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
Includes=../../include
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
IsCpp=1
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=CheckReturn.exe
|
||||
HostApplication=
|
||||
Folders=
|
||||
CommandLine=
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=1000001000000001000000
|
||||
|
||||
[Unit1]
|
||||
FileName=main.cpp
|
||||
CompileCpp=1
|
||||
Folder=CheckReturn
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit2]
|
||||
FileName=..\..\include\loki\CheckReturn.h
|
||||
CompileCpp=1
|
||||
Folder=CheckReturn
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[VersionInfo]
|
||||
Major=0
|
||||
Minor=1
|
||||
Release=1
|
||||
Build=1
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
|
||||
[Project]
|
||||
FileName=CheckReturn.dev
|
||||
Name=CheckReturn
|
||||
UnitCount=2
|
||||
Type=1
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
Includes=../../include
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
IsCpp=1
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=CheckReturn.exe
|
||||
HostApplication=
|
||||
Folders=
|
||||
CommandLine=
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=1000001000000001000000
|
||||
|
||||
[Unit1]
|
||||
FileName=main.cpp
|
||||
CompileCpp=1
|
||||
Folder=CheckReturn
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit2]
|
||||
FileName=..\..\include\loki\CheckReturn.h
|
||||
CompileCpp=1
|
||||
Folder=CheckReturn
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[VersionInfo]
|
||||
Major=0
|
||||
Minor=1
|
||||
Release=1
|
||||
Build=1
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
|
||||
|
|
|
@ -1,197 +1,197 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="CheckReturn"
|
||||
ProjectGUID="{C0826A05-9143-4545-B5DE-811C188CB54E}"
|
||||
RootNamespace="CheckReturn"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\include\loki\CheckReturn.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="CheckReturn"
|
||||
ProjectGUID="{C0826A05-9143-4545-B5DE-811C188CB54E}"
|
||||
RootNamespace="CheckReturn"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\include\loki\CheckReturn.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
|
|
@ -1,198 +1,198 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="CheckReturn"
|
||||
ProjectGUID="{C0826A05-9143-4545-B5DE-811C188CB54E}"
|
||||
RootNamespace="CheckReturn"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\include\loki\CheckReturn.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="CheckReturn"
|
||||
ProjectGUID="{C0826A05-9143-4545-B5DE-811C188CB54E}"
|
||||
RootNamespace="CheckReturn"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\include\loki\CheckReturn.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
|
|
@ -1,155 +1,155 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// The Loki Library
|
||||
// Copyright (c) 2007 Rich Sposato
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
// The author makes no representations about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
#include <loki/CheckReturn.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef ::Loki::CheckReturn< bool > BoolReturn;
|
||||
|
||||
typedef ::Loki::CheckReturn< string > StringReturn;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool NoCheckRequired( void )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
BoolReturn CheckRequired( void )
|
||||
{
|
||||
return BoolReturn( true );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
BoolReturn CheckRequired( bool value )
|
||||
{
|
||||
// By passing false into CheckRequired, CheckRequired calls an overloaded
|
||||
// version of CheckRequired, thus demonstrating that one can use a function
|
||||
// call within the return statement and not have to create a named
|
||||
// temporary variable.
|
||||
if ( !value )
|
||||
return CheckRequired();
|
||||
|
||||
return BoolReturn( value );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
string GetString( void )
|
||||
{
|
||||
return string( "a" );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
StringReturn MustUseString( const char * s )
|
||||
{
|
||||
return StringReturn( s );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StringEater( const string & s )
|
||||
{
|
||||
(void)s;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main( unsigned int argc, const char * argv[] )
|
||||
{
|
||||
|
||||
if ( 2 == argc )
|
||||
{
|
||||
const char * const a = argv[ argc - 1 ];
|
||||
|
||||
// okay to call without storing or using return value.
|
||||
GetString();
|
||||
cout << "Called GetString without using return value." << endl;
|
||||
|
||||
// Should not assert since caller stores return value.
|
||||
const string s = MustUseString( a );
|
||||
cout << "Called MustUseString and stored return value." << endl;
|
||||
|
||||
{
|
||||
// Should not assert since caller passes return value into another
|
||||
// function, thus converting CheckReturn back into actual type.
|
||||
StringEater( MustUseString( a ) );
|
||||
cout <<
|
||||
"Called MustUseString and passed return value into another function."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// This should assert since caller does not check return value.
|
||||
MustUseString( s.c_str() );
|
||||
cout << "Should assert before this line! How did we get here?" << endl;
|
||||
}
|
||||
|
||||
|
||||
// okay to call without storing or using return value.
|
||||
NoCheckRequired();
|
||||
cout << "Called NoCheckRequired without using return value." << endl;
|
||||
|
||||
// Should not assert since caller stores return value.
|
||||
bool okay = CheckRequired();
|
||||
cout << "Called CheckRequired and stored return value." << endl;
|
||||
|
||||
if ( CheckRequired( okay ) )
|
||||
{
|
||||
cout << "Called CheckRequired and used return value." << endl;
|
||||
}
|
||||
|
||||
{
|
||||
// Should not assert since caller stores return value ...
|
||||
BoolReturn checkBool = CheckRequired();
|
||||
// and then deliberately ignores it before destructor runs.
|
||||
(bool)checkBool;
|
||||
cout << "Called CheckRequired, stored return value, and ignored it."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
{
|
||||
// This should not assert since caller deliberately chooses to not
|
||||
// check return value by casting to return value to correct type.
|
||||
(bool)CheckRequired();
|
||||
}
|
||||
|
||||
{
|
||||
// This should not assert since caller deliberately chooses to not
|
||||
// check return value by casting to return value to correct type.
|
||||
(bool)CheckRequired( false );
|
||||
cout << "Made a nested call to CheckRequired." << endl;
|
||||
}
|
||||
|
||||
// This should assert since caller does not check return value.
|
||||
CheckRequired();
|
||||
cout << "Should assert before this line! How did we get here?" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// $Log$
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// The Loki Library
|
||||
// Copyright (c) 2007 Rich Sposato
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
// The author makes no representations about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
#include <loki/CheckReturn.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef ::Loki::CheckReturn< bool > BoolReturn;
|
||||
|
||||
typedef ::Loki::CheckReturn< string > StringReturn;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool NoCheckRequired( void )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
BoolReturn CheckRequired( void )
|
||||
{
|
||||
return BoolReturn( true );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
BoolReturn CheckRequired( bool value )
|
||||
{
|
||||
// By passing false into CheckRequired, CheckRequired calls an overloaded
|
||||
// version of CheckRequired, thus demonstrating that one can use a function
|
||||
// call within the return statement and not have to create a named
|
||||
// temporary variable.
|
||||
if ( !value )
|
||||
return CheckRequired();
|
||||
|
||||
return BoolReturn( value );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
string GetString( void )
|
||||
{
|
||||
return string( "a" );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
StringReturn MustUseString( const char * s )
|
||||
{
|
||||
return StringReturn( s );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StringEater( const string & s )
|
||||
{
|
||||
(void)s;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main( unsigned int argc, const char * argv[] )
|
||||
{
|
||||
|
||||
if ( 2 == argc )
|
||||
{
|
||||
const char * const a = argv[ argc - 1 ];
|
||||
|
||||
// okay to call without storing or using return value.
|
||||
GetString();
|
||||
cout << "Called GetString without using return value." << endl;
|
||||
|
||||
// Should not assert since caller stores return value.
|
||||
const string s = MustUseString( a );
|
||||
cout << "Called MustUseString and stored return value." << endl;
|
||||
|
||||
{
|
||||
// Should not assert since caller passes return value into another
|
||||
// function, thus converting CheckReturn back into actual type.
|
||||
StringEater( MustUseString( a ) );
|
||||
cout <<
|
||||
"Called MustUseString and passed return value into another function."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// This should assert since caller does not check return value.
|
||||
MustUseString( s.c_str() );
|
||||
cout << "Should assert before this line! How did we get here?" << endl;
|
||||
}
|
||||
|
||||
|
||||
// okay to call without storing or using return value.
|
||||
NoCheckRequired();
|
||||
cout << "Called NoCheckRequired without using return value." << endl;
|
||||
|
||||
// Should not assert since caller stores return value.
|
||||
bool okay = CheckRequired();
|
||||
cout << "Called CheckRequired and stored return value." << endl;
|
||||
|
||||
if ( CheckRequired( okay ) )
|
||||
{
|
||||
cout << "Called CheckRequired and used return value." << endl;
|
||||
}
|
||||
|
||||
{
|
||||
// Should not assert since caller stores return value ...
|
||||
BoolReturn checkBool = CheckRequired();
|
||||
// and then deliberately ignores it before destructor runs.
|
||||
(bool)checkBool;
|
||||
cout << "Called CheckRequired, stored return value, and ignored it."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
{
|
||||
// This should not assert since caller deliberately chooses to not
|
||||
// check return value by casting to return value to correct type.
|
||||
(bool)CheckRequired();
|
||||
}
|
||||
|
||||
{
|
||||
// This should not assert since caller deliberately chooses to not
|
||||
// check return value by casting to return value to correct type.
|
||||
(bool)CheckRequired( false );
|
||||
cout << "Made a nested call to CheckRequired." << endl;
|
||||
}
|
||||
|
||||
// This should assert since caller does not check return value.
|
||||
CheckRequired();
|
||||
cout << "Should assert before this line! How did we get here?" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// $Log$
|
||||
|
|
|
@ -1,187 +1,187 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Checker"
|
||||
ProjectGUID="{2148AAC5-5CE3-493E-8D82-439ABC2E8053}"
|
||||
RootNamespace="Checker"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
FloatingPointExceptions="false"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(ProjectDir)$(ConfigurationName)\$(ProjectName).exe"
|
||||
GenerateDebugInformation="true"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
UseUnicodeResponseFiles="false"
|
||||
OutputFile="$(ProjectDir)$(ConfigurationName)\$(ProjectName).exe"
|
||||
GenerateDebugInformation="false"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\include\loki\Checker.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Checker"
|
||||
ProjectGUID="{2148AAC5-5CE3-493E-8D82-439ABC2E8053}"
|
||||
RootNamespace="Checker"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
FloatingPointExceptions="false"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(ProjectDir)$(ConfigurationName)\$(ProjectName).exe"
|
||||
GenerateDebugInformation="true"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
UseUnicodeResponseFiles="false"
|
||||
OutputFile="$(ProjectDir)$(ConfigurationName)\$(ProjectName).exe"
|
||||
GenerateDebugInformation="false"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\include\loki\Checker.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
|
|
@ -1,200 +1,200 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
/// @file main.cpp This provides examples on how to use Loki's Checker facility.
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "../../include/loki/Checker.h"
|
||||
|
||||
|
||||
#if !defined( nullptr )
|
||||
#define nullptr NULL
|
||||
#endif
|
||||
|
||||
#if !defined( NULL )
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/* This class has 2 invariants. The this pointer may never equal NULL, and the
|
||||
value may not equal zero.
|
||||
*/
|
||||
class Thingy
|
||||
{
|
||||
public:
|
||||
|
||||
// This example shows how static functions can use a no-throw checkers.
|
||||
static void ChangeThat( void )
|
||||
{
|
||||
CheckStaticForNoThrow checker( &Thingy::StaticIsValid );
|
||||
(void)checker;
|
||||
s_value--;
|
||||
}
|
||||
|
||||
// This example shows how static functions can use an invariant checkers.
|
||||
static unsigned int GetThat( void )
|
||||
{
|
||||
CheckStaticInvariants checker( &Thingy::StaticIsValid );
|
||||
(void)checker;
|
||||
return s_value;
|
||||
}
|
||||
|
||||
// This example shows how ctors can use an invariant checker.
|
||||
explicit Thingy( unsigned int value ) : m_value( value )
|
||||
{
|
||||
CheckInvariants checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
checker.Check();
|
||||
}
|
||||
|
||||
// A destructor really doesn't need a checker, but does need to confirm
|
||||
// the object is valid at the start of the destructor.
|
||||
~Thingy( void )
|
||||
{
|
||||
assert( IsValid() );
|
||||
}
|
||||
|
||||
bool operator == ( const Thingy & that ) const
|
||||
{
|
||||
return ( m_value == that.m_value );
|
||||
}
|
||||
|
||||
void DoSomethingEvil( void )
|
||||
{
|
||||
m_value = 0;
|
||||
}
|
||||
|
||||
// This example shows how to use the no-throw checker.
|
||||
unsigned int GetValue( void ) const
|
||||
{
|
||||
CheckForNoThrow checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
return m_value;
|
||||
}
|
||||
|
||||
// This example shows how to use the equality checker.
|
||||
unsigned int DoSomething( bool doThrow ) const
|
||||
{
|
||||
CheckForEquality checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
if ( doThrow )
|
||||
throw ::std::exception( "Test Exception." );
|
||||
return m_value;
|
||||
}
|
||||
|
||||
// This example shows how to use the no-change checker.
|
||||
void DoSomethingElse( void ) const
|
||||
{
|
||||
CheckForNoChange checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// This is a static validator.
|
||||
static bool StaticIsValid( void )
|
||||
{
|
||||
assert( s_value != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is a per-instance validator.
|
||||
bool IsValid( void ) const
|
||||
{
|
||||
assert( nullptr != this );
|
||||
assert( m_value != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
// These lines show how to declare checkers for non-static functions in a host class.
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoThrow > CheckForNoThrow;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoChangeOrThrow > CheckForNoChangeOrThrow;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoChange > CheckForNoChange;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForEquality > CheckForEquality;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNothing > CheckInvariants;
|
||||
|
||||
// These lines show how to declare checkers for static functions of a host class.
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
|
||||
|
||||
static unsigned int s_value;
|
||||
|
||||
unsigned int m_value;
|
||||
|
||||
};
|
||||
|
||||
unsigned int Thingy::s_value = 10;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This is a validator function called by checkers inside standalone functions.
|
||||
bool AllIsValid( void )
|
||||
{
|
||||
assert( Thingy::GetThat() != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// These lines show how to declare checkers for standalone functions.
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DoSomething( void )
|
||||
{
|
||||
// This example shows how to use a checker in a stand-alone function.
|
||||
CheckStaticForNoThrow checker( &AllIsValid );
|
||||
(void)checker;
|
||||
Thingy::ChangeThat();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main( unsigned int argc, const char * const argv[] )
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
// First do some tests on class member functions.
|
||||
Thingy t1( 1 );
|
||||
t1.DoSomething( false );
|
||||
Thingy t2( 2 );
|
||||
t2.DoSomething( true );
|
||||
|
||||
// Next do some tests with static member functions.
|
||||
Thingy::ChangeThat();
|
||||
const unsigned int value = Thingy::GetThat();
|
||||
assert( value != 0 );
|
||||
|
||||
// Then do a test with a standalone function.
|
||||
DoSomething();
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
/// @file main.cpp This provides examples on how to use Loki's Checker facility.
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "../../include/loki/Checker.h"
|
||||
|
||||
|
||||
#if !defined( nullptr )
|
||||
#define nullptr NULL
|
||||
#endif
|
||||
|
||||
#if !defined( NULL )
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/* This class has 2 invariants. The this pointer may never equal NULL, and the
|
||||
value may not equal zero.
|
||||
*/
|
||||
class Thingy
|
||||
{
|
||||
public:
|
||||
|
||||
// This example shows how static functions can use a no-throw checkers.
|
||||
static void ChangeThat( void )
|
||||
{
|
||||
CheckStaticForNoThrow checker( &Thingy::StaticIsValid );
|
||||
(void)checker;
|
||||
s_value--;
|
||||
}
|
||||
|
||||
// This example shows how static functions can use an invariant checkers.
|
||||
static unsigned int GetThat( void )
|
||||
{
|
||||
CheckStaticInvariants checker( &Thingy::StaticIsValid );
|
||||
(void)checker;
|
||||
return s_value;
|
||||
}
|
||||
|
||||
// This example shows how ctors can use an invariant checker.
|
||||
explicit Thingy( unsigned int value ) : m_value( value )
|
||||
{
|
||||
CheckInvariants checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
checker.Check();
|
||||
}
|
||||
|
||||
// A destructor really doesn't need a checker, but does need to confirm
|
||||
// the object is valid at the start of the destructor.
|
||||
~Thingy( void )
|
||||
{
|
||||
assert( IsValid() );
|
||||
}
|
||||
|
||||
bool operator == ( const Thingy & that ) const
|
||||
{
|
||||
return ( m_value == that.m_value );
|
||||
}
|
||||
|
||||
void DoSomethingEvil( void )
|
||||
{
|
||||
m_value = 0;
|
||||
}
|
||||
|
||||
// This example shows how to use the no-throw checker.
|
||||
unsigned int GetValue( void ) const
|
||||
{
|
||||
CheckForNoThrow checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
return m_value;
|
||||
}
|
||||
|
||||
// This example shows how to use the equality checker.
|
||||
unsigned int DoSomething( bool doThrow ) const
|
||||
{
|
||||
CheckForEquality checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
if ( doThrow )
|
||||
throw ::std::exception( "Test Exception." );
|
||||
return m_value;
|
||||
}
|
||||
|
||||
// This example shows how to use the no-change checker.
|
||||
void DoSomethingElse( void ) const
|
||||
{
|
||||
CheckForNoChange checker( this, &Thingy::IsValid );
|
||||
(void)checker;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// This is a static validator.
|
||||
static bool StaticIsValid( void )
|
||||
{
|
||||
assert( s_value != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is a per-instance validator.
|
||||
bool IsValid( void ) const
|
||||
{
|
||||
assert( nullptr != this );
|
||||
assert( m_value != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
// These lines show how to declare checkers for non-static functions in a host class.
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoThrow > CheckForNoThrow;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoChangeOrThrow > CheckForNoChangeOrThrow;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNoChange > CheckForNoChange;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForEquality > CheckForEquality;
|
||||
typedef ::Loki::Checker< Thingy, ::Loki::CheckForNothing > CheckInvariants;
|
||||
|
||||
// These lines show how to declare checkers for static functions of a host class.
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
|
||||
|
||||
static unsigned int s_value;
|
||||
|
||||
unsigned int m_value;
|
||||
|
||||
};
|
||||
|
||||
unsigned int Thingy::s_value = 10;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This is a validator function called by checkers inside standalone functions.
|
||||
bool AllIsValid( void )
|
||||
{
|
||||
assert( Thingy::GetThat() != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// These lines show how to declare checkers for standalone functions.
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
|
||||
typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DoSomething( void )
|
||||
{
|
||||
// This example shows how to use a checker in a stand-alone function.
|
||||
CheckStaticForNoThrow checker( &AllIsValid );
|
||||
(void)checker;
|
||||
Thingy::ChangeThat();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main( unsigned int argc, const char * const argv[] )
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
// First do some tests on class member functions.
|
||||
Thingy t1( 1 );
|
||||
t1.DoSomething( false );
|
||||
Thingy t2( 2 );
|
||||
t2.DoSomething( true );
|
||||
|
||||
// Next do some tests with static member functions.
|
||||
Thingy::ChangeThat();
|
||||
const unsigned int value = Thingy::GetThat();
|
||||
assert( value != 0 );
|
||||
|
||||
// Then do a test with a standalone function.
|
||||
DoSomething();
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -1,211 +1,211 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="LevelMutex"
|
||||
ProjectGUID="{7C09E027-5484-4641-8310-BDDEB1EC8676}"
|
||||
RootNamespace="LevelMutex"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../include/loki;../../include"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
SmallerTypeCheck="true"
|
||||
RuntimeLibrary="3"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="../../include/loki;../../include"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
StructMemberAlignment="1"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\MultiThreadTests.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Thing.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ThreadPool.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\MultiThreadTests.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Thing.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ThreadPool.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="LevelMutex"
|
||||
ProjectGUID="{7C09E027-5484-4641-8310-BDDEB1EC8676}"
|
||||
RootNamespace="LevelMutex"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../include/loki;../../include"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
SmallerTypeCheck="true"
|
||||
RuntimeLibrary="3"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="../../include/loki;../../include"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
StructMemberAlignment="1"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\main.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\MultiThreadTests.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Thing.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ThreadPool.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\MultiThreadTests.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Thing.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ThreadPool.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,55 +1,55 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef LOKI_MULTI_THREAD_TESTS_H_INCLUDED
|
||||
#define LOKI_MULTI_THREAD_TESTS_H_INCLUDED
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void SetToRedoSingleTests( bool redo );
|
||||
|
||||
bool WillRedoSingleTests( void );
|
||||
|
||||
void SingleThreadSimpleTest( void );
|
||||
|
||||
void SingleThreadReentrantTest( void );
|
||||
|
||||
void SingleThreadSimpleMultiLockTest( void );
|
||||
|
||||
void SingleThreadComplexMultiLockTest( bool doSetup );
|
||||
|
||||
void SingleThreadExceptionTest( void );
|
||||
|
||||
void MultiThreadSimpleTest( void );
|
||||
|
||||
void MultiThreadTryLockTest( void );
|
||||
|
||||
void MultiThreadReentrantTest( void );
|
||||
|
||||
void MultiThreadMultiLockTest( void );
|
||||
|
||||
void MultiThreadRandomMultiLockTest( void );
|
||||
|
||||
void MultiThreadHierarchySingleLockTest( void );
|
||||
|
||||
void MultiThreadHierarchyMultiLockTest( void );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef LOKI_MULTI_THREAD_TESTS_H_INCLUDED
|
||||
#define LOKI_MULTI_THREAD_TESTS_H_INCLUDED
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void SetToRedoSingleTests( bool redo );
|
||||
|
||||
bool WillRedoSingleTests( void );
|
||||
|
||||
void SingleThreadSimpleTest( void );
|
||||
|
||||
void SingleThreadReentrantTest( void );
|
||||
|
||||
void SingleThreadSimpleMultiLockTest( void );
|
||||
|
||||
void SingleThreadComplexMultiLockTest( bool doSetup );
|
||||
|
||||
void SingleThreadExceptionTest( void );
|
||||
|
||||
void MultiThreadSimpleTest( void );
|
||||
|
||||
void MultiThreadTryLockTest( void );
|
||||
|
||||
void MultiThreadReentrantTest( void );
|
||||
|
||||
void MultiThreadMultiLockTest( void );
|
||||
|
||||
void MultiThreadRandomMultiLockTest( void );
|
||||
|
||||
void MultiThreadHierarchySingleLockTest( void );
|
||||
|
||||
void MultiThreadHierarchyMultiLockTest( void );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,364 +1,364 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef LOKI_TEST_LEVEL_MUTEX_THING_H
|
||||
#define LOKI_TEST_LEVEL_MUTEX_THING_H
|
||||
|
||||
#include <LevelMutex.h>
|
||||
#include <Allocator.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void GoToSleep( unsigned int milliSeconds );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class ExceptionTossingMutex : public ::Loki::SleepLevelMutex
|
||||
{
|
||||
public:
|
||||
|
||||
enum ThrowingPolicy
|
||||
{
|
||||
Never,
|
||||
Always,
|
||||
Randomly
|
||||
};
|
||||
|
||||
ExceptionTossingMutex( unsigned int level );
|
||||
|
||||
virtual ~ExceptionTossingMutex( void );
|
||||
|
||||
virtual ::Loki::MutexErrors::Type Lock( void ) volatile;
|
||||
|
||||
virtual ::Loki::MutexErrors::Type TryLock( void ) volatile;
|
||||
|
||||
virtual ::Loki::MutexErrors::Type Unlock( void ) volatile;
|
||||
|
||||
inline ThrowingPolicy GetTossPolicy( void ) const { return m_policy; }
|
||||
|
||||
inline void SetTossPolicy( ThrowingPolicy policy ) { m_policy = policy; }
|
||||
|
||||
private:
|
||||
|
||||
ExceptionTossingMutex( void );
|
||||
ExceptionTossingMutex( const ExceptionTossingMutex & );
|
||||
ExceptionTossingMutex & operator = ( const ExceptionTossingMutex & );
|
||||
|
||||
ThrowingPolicy m_policy;
|
||||
};
|
||||
|
||||
typedef ::Loki::LevelMutex< ExceptionTossingMutex, 1,
|
||||
::Loki::JustReturnMutexError, ::Loki::NoMutexWait > ExceptionMutex;
|
||||
|
||||
typedef ::Loki::LevelMutex< ::Loki::SleepLevelMutex, 1,
|
||||
::Loki::JustReturnMutexError, ::Loki::MutexSleepWaits > SleepMutex;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class TestResults
|
||||
{
|
||||
public:
|
||||
|
||||
static bool Create( unsigned int threadCount );
|
||||
|
||||
static void Destroy( void );
|
||||
|
||||
inline static TestResults * GetIt( void ) { return s_instance; }
|
||||
|
||||
void Reset( unsigned int threadCount );
|
||||
|
||||
void SetResult( unsigned int threadIndex, unsigned int total,
|
||||
unsigned int fails );
|
||||
|
||||
void OutputResults( void );
|
||||
|
||||
private:
|
||||
|
||||
struct TestResult
|
||||
{
|
||||
TestResult( void );
|
||||
TestResult( const TestResult & that );
|
||||
~TestResult( void );
|
||||
unsigned int m_total;
|
||||
unsigned int m_fails;
|
||||
};
|
||||
|
||||
typedef ::std::vector< TestResult, ::Loki::LokiAllocator< TestResult > > Results;
|
||||
|
||||
explicit TestResults( unsigned int threadCount );
|
||||
|
||||
~TestResults( void );
|
||||
|
||||
TestResults( void );
|
||||
TestResults( const TestResults & );
|
||||
TestResults & operator = ( const TestResults & );
|
||||
|
||||
static TestResults * s_instance;
|
||||
|
||||
Results m_results;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class Thing
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ::std::vector< volatile Thing * > ThingPool;
|
||||
|
||||
static volatile Thing & GetIt( void ) { return *s_thing; }
|
||||
|
||||
static void Init( unsigned int value );
|
||||
|
||||
static void Destroy( void );
|
||||
|
||||
static volatile Thing * GetFromPool( unsigned int index );
|
||||
|
||||
static bool MakePool( unsigned int count );
|
||||
|
||||
static unsigned int GetPoolSize( void );
|
||||
|
||||
static void DestroyPool( void );
|
||||
|
||||
void Print( unsigned int value, unsigned int index, unsigned int startSize ) const volatile;
|
||||
|
||||
void Print( unsigned int value, unsigned int index, unsigned int startSize ) const;
|
||||
|
||||
unsigned int GetValue( void ) const volatile { return m_value; }
|
||||
|
||||
unsigned int GetValue( void ) const { return m_value; }
|
||||
|
||||
void SetValue( unsigned int value ) volatile;
|
||||
|
||||
void SetValue( unsigned int value ) { m_value = value; }
|
||||
|
||||
inline volatile SleepMutex & GetMutex( void ) volatile { return m_mutex; }
|
||||
|
||||
inline const volatile SleepMutex & GetMutex( void ) const volatile { return m_mutex; }
|
||||
|
||||
private:
|
||||
|
||||
explicit Thing( unsigned int value );
|
||||
|
||||
~Thing( void );
|
||||
|
||||
Thing( void );
|
||||
Thing( const Thing & );
|
||||
Thing & operator = ( const Thing & );
|
||||
|
||||
static volatile Thing * s_thing;
|
||||
|
||||
static ThingPool s_pool;
|
||||
|
||||
static TestResults s_results;
|
||||
|
||||
mutable volatile SleepMutex m_mutex;
|
||||
unsigned int m_value;
|
||||
};
|
||||
|
||||
typedef ::std::vector< Thing * > UnsafeThingPool;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
template < class Thingy >
|
||||
class Unlocker
|
||||
{
|
||||
public:
|
||||
explicit inline Unlocker( volatile Thingy * thing ) : m_thing( thing ) {}
|
||||
inline Unlocker( const Unlocker & that ) : m_thing( that.m_thing )
|
||||
{
|
||||
const_cast< Unlocker & >( that ).m_thing = NULL;
|
||||
}
|
||||
inline ~Unlocker( void ) { Unlock(); }
|
||||
inline void Unlock( void )
|
||||
{
|
||||
if ( NULL != m_thing )
|
||||
m_thing->UnlockHierarchy();
|
||||
}
|
||||
private:
|
||||
volatile Thingy * m_thing;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class LevelThing
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Unlocker< LevelThing > Unlocker;
|
||||
|
||||
static volatile LevelThing * GetFromPool( unsigned int index );
|
||||
|
||||
static bool MakePool( unsigned int count );
|
||||
|
||||
static void DestroyPool( void );
|
||||
|
||||
Unlocker LockHierarchy( void ) volatile;
|
||||
|
||||
void UnlockHierarchy( void ) volatile;
|
||||
|
||||
void SetValue( unsigned int value ) volatile;
|
||||
|
||||
void SetValue( unsigned int value );
|
||||
|
||||
inline unsigned int GetValue( void ) const volatile { return m_value; }
|
||||
|
||||
inline unsigned int GetValue( void ) const { return m_value; }
|
||||
|
||||
bool DoValuesMatch( unsigned int value ) const volatile;
|
||||
|
||||
bool DoValuesMatch( unsigned int value ) const;
|
||||
|
||||
inline volatile ::Loki::LevelMutexInfo & GetMutex( void ) volatile { return m_mutex; }
|
||||
|
||||
inline const volatile ::Loki::LevelMutexInfo & GetMutex( void ) const volatile { return m_mutex; }
|
||||
|
||||
private:
|
||||
|
||||
typedef ::std::vector< volatile LevelThing * > LevelThingPool;
|
||||
|
||||
LevelThing( unsigned int level, unsigned int place );
|
||||
|
||||
~LevelThing( void );
|
||||
|
||||
LevelThing( void );
|
||||
LevelThing( const LevelThing & );
|
||||
LevelThing & operator = ( const LevelThing & );
|
||||
|
||||
static LevelThingPool s_pool;
|
||||
|
||||
mutable volatile SleepMutex m_mutex;
|
||||
const unsigned int m_place;
|
||||
unsigned int m_value;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SomeThing
|
||||
{
|
||||
public:
|
||||
|
||||
SomeThing( unsigned int level, unsigned int place );
|
||||
|
||||
~SomeThing( void );
|
||||
|
||||
inline unsigned int GetLevel( void ) const volatile { return m_level; }
|
||||
|
||||
void SetValue( unsigned int value ) volatile;
|
||||
|
||||
void SetValue( unsigned int value );
|
||||
|
||||
inline unsigned int GetValue( void ) const volatile { return m_value; }
|
||||
|
||||
inline unsigned int GetValue( void ) const { return m_value; }
|
||||
|
||||
inline volatile ::Loki::LevelMutexInfo & GetMutex( void ) volatile { return m_mutex; }
|
||||
|
||||
inline const volatile ::Loki::LevelMutexInfo & GetMutex( void ) const volatile { return m_mutex; }
|
||||
|
||||
private:
|
||||
|
||||
SomeThing( void );
|
||||
SomeThing( const SomeThing & );
|
||||
SomeThing & operator = ( const SomeThing & );
|
||||
|
||||
mutable volatile SleepMutex m_mutex;
|
||||
const unsigned int m_place;
|
||||
const unsigned int m_level;
|
||||
unsigned int m_value;
|
||||
};
|
||||
|
||||
typedef ::std::vector< volatile SomeThing * > SomeThingPool;
|
||||
|
||||
typedef SomeThingPool::iterator SomeThingPoolIter;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class ManyThingsPool
|
||||
{
|
||||
public:
|
||||
|
||||
explicit ManyThingsPool( unsigned int level, unsigned int count );
|
||||
|
||||
~ManyThingsPool( void );
|
||||
|
||||
volatile SomeThing * GetFromPool( unsigned int index );
|
||||
|
||||
unsigned int GetCount( void ) const;
|
||||
|
||||
private:
|
||||
|
||||
ManyThingsPool( void );
|
||||
ManyThingsPool( const ManyThingsPool & );
|
||||
ManyThingsPool & operator = ( const ManyThingsPool & );
|
||||
|
||||
SomeThingPool m_pool;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class MultiLevelPool
|
||||
{
|
||||
public:
|
||||
|
||||
static void MakePool( unsigned int count, unsigned int thingCount );
|
||||
|
||||
static void DestroyPool( void );
|
||||
|
||||
static ManyThingsPool * GetFromPool( unsigned int index );
|
||||
|
||||
static unsigned int GetCount( void );
|
||||
|
||||
private:
|
||||
|
||||
typedef ::std::vector< ManyThingsPool * > MultiThingPool;
|
||||
|
||||
~MultiLevelPool( void );
|
||||
MultiLevelPool( void );
|
||||
MultiLevelPool( const MultiLevelPool & );
|
||||
MultiLevelPool & operator = ( const MultiLevelPool & );
|
||||
|
||||
static MultiThingPool s_pool;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount,
|
||||
unsigned int value, const SomeThingPool & pool );
|
||||
|
||||
void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount,
|
||||
unsigned int value, const SomeThingPool & pool, bool locked );
|
||||
|
||||
void MakePool( SomeThingPool & pool );
|
||||
|
||||
void LockThese( SomeThingPool & pool );
|
||||
|
||||
void UnlockThese( SomeThingPool & pool );
|
||||
|
||||
unsigned int CountLockedByThisThread( const SomeThingPool & pool );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// $Id$
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef LOKI_TEST_LEVEL_MUTEX_THING_H
|
||||
#define LOKI_TEST_LEVEL_MUTEX_THING_H
|
||||
|
||||
#include <LevelMutex.h>
|
||||
#include <Allocator.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void GoToSleep( unsigned int milliSeconds );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class ExceptionTossingMutex : public ::Loki::SleepLevelMutex
|
||||
{
|
||||
public:
|
||||
|
||||
enum ThrowingPolicy
|
||||
{
|
||||
Never,
|
||||
Always,
|
||||
Randomly
|
||||
};
|
||||
|
||||
ExceptionTossingMutex( unsigned int level );
|
||||
|
||||
virtual ~ExceptionTossingMutex( void );
|
||||
|
||||
virtual ::Loki::MutexErrors::Type Lock( void ) volatile;
|
||||
|
||||
virtual ::Loki::MutexErrors::Type TryLock( void ) volatile;
|
||||
|
||||
virtual ::Loki::MutexErrors::Type Unlock( void ) volatile;
|
||||
|
||||
inline ThrowingPolicy GetTossPolicy( void ) const { return m_policy; }
|
||||
|
||||
inline void SetTossPolicy( ThrowingPolicy policy ) { m_policy = policy; }
|
||||
|
||||
private:
|
||||
|
||||
ExceptionTossingMutex( void );
|
||||
ExceptionTossingMutex( const ExceptionTossingMutex & );
|
||||
ExceptionTossingMutex & operator = ( const ExceptionTossingMutex & );
|
||||
|
||||
ThrowingPolicy m_policy;
|
||||
};
|
||||
|
||||
typedef ::Loki::LevelMutex< ExceptionTossingMutex, 1,
|
||||
::Loki::JustReturnMutexError, ::Loki::NoMutexWait > ExceptionMutex;
|
||||
|
||||
typedef ::Loki::LevelMutex< ::Loki::SleepLevelMutex, 1,
|
||||
::Loki::JustReturnMutexError, ::Loki::MutexSleepWaits > SleepMutex;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class TestResults
|
||||
{
|
||||
public:
|
||||
|
||||
static bool Create( unsigned int threadCount );
|
||||
|
||||
static void Destroy( void );
|
||||
|
||||
inline static TestResults * GetIt( void ) { return s_instance; }
|
||||
|
||||
void Reset( unsigned int threadCount );
|
||||
|
||||
void SetResult( unsigned int threadIndex, unsigned int total,
|
||||
unsigned int fails );
|
||||
|
||||
void OutputResults( void );
|
||||
|
||||
private:
|
||||
|
||||
struct TestResult
|
||||
{
|
||||
TestResult( void );
|
||||
TestResult( const TestResult & that );
|
||||
~TestResult( void );
|
||||
unsigned int m_total;
|
||||
unsigned int m_fails;
|
||||
};
|
||||
|
||||
typedef ::std::vector< TestResult, ::Loki::LokiAllocator< TestResult > > Results;
|
||||
|
||||
explicit TestResults( unsigned int threadCount );
|
||||
|
||||
~TestResults( void );
|
||||
|
||||
TestResults( void );
|
||||
TestResults( const TestResults & );
|
||||
TestResults & operator = ( const TestResults & );
|
||||
|
||||
static TestResults * s_instance;
|
||||
|
||||
Results m_results;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class Thing
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ::std::vector< volatile Thing * > ThingPool;
|
||||
|
||||
static volatile Thing & GetIt( void ) { return *s_thing; }
|
||||
|
||||
static void Init( unsigned int value );
|
||||
|
||||
static void Destroy( void );
|
||||
|
||||
static volatile Thing * GetFromPool( unsigned int index );
|
||||
|
||||
static bool MakePool( unsigned int count );
|
||||
|
||||
static unsigned int GetPoolSize( void );
|
||||
|
||||
static void DestroyPool( void );
|
||||
|
||||
void Print( unsigned int value, unsigned int index, unsigned int startSize ) const volatile;
|
||||
|
||||
void Print( unsigned int value, unsigned int index, unsigned int startSize ) const;
|
||||
|
||||
unsigned int GetValue( void ) const volatile { return m_value; }
|
||||
|
||||
unsigned int GetValue( void ) const { return m_value; }
|
||||
|
||||
void SetValue( unsigned int value ) volatile;
|
||||
|
||||
void SetValue( unsigned int value ) { m_value = value; }
|
||||
|
||||
inline volatile SleepMutex & GetMutex( void ) volatile { return m_mutex; }
|
||||
|
||||
inline const volatile SleepMutex & GetMutex( void ) const volatile { return m_mutex; }
|
||||
|
||||
private:
|
||||
|
||||
explicit Thing( unsigned int value );
|
||||
|
||||
~Thing( void );
|
||||
|
||||
Thing( void );
|
||||
Thing( const Thing & );
|
||||
Thing & operator = ( const Thing & );
|
||||
|
||||
static volatile Thing * s_thing;
|
||||
|
||||
static ThingPool s_pool;
|
||||
|
||||
static TestResults s_results;
|
||||
|
||||
mutable volatile SleepMutex m_mutex;
|
||||
unsigned int m_value;
|
||||
};
|
||||
|
||||
typedef ::std::vector< Thing * > UnsafeThingPool;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
template < class Thingy >
|
||||
class Unlocker
|
||||
{
|
||||
public:
|
||||
explicit inline Unlocker( volatile Thingy * thing ) : m_thing( thing ) {}
|
||||
inline Unlocker( const Unlocker & that ) : m_thing( that.m_thing )
|
||||
{
|
||||
const_cast< Unlocker & >( that ).m_thing = NULL;
|
||||
}
|
||||
inline ~Unlocker( void ) { Unlock(); }
|
||||
inline void Unlock( void )
|
||||
{
|
||||
if ( NULL != m_thing )
|
||||
m_thing->UnlockHierarchy();
|
||||
}
|
||||
private:
|
||||
volatile Thingy * m_thing;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class LevelThing
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Unlocker< LevelThing > Unlocker;
|
||||
|
||||
static volatile LevelThing * GetFromPool( unsigned int index );
|
||||
|
||||
static bool MakePool( unsigned int count );
|
||||
|
||||
static void DestroyPool( void );
|
||||
|
||||
Unlocker LockHierarchy( void ) volatile;
|
||||
|
||||
void UnlockHierarchy( void ) volatile;
|
||||
|
||||
void SetValue( unsigned int value ) volatile;
|
||||
|
||||
void SetValue( unsigned int value );
|
||||
|
||||
inline unsigned int GetValue( void ) const volatile { return m_value; }
|
||||
|
||||
inline unsigned int GetValue( void ) const { return m_value; }
|
||||
|
||||
bool DoValuesMatch( unsigned int value ) const volatile;
|
||||
|
||||
bool DoValuesMatch( unsigned int value ) const;
|
||||
|
||||
inline volatile ::Loki::LevelMutexInfo & GetMutex( void ) volatile { return m_mutex; }
|
||||
|
||||
inline const volatile ::Loki::LevelMutexInfo & GetMutex( void ) const volatile { return m_mutex; }
|
||||
|
||||
private:
|
||||
|
||||
typedef ::std::vector< volatile LevelThing * > LevelThingPool;
|
||||
|
||||
LevelThing( unsigned int level, unsigned int place );
|
||||
|
||||
~LevelThing( void );
|
||||
|
||||
LevelThing( void );
|
||||
LevelThing( const LevelThing & );
|
||||
LevelThing & operator = ( const LevelThing & );
|
||||
|
||||
static LevelThingPool s_pool;
|
||||
|
||||
mutable volatile SleepMutex m_mutex;
|
||||
const unsigned int m_place;
|
||||
unsigned int m_value;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SomeThing
|
||||
{
|
||||
public:
|
||||
|
||||
SomeThing( unsigned int level, unsigned int place );
|
||||
|
||||
~SomeThing( void );
|
||||
|
||||
inline unsigned int GetLevel( void ) const volatile { return m_level; }
|
||||
|
||||
void SetValue( unsigned int value ) volatile;
|
||||
|
||||
void SetValue( unsigned int value );
|
||||
|
||||
inline unsigned int GetValue( void ) const volatile { return m_value; }
|
||||
|
||||
inline unsigned int GetValue( void ) const { return m_value; }
|
||||
|
||||
inline volatile ::Loki::LevelMutexInfo & GetMutex( void ) volatile { return m_mutex; }
|
||||
|
||||
inline const volatile ::Loki::LevelMutexInfo & GetMutex( void ) const volatile { return m_mutex; }
|
||||
|
||||
private:
|
||||
|
||||
SomeThing( void );
|
||||
SomeThing( const SomeThing & );
|
||||
SomeThing & operator = ( const SomeThing & );
|
||||
|
||||
mutable volatile SleepMutex m_mutex;
|
||||
const unsigned int m_place;
|
||||
const unsigned int m_level;
|
||||
unsigned int m_value;
|
||||
};
|
||||
|
||||
typedef ::std::vector< volatile SomeThing * > SomeThingPool;
|
||||
|
||||
typedef SomeThingPool::iterator SomeThingPoolIter;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class ManyThingsPool
|
||||
{
|
||||
public:
|
||||
|
||||
explicit ManyThingsPool( unsigned int level, unsigned int count );
|
||||
|
||||
~ManyThingsPool( void );
|
||||
|
||||
volatile SomeThing * GetFromPool( unsigned int index );
|
||||
|
||||
unsigned int GetCount( void ) const;
|
||||
|
||||
private:
|
||||
|
||||
ManyThingsPool( void );
|
||||
ManyThingsPool( const ManyThingsPool & );
|
||||
ManyThingsPool & operator = ( const ManyThingsPool & );
|
||||
|
||||
SomeThingPool m_pool;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class MultiLevelPool
|
||||
{
|
||||
public:
|
||||
|
||||
static void MakePool( unsigned int count, unsigned int thingCount );
|
||||
|
||||
static void DestroyPool( void );
|
||||
|
||||
static ManyThingsPool * GetFromPool( unsigned int index );
|
||||
|
||||
static unsigned int GetCount( void );
|
||||
|
||||
private:
|
||||
|
||||
typedef ::std::vector< ManyThingsPool * > MultiThingPool;
|
||||
|
||||
~MultiLevelPool( void );
|
||||
MultiLevelPool( void );
|
||||
MultiLevelPool( const MultiLevelPool & );
|
||||
MultiLevelPool & operator = ( const MultiLevelPool & );
|
||||
|
||||
static MultiThingPool s_pool;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount,
|
||||
unsigned int value, const SomeThingPool & pool );
|
||||
|
||||
void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount,
|
||||
unsigned int value, const SomeThingPool & pool, bool locked );
|
||||
|
||||
void MakePool( SomeThingPool & pool );
|
||||
|
||||
void LockThese( SomeThingPool & pool );
|
||||
|
||||
void UnlockThese( SomeThingPool & pool );
|
||||
|
||||
unsigned int CountLockedByThisThread( const SomeThingPool & pool );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,390 +1,390 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <process.h>
|
||||
|
||||
|
||||
using namespace ::std;
|
||||
|
||||
// define nullptr even though new compilers will have this keyword just so we
|
||||
// have a consistent and easy way of identifying which uses of 0 mean null.
|
||||
#define nullptr 0
|
||||
|
||||
#if defined( DEBUG ) || defined( _DEBUG )
|
||||
#define LOKI_DEBUG_CODE( code ) code;
|
||||
#else
|
||||
#define LOKI_DEBUG_CODE( code ) ;
|
||||
#endif
|
||||
|
||||
|
||||
volatile Thread * Thread::s_thread = nullptr;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Thread::Thread( volatile ThreadPool * owner ) :
|
||||
m_thread(),
|
||||
m_func( nullptr ),
|
||||
m_parm( nullptr ),
|
||||
m_status( Thread::Idle ),
|
||||
m_stop( false ),
|
||||
m_owner( owner )
|
||||
{
|
||||
assert( IsValid( owner ) );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Thread::Thread( volatile ThreadPool * owner, CallFunction function,
|
||||
void * parm ) :
|
||||
m_thread(),
|
||||
m_func( function ),
|
||||
m_parm( parm ),
|
||||
m_status( Thread::Starting ),
|
||||
m_stop( false ),
|
||||
m_owner( owner )
|
||||
{
|
||||
assert( IsValid( owner ) );
|
||||
assert( nullptr != m_func );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Thread::~Thread( void )
|
||||
{
|
||||
assert( IsValid( m_owner ) );
|
||||
assert( Thread::Dead == m_status );
|
||||
assert( nullptr == m_func );
|
||||
assert( nullptr == m_parm );
|
||||
assert( m_stop );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool Thread::WaitForThread( void ) volatile
|
||||
{
|
||||
assert( IsValid( m_owner ) );
|
||||
const volatile Thread * current = Thread::GetCurrentThread();
|
||||
if ( this == current )
|
||||
return false;
|
||||
if ( m_status == Thread::Dead )
|
||||
return false;
|
||||
while ( this->m_status == Thread::Active )
|
||||
{
|
||||
// Call the wait policy.
|
||||
#if defined( _MSC_VER )
|
||||
::SleepEx( 1, true );
|
||||
#else
|
||||
::sleep( 1 );
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool Thread::IsValid( const volatile ThreadPool * owner ) const volatile
|
||||
{
|
||||
assert( nullptr != this );
|
||||
assert( nullptr != m_owner );
|
||||
assert( nullptr != owner );
|
||||
assert( m_owner == owner );
|
||||
switch ( m_status )
|
||||
{
|
||||
case Thread::Dead:
|
||||
case Thread::Idle:
|
||||
assert( nullptr == m_func );
|
||||
assert( nullptr == m_parm );
|
||||
break;
|
||||
case Thread::Active:
|
||||
case Thread::Starting:
|
||||
assert( nullptr != m_func );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ThreadPool::ThreadPool( unsigned int threadCount ) :
|
||||
m_threads()
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
if ( 0 < threadCount )
|
||||
Create( threadCount );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ThreadPool::~ThreadPool( void )
|
||||
{
|
||||
assert( IsValid() );
|
||||
|
||||
ThreadsIter end( m_threads.end() );
|
||||
for ( ThreadsIter it( m_threads.begin() ); it != end; ++it )
|
||||
{
|
||||
try
|
||||
{
|
||||
volatile Thread * thread = *it;
|
||||
assert( nullptr != thread );
|
||||
thread->m_stop = true;
|
||||
thread->WaitForThread();
|
||||
if ( thread->GetStatus() == Thread::Idle )
|
||||
thread->m_status = Thread::Dead;
|
||||
LokiThreadJoin( thread->m_thread );
|
||||
*it = nullptr;
|
||||
delete thread;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
unsigned int ThreadPool::Create( unsigned int threadCount ) volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
const unsigned int countNow = GetCount( Thread::Idle );
|
||||
if ( threadCount <= countNow )
|
||||
return threadCount;
|
||||
|
||||
const unsigned int totalCount = pThis->m_threads.size();
|
||||
const unsigned int howManyToAdd = threadCount - countNow;
|
||||
if ( pThis->m_threads.capacity() <= howManyToAdd )
|
||||
pThis->m_threads.reserve( totalCount + howManyToAdd );
|
||||
for ( unsigned int ii = 0; ii < howManyToAdd; ++ii )
|
||||
{
|
||||
#if defined( _MSC_VER )
|
||||
volatile Thread * thread = new Thread( this );
|
||||
#else
|
||||
Thread * thread = new Thread( this );
|
||||
#endif
|
||||
pThis->m_threads.push_back( thread );
|
||||
Thread * pThread = const_cast< Thread * >( thread );
|
||||
void * p = reinterpret_cast< void * >( pThread );
|
||||
// Call thread creation policy?
|
||||
LokiThreadCreate( &thread->m_thread, nullptr, TopFunction, p );
|
||||
}
|
||||
|
||||
return howManyToAdd;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
unsigned int ThreadPool::GetCount( void ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
const unsigned int count = pThis->m_threads.size();
|
||||
return count;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
unsigned int ThreadPool::GetCount( Thread::Status status ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
const unsigned int totalCount = pThis->m_threads.size();
|
||||
unsigned int count = 0;
|
||||
for ( size_t ii = 0; ii < totalCount; ii++ )
|
||||
{
|
||||
const volatile Thread * thread = pThis->m_threads.at( ii );
|
||||
assert( nullptr != thread );
|
||||
if ( thread->GetStatus() == status )
|
||||
++count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
volatile const Thread * ThreadPool::GetThread( unsigned int index ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
if ( pThis->m_threads.size() <= index )
|
||||
return nullptr;
|
||||
volatile const Thread * thread = pThis->m_threads[ index ];
|
||||
return thread;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ThreadPool::Join( unsigned int index ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
if ( pThis->m_threads.size() <= index )
|
||||
return;
|
||||
volatile Thread * thread = pThis->m_threads[ index ];
|
||||
thread->WaitForThread();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ThreadPool::JoinAll( void ) volatile const
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
for ( size_t ii = 0; ii < pThis->m_threads.size(); ii++ )
|
||||
{
|
||||
volatile Thread * thread = pThis->m_threads.at( ii );
|
||||
assert( nullptr != thread );
|
||||
thread->WaitForThread();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
volatile Thread * ThreadPool::Start( CallFunction function, void * parm ) volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
if ( nullptr == function )
|
||||
return nullptr;
|
||||
#if defined( _MSC_VER )
|
||||
volatile Thread * thread = nullptr;
|
||||
#else
|
||||
Thread * thread = nullptr;
|
||||
#endif
|
||||
bool foundOne = false;
|
||||
|
||||
for ( size_t ii = 0; ii < pThis->m_threads.size(); ii++ )
|
||||
{
|
||||
#if defined( _MSC_VER )
|
||||
thread = pThis->m_threads.at( ii );
|
||||
#else
|
||||
thread = const_cast< Thread * >( pThis->m_threads.at( ii ) );
|
||||
#endif
|
||||
assert( nullptr != thread );
|
||||
if ( Thread::Idle == thread->m_status )
|
||||
{
|
||||
foundOne = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( foundOne )
|
||||
{
|
||||
thread->m_func = function;
|
||||
thread->m_parm = parm;
|
||||
thread->m_status = Thread::Starting;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Did not find an idle thread, so start a new one.
|
||||
thread = new Thread( this, function, parm );
|
||||
pThis->m_threads.push_back( thread );
|
||||
Thread * pThread = const_cast< Thread * >( thread );
|
||||
void * p = reinterpret_cast< void * >( pThread );
|
||||
// Call to thread creation policy?
|
||||
LokiThreadCreate( &thread->m_thread, nullptr, TopFunction, p );
|
||||
}
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
unsigned int ThreadPool::TopFunction( void * p )
|
||||
#else
|
||||
void * ThreadPool::TopFunction( void * p )
|
||||
#endif
|
||||
{
|
||||
assert( nullptr != p );
|
||||
|
||||
volatile Thread * thread = reinterpret_cast< volatile Thread * >( p );
|
||||
Thread::SetCurrentThread( thread );
|
||||
while ( ( thread->m_status != Thread::Dead ) && ( !thread->m_stop ) )
|
||||
{
|
||||
// Call the thread's WaitPolicy here?
|
||||
#if defined( _MSC_VER )
|
||||
::SleepEx( 1, true );
|
||||
#else
|
||||
::sleep( 1 );
|
||||
#endif
|
||||
if ( thread->m_status == Thread::Starting )
|
||||
{
|
||||
try
|
||||
{
|
||||
assert( nullptr != thread->m_func );
|
||||
thread->m_status = Thread::Active;
|
||||
thread->m_func( thread->m_parm );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
// What to do in case of exception?
|
||||
// Call an exception policy?
|
||||
}
|
||||
thread->m_status = Thread::Idle;
|
||||
thread->m_func = nullptr;
|
||||
thread->m_parm = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
return 0;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool ThreadPool::IsValid( void ) const volatile
|
||||
{
|
||||
assert( nullptr != this );
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
ThreadsCIter end( pThis->m_threads.end() );
|
||||
for ( ThreadsCIter it( pThis->m_threads.begin() ); it != end; ++it )
|
||||
{
|
||||
const volatile Thread * thread = *it;
|
||||
assert( nullptr != thread );
|
||||
assert( thread->IsValid( this ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <process.h>
|
||||
|
||||
|
||||
using namespace ::std;
|
||||
|
||||
// define nullptr even though new compilers will have this keyword just so we
|
||||
// have a consistent and easy way of identifying which uses of 0 mean null.
|
||||
#define nullptr 0
|
||||
|
||||
#if defined( DEBUG ) || defined( _DEBUG )
|
||||
#define LOKI_DEBUG_CODE( code ) code;
|
||||
#else
|
||||
#define LOKI_DEBUG_CODE( code ) ;
|
||||
#endif
|
||||
|
||||
|
||||
volatile Thread * Thread::s_thread = nullptr;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Thread::Thread( volatile ThreadPool * owner ) :
|
||||
m_thread(),
|
||||
m_func( nullptr ),
|
||||
m_parm( nullptr ),
|
||||
m_status( Thread::Idle ),
|
||||
m_stop( false ),
|
||||
m_owner( owner )
|
||||
{
|
||||
assert( IsValid( owner ) );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Thread::Thread( volatile ThreadPool * owner, CallFunction function,
|
||||
void * parm ) :
|
||||
m_thread(),
|
||||
m_func( function ),
|
||||
m_parm( parm ),
|
||||
m_status( Thread::Starting ),
|
||||
m_stop( false ),
|
||||
m_owner( owner )
|
||||
{
|
||||
assert( IsValid( owner ) );
|
||||
assert( nullptr != m_func );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Thread::~Thread( void )
|
||||
{
|
||||
assert( IsValid( m_owner ) );
|
||||
assert( Thread::Dead == m_status );
|
||||
assert( nullptr == m_func );
|
||||
assert( nullptr == m_parm );
|
||||
assert( m_stop );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool Thread::WaitForThread( void ) volatile
|
||||
{
|
||||
assert( IsValid( m_owner ) );
|
||||
const volatile Thread * current = Thread::GetCurrentThread();
|
||||
if ( this == current )
|
||||
return false;
|
||||
if ( m_status == Thread::Dead )
|
||||
return false;
|
||||
while ( this->m_status == Thread::Active )
|
||||
{
|
||||
// Call the wait policy.
|
||||
#if defined( _MSC_VER )
|
||||
::SleepEx( 1, true );
|
||||
#else
|
||||
::sleep( 1 );
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool Thread::IsValid( const volatile ThreadPool * owner ) const volatile
|
||||
{
|
||||
assert( nullptr != this );
|
||||
assert( nullptr != m_owner );
|
||||
assert( nullptr != owner );
|
||||
assert( m_owner == owner );
|
||||
switch ( m_status )
|
||||
{
|
||||
case Thread::Dead:
|
||||
case Thread::Idle:
|
||||
assert( nullptr == m_func );
|
||||
assert( nullptr == m_parm );
|
||||
break;
|
||||
case Thread::Active:
|
||||
case Thread::Starting:
|
||||
assert( nullptr != m_func );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ThreadPool::ThreadPool( unsigned int threadCount ) :
|
||||
m_threads()
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
if ( 0 < threadCount )
|
||||
Create( threadCount );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ThreadPool::~ThreadPool( void )
|
||||
{
|
||||
assert( IsValid() );
|
||||
|
||||
ThreadsIter end( m_threads.end() );
|
||||
for ( ThreadsIter it( m_threads.begin() ); it != end; ++it )
|
||||
{
|
||||
try
|
||||
{
|
||||
volatile Thread * thread = *it;
|
||||
assert( nullptr != thread );
|
||||
thread->m_stop = true;
|
||||
thread->WaitForThread();
|
||||
if ( thread->GetStatus() == Thread::Idle )
|
||||
thread->m_status = Thread::Dead;
|
||||
LokiThreadJoin( thread->m_thread );
|
||||
*it = nullptr;
|
||||
delete thread;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
unsigned int ThreadPool::Create( unsigned int threadCount ) volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
const unsigned int countNow = GetCount( Thread::Idle );
|
||||
if ( threadCount <= countNow )
|
||||
return threadCount;
|
||||
|
||||
const unsigned int totalCount = pThis->m_threads.size();
|
||||
const unsigned int howManyToAdd = threadCount - countNow;
|
||||
if ( pThis->m_threads.capacity() <= howManyToAdd )
|
||||
pThis->m_threads.reserve( totalCount + howManyToAdd );
|
||||
for ( unsigned int ii = 0; ii < howManyToAdd; ++ii )
|
||||
{
|
||||
#if defined( _MSC_VER )
|
||||
volatile Thread * thread = new Thread( this );
|
||||
#else
|
||||
Thread * thread = new Thread( this );
|
||||
#endif
|
||||
pThis->m_threads.push_back( thread );
|
||||
Thread * pThread = const_cast< Thread * >( thread );
|
||||
void * p = reinterpret_cast< void * >( pThread );
|
||||
// Call thread creation policy?
|
||||
LokiThreadCreate( &thread->m_thread, nullptr, TopFunction, p );
|
||||
}
|
||||
|
||||
return howManyToAdd;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
unsigned int ThreadPool::GetCount( void ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
const unsigned int count = pThis->m_threads.size();
|
||||
return count;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
unsigned int ThreadPool::GetCount( Thread::Status status ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
const unsigned int totalCount = pThis->m_threads.size();
|
||||
unsigned int count = 0;
|
||||
for ( size_t ii = 0; ii < totalCount; ii++ )
|
||||
{
|
||||
const volatile Thread * thread = pThis->m_threads.at( ii );
|
||||
assert( nullptr != thread );
|
||||
if ( thread->GetStatus() == status )
|
||||
++count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
volatile const Thread * ThreadPool::GetThread( unsigned int index ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
if ( pThis->m_threads.size() <= index )
|
||||
return nullptr;
|
||||
volatile const Thread * thread = pThis->m_threads[ index ];
|
||||
return thread;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ThreadPool::Join( unsigned int index ) const volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
if ( pThis->m_threads.size() <= index )
|
||||
return;
|
||||
volatile Thread * thread = pThis->m_threads[ index ];
|
||||
thread->WaitForThread();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ThreadPool::JoinAll( void ) volatile const
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
for ( size_t ii = 0; ii < pThis->m_threads.size(); ii++ )
|
||||
{
|
||||
volatile Thread * thread = pThis->m_threads.at( ii );
|
||||
assert( nullptr != thread );
|
||||
thread->WaitForThread();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
volatile Thread * ThreadPool::Start( CallFunction function, void * parm ) volatile
|
||||
{
|
||||
assert( IsValid() );
|
||||
LOKI_DEBUG_CODE( Checker checker( this ); (void)checker; )
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
|
||||
if ( nullptr == function )
|
||||
return nullptr;
|
||||
#if defined( _MSC_VER )
|
||||
volatile Thread * thread = nullptr;
|
||||
#else
|
||||
Thread * thread = nullptr;
|
||||
#endif
|
||||
bool foundOne = false;
|
||||
|
||||
for ( size_t ii = 0; ii < pThis->m_threads.size(); ii++ )
|
||||
{
|
||||
#if defined( _MSC_VER )
|
||||
thread = pThis->m_threads.at( ii );
|
||||
#else
|
||||
thread = const_cast< Thread * >( pThis->m_threads.at( ii ) );
|
||||
#endif
|
||||
assert( nullptr != thread );
|
||||
if ( Thread::Idle == thread->m_status )
|
||||
{
|
||||
foundOne = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( foundOne )
|
||||
{
|
||||
thread->m_func = function;
|
||||
thread->m_parm = parm;
|
||||
thread->m_status = Thread::Starting;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Did not find an idle thread, so start a new one.
|
||||
thread = new Thread( this, function, parm );
|
||||
pThis->m_threads.push_back( thread );
|
||||
Thread * pThread = const_cast< Thread * >( thread );
|
||||
void * p = reinterpret_cast< void * >( pThread );
|
||||
// Call to thread creation policy?
|
||||
LokiThreadCreate( &thread->m_thread, nullptr, TopFunction, p );
|
||||
}
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
unsigned int ThreadPool::TopFunction( void * p )
|
||||
#else
|
||||
void * ThreadPool::TopFunction( void * p )
|
||||
#endif
|
||||
{
|
||||
assert( nullptr != p );
|
||||
|
||||
volatile Thread * thread = reinterpret_cast< volatile Thread * >( p );
|
||||
Thread::SetCurrentThread( thread );
|
||||
while ( ( thread->m_status != Thread::Dead ) && ( !thread->m_stop ) )
|
||||
{
|
||||
// Call the thread's WaitPolicy here?
|
||||
#if defined( _MSC_VER )
|
||||
::SleepEx( 1, true );
|
||||
#else
|
||||
::sleep( 1 );
|
||||
#endif
|
||||
if ( thread->m_status == Thread::Starting )
|
||||
{
|
||||
try
|
||||
{
|
||||
assert( nullptr != thread->m_func );
|
||||
thread->m_status = Thread::Active;
|
||||
thread->m_func( thread->m_parm );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
// What to do in case of exception?
|
||||
// Call an exception policy?
|
||||
}
|
||||
thread->m_status = Thread::Idle;
|
||||
thread->m_func = nullptr;
|
||||
thread->m_parm = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
return 0;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool ThreadPool::IsValid( void ) const volatile
|
||||
{
|
||||
assert( nullptr != this );
|
||||
ThreadPool * pThis = const_cast< ThreadPool * >( this );
|
||||
ThreadsCIter end( pThis->m_threads.end() );
|
||||
for ( ThreadsCIter it( pThis->m_threads.begin() ); it != end; ++it )
|
||||
{
|
||||
const volatile Thread * thread = *it;
|
||||
assert( nullptr != thread );
|
||||
assert( thread->IsValid( this ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -1,226 +1,226 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <vector>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef void * ( * CallFunction )( void * );
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
#include <Windows.h>
|
||||
|
||||
#define LokiThread HANDLE
|
||||
|
||||
#define LokiThreadCreate( handle, attr, func, arg ) \
|
||||
(int)(( * handle = ( HANDLE ) _beginthreadex ( nullptr, 0, func, arg, 0, nullptr ) ) == nullptr )
|
||||
|
||||
#define LokiThreadJoin( thread ) \
|
||||
((::WaitForSingleObject((thread),INFINITE)!=WAIT_OBJECT_0) || !CloseHandle(thread))
|
||||
|
||||
#else
|
||||
#include <pthread.h>
|
||||
|
||||
typedef void * ( * CallFunction )( void * );
|
||||
|
||||
#define LokiThread pthread_t
|
||||
#define LokiThreadCreate( handle, attr, func, arg ) \
|
||||
pthread_create( handle, attr, func, arg )
|
||||
#define LokiThreadJoin( thread ) pthread_join( thread, NULL )
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/** @par thread_local Keyword
|
||||
The mutexes require compilers to provide thread local storage - meaning each
|
||||
thread gets its own copy of the data. The next version of C++ will have a
|
||||
new keyword, thread_local for that purpose. Some existing compilers already
|
||||
provide thread local storage using different syntax, so these lines use
|
||||
thread_local to mimic that syntax. If your compiler provides thread local
|
||||
storage but using different syntax besides "thread_local", you may want to
|
||||
modify these lines. If your compiler does not support thread local storage,
|
||||
you can't use LevelMutex.
|
||||
*/
|
||||
#ifndef LOKI_THREAD_LOCAL
|
||||
#if defined( _MSC_VER )
|
||||
#if ( _MSC_VER >= 1300 )
|
||||
#define LOKI_THREAD_LOCAL __declspec( thread )
|
||||
#else
|
||||
#error "Only Visual Studio versions 7.0 and after supported."
|
||||
#endif
|
||||
|
||||
#elif ( __GNUC__ )
|
||||
#define LOKI_THREAD_LOCAL __thread
|
||||
|
||||
#else
|
||||
#warning "Check if your compiler provides thread local storage."
|
||||
#define LOKI_THREAD_LOCAL thread_local
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
class ThreadPool;
|
||||
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
|
||||
enum Status
|
||||
{
|
||||
Dead = 0,
|
||||
Idle,
|
||||
Starting,
|
||||
Active
|
||||
};
|
||||
|
||||
inline static volatile Thread * GetCurrentThread( void )
|
||||
{
|
||||
return s_thread;
|
||||
}
|
||||
|
||||
bool WaitForThread( void ) volatile;
|
||||
|
||||
inline CallFunction GetFunction( void ) const volatile { return m_func; }
|
||||
|
||||
inline void * GetParameter( void ) const volatile { return m_parm; }
|
||||
|
||||
inline Status GetStatus( void ) const volatile { return m_status; }
|
||||
|
||||
inline const volatile ThreadPool * GetThreadPool( void ) const volatile
|
||||
{
|
||||
return m_owner;
|
||||
}
|
||||
|
||||
inline volatile ThreadPool * GetThreadPool( void ) volatile
|
||||
{
|
||||
return m_owner;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class ThreadPool;
|
||||
|
||||
inline static void SetCurrentThread( volatile Thread * thread )
|
||||
{
|
||||
s_thread = thread;
|
||||
}
|
||||
|
||||
explicit Thread( volatile ThreadPool * owner );
|
||||
|
||||
Thread( volatile ThreadPool * owner, CallFunction function, void * parm );
|
||||
|
||||
~Thread( void );
|
||||
|
||||
/// Default constructor not implemented.
|
||||
Thread( void );
|
||||
|
||||
/// not implemented.
|
||||
Thread( const Thread & );
|
||||
|
||||
/// not implemented.
|
||||
Thread & operator = ( const Thread & );
|
||||
|
||||
bool IsValid( const volatile ThreadPool * owner ) const volatile;
|
||||
|
||||
static LOKI_THREAD_LOCAL volatile Thread * s_thread;
|
||||
|
||||
LokiThread m_thread;
|
||||
CallFunction m_func;
|
||||
void * m_parm;
|
||||
Status m_status;
|
||||
bool m_stop;
|
||||
volatile ThreadPool * const m_owner;
|
||||
};
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
|
||||
explicit ThreadPool( unsigned int threadCount = 0 );
|
||||
|
||||
~ThreadPool( void );
|
||||
|
||||
unsigned int Create( unsigned int threadCount ) volatile;
|
||||
|
||||
volatile Thread * Start( CallFunction function, void * parm ) volatile;
|
||||
|
||||
void Join( unsigned int index ) const volatile;
|
||||
|
||||
void JoinAll( void ) const volatile;
|
||||
|
||||
unsigned int GetCount( void ) const volatile;
|
||||
|
||||
unsigned int GetCount( Thread::Status status ) const volatile;
|
||||
|
||||
volatile const Thread * GetThread( unsigned int index ) const volatile;
|
||||
|
||||
inline volatile Thread * GetThread( unsigned int index ) volatile
|
||||
{
|
||||
return const_cast< volatile Thread * >(
|
||||
const_cast< const volatile ThreadPool * >( this )->
|
||||
GetThread( index ) );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** @class Checker
|
||||
Performs validity check on ThreadPool to insure no class invariants were
|
||||
violated inside any member function. This class only gets used in debug
|
||||
builds, and any instance of it gets optimized away in a release build. A
|
||||
checker is created inside many of member functions so that it's destructor
|
||||
gets called when the function exits.
|
||||
*/
|
||||
class Checker
|
||||
{
|
||||
public:
|
||||
inline explicit Checker( const volatile ThreadPool * mutex ) :
|
||||
m_pool( mutex ) {}
|
||||
inline ~Checker( void ) { m_pool->IsValid(); }
|
||||
private:
|
||||
Checker( void );
|
||||
Checker( const Checker & );
|
||||
Checker & operator = ( const Checker & );
|
||||
const volatile ThreadPool * m_pool;
|
||||
};
|
||||
|
||||
/// Copy-constructor is not implemented.
|
||||
ThreadPool( const ThreadPool & );
|
||||
|
||||
/// Copy-assignment operator is not implemented.
|
||||
ThreadPool & operator = ( const ThreadPool & );
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
static unsigned int __stdcall TopFunction( void * p );
|
||||
#else
|
||||
static void * TopFunction( void * p );
|
||||
#endif
|
||||
|
||||
/** Returns true if no class invariant broken, otherwise asserts. This function
|
||||
only gets called in debug builds.
|
||||
*/
|
||||
bool IsValid( void ) const volatile;
|
||||
|
||||
typedef ::std::vector< volatile Thread * > Threads;
|
||||
typedef Threads::iterator ThreadsIter;
|
||||
typedef Threads::const_iterator ThreadsCIter;
|
||||
|
||||
Threads m_threads;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Part of LevelMutex test program for The Loki Library
|
||||
// Copyright (c) 2008 Richard Sposato
|
||||
// The copyright on this file is protected under the terms of the MIT license.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
//
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <vector>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef void * ( * CallFunction )( void * );
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
#include <Windows.h>
|
||||
|
||||
#define LokiThread HANDLE
|
||||
|
||||
#define LokiThreadCreate( handle, attr, func, arg ) \
|
||||
(int)(( * handle = ( HANDLE ) _beginthreadex ( nullptr, 0, func, arg, 0, nullptr ) ) == nullptr )
|
||||
|
||||
#define LokiThreadJoin( thread ) \
|
||||
((::WaitForSingleObject((thread),INFINITE)!=WAIT_OBJECT_0) || !CloseHandle(thread))
|
||||
|
||||
#else
|
||||
#include <pthread.h>
|
||||
|
||||
typedef void * ( * CallFunction )( void * );
|
||||
|
||||
#define LokiThread pthread_t
|
||||
#define LokiThreadCreate( handle, attr, func, arg ) \
|
||||
pthread_create( handle, attr, func, arg )
|
||||
#define LokiThreadJoin( thread ) pthread_join( thread, NULL )
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/** @par thread_local Keyword
|
||||
The mutexes require compilers to provide thread local storage - meaning each
|
||||
thread gets its own copy of the data. The next version of C++ will have a
|
||||
new keyword, thread_local for that purpose. Some existing compilers already
|
||||
provide thread local storage using different syntax, so these lines use
|
||||
thread_local to mimic that syntax. If your compiler provides thread local
|
||||
storage but using different syntax besides "thread_local", you may want to
|
||||
modify these lines. If your compiler does not support thread local storage,
|
||||
you can't use LevelMutex.
|
||||
*/
|
||||
#ifndef LOKI_THREAD_LOCAL
|
||||
#if defined( _MSC_VER )
|
||||
#if ( _MSC_VER >= 1300 )
|
||||
#define LOKI_THREAD_LOCAL __declspec( thread )
|
||||
#else
|
||||
#error "Only Visual Studio versions 7.0 and after supported."
|
||||
#endif
|
||||
|
||||
#elif ( __GNUC__ )
|
||||
#define LOKI_THREAD_LOCAL __thread
|
||||
|
||||
#else
|
||||
#warning "Check if your compiler provides thread local storage."
|
||||
#define LOKI_THREAD_LOCAL thread_local
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
class ThreadPool;
|
||||
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
|
||||
enum Status
|
||||
{
|
||||
Dead = 0,
|
||||
Idle,
|
||||
Starting,
|
||||
Active
|
||||
};
|
||||
|
||||
inline static volatile Thread * GetCurrentThread( void )
|
||||
{
|
||||
return s_thread;
|
||||
}
|
||||
|
||||
bool WaitForThread( void ) volatile;
|
||||
|
||||
inline CallFunction GetFunction( void ) const volatile { return m_func; }
|
||||
|
||||
inline void * GetParameter( void ) const volatile { return m_parm; }
|
||||
|
||||
inline Status GetStatus( void ) const volatile { return m_status; }
|
||||
|
||||
inline const volatile ThreadPool * GetThreadPool( void ) const volatile
|
||||
{
|
||||
return m_owner;
|
||||
}
|
||||
|
||||
inline volatile ThreadPool * GetThreadPool( void ) volatile
|
||||
{
|
||||
return m_owner;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class ThreadPool;
|
||||
|
||||
inline static void SetCurrentThread( volatile Thread * thread )
|
||||
{
|
||||
s_thread = thread;
|
||||
}
|
||||
|
||||
explicit Thread( volatile ThreadPool * owner );
|
||||
|
||||
Thread( volatile ThreadPool * owner, CallFunction function, void * parm );
|
||||
|
||||
~Thread( void );
|
||||
|
||||
/// Default constructor not implemented.
|
||||
Thread( void );
|
||||
|
||||
/// not implemented.
|
||||
Thread( const Thread & );
|
||||
|
||||
/// not implemented.
|
||||
Thread & operator = ( const Thread & );
|
||||
|
||||
bool IsValid( const volatile ThreadPool * owner ) const volatile;
|
||||
|
||||
static LOKI_THREAD_LOCAL volatile Thread * s_thread;
|
||||
|
||||
LokiThread m_thread;
|
||||
CallFunction m_func;
|
||||
void * m_parm;
|
||||
Status m_status;
|
||||
bool m_stop;
|
||||
volatile ThreadPool * const m_owner;
|
||||
};
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
|
||||
explicit ThreadPool( unsigned int threadCount = 0 );
|
||||
|
||||
~ThreadPool( void );
|
||||
|
||||
unsigned int Create( unsigned int threadCount ) volatile;
|
||||
|
||||
volatile Thread * Start( CallFunction function, void * parm ) volatile;
|
||||
|
||||
void Join( unsigned int index ) const volatile;
|
||||
|
||||
void JoinAll( void ) const volatile;
|
||||
|
||||
unsigned int GetCount( void ) const volatile;
|
||||
|
||||
unsigned int GetCount( Thread::Status status ) const volatile;
|
||||
|
||||
volatile const Thread * GetThread( unsigned int index ) const volatile;
|
||||
|
||||
inline volatile Thread * GetThread( unsigned int index ) volatile
|
||||
{
|
||||
return const_cast< volatile Thread * >(
|
||||
const_cast< const volatile ThreadPool * >( this )->
|
||||
GetThread( index ) );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** @class Checker
|
||||
Performs validity check on ThreadPool to insure no class invariants were
|
||||
violated inside any member function. This class only gets used in debug
|
||||
builds, and any instance of it gets optimized away in a release build. A
|
||||
checker is created inside many of member functions so that it's destructor
|
||||
gets called when the function exits.
|
||||
*/
|
||||
class Checker
|
||||
{
|
||||
public:
|
||||
inline explicit Checker( const volatile ThreadPool * mutex ) :
|
||||
m_pool( mutex ) {}
|
||||
inline ~Checker( void ) { m_pool->IsValid(); }
|
||||
private:
|
||||
Checker( void );
|
||||
Checker( const Checker & );
|
||||
Checker & operator = ( const Checker & );
|
||||
const volatile ThreadPool * m_pool;
|
||||
};
|
||||
|
||||
/// Copy-constructor is not implemented.
|
||||
ThreadPool( const ThreadPool & );
|
||||
|
||||
/// Copy-assignment operator is not implemented.
|
||||
ThreadPool & operator = ( const ThreadPool & );
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
static unsigned int __stdcall TopFunction( void * p );
|
||||
#else
|
||||
static void * TopFunction( void * p );
|
||||
#endif
|
||||
|
||||
/** Returns true if no class invariant broken, otherwise asserts. This function
|
||||
only gets called in debug builds.
|
||||
*/
|
||||
bool IsValid( void ) const volatile;
|
||||
|
||||
typedef ::std::vector< volatile Thread * > Threads;
|
||||
typedef Threads::iterator ThreadsIter;
|
||||
typedef Threads::const_iterator ThreadsCIter;
|
||||
|
||||
Threads m_threads;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue