mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Add Stoppable prepare and start interfaces
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ImportGroup Label="PropertySheets" />
|
<ImportGroup Label="PropertySheets" />
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros">
|
||||||
|
<RepoDir>..\..</RepoDir>
|
||||||
|
</PropertyGroup>
|
||||||
<PropertyGroup />
|
<PropertyGroup />
|
||||||
<ItemDefinitionGroup>
|
<ItemDefinitionGroup>
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@@ -9,8 +11,12 @@
|
|||||||
<PreprocessorDefinitions>BEAST_COMPILING_STATIC_LIBARARY=1;_CRTDBG_MAP_ALLOC;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>BEAST_COMPILING_STATIC_LIBARARY=1;_CRTDBG_MAP_ALLOC;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
<MinimalRebuild>false</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(RepoDir)\config;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<BuildMacro Include="RepoDir">
|
||||||
|
<Value>$(RepoDir)</Value>
|
||||||
|
</BuildMacro>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -78,6 +78,7 @@
|
|||||||
</None>
|
</None>
|
||||||
<None Include="..\..\modules\beast_core\zip\zlib\README" />
|
<None Include="..\..\modules\beast_core\zip\zlib\README" />
|
||||||
<None Include="..\..\README.md" />
|
<None Include="..\..\README.md" />
|
||||||
|
<None Include="..\..\scripts\compile.sh" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\beast\Arithmetic.h" />
|
<ClInclude Include="..\..\beast\Arithmetic.h" />
|
||||||
@@ -119,6 +120,7 @@
|
|||||||
<ClInclude Include="..\..\beast\mpl\RemoveVolatile.h" />
|
<ClInclude Include="..\..\beast\mpl\RemoveVolatile.h" />
|
||||||
<ClInclude Include="..\..\beast\Net.h" />
|
<ClInclude Include="..\..\beast\Net.h" />
|
||||||
<ClInclude Include="..\..\beast\net\IPEndpoint.h" />
|
<ClInclude Include="..\..\beast\net\IPEndpoint.h" />
|
||||||
|
<ClInclude Include="..\..\beast\SafeBool.h" />
|
||||||
<ClInclude Include="..\..\beast\StaticAssert.h" />
|
<ClInclude Include="..\..\beast\StaticAssert.h" />
|
||||||
<ClInclude Include="..\..\beast\Strings.h" />
|
<ClInclude Include="..\..\beast\Strings.h" />
|
||||||
<ClInclude Include="..\..\beast\strings\CharacterFunctions.h" />
|
<ClInclude Include="..\..\beast\strings\CharacterFunctions.h" />
|
||||||
@@ -143,9 +145,12 @@
|
|||||||
<ClInclude Include="..\..\beast\type_traits\RemoveSigned.h" />
|
<ClInclude Include="..\..\beast\type_traits\RemoveSigned.h" />
|
||||||
<ClInclude Include="..\..\beast\Uncopyable.h" />
|
<ClInclude Include="..\..\beast\Uncopyable.h" />
|
||||||
<ClInclude Include="..\..\beast\Utility.h" />
|
<ClInclude Include="..\..\beast\Utility.h" />
|
||||||
|
<ClInclude Include="..\..\beast\utility\Debug.h" />
|
||||||
<ClInclude Include="..\..\beast\utility\EnableIf.h" />
|
<ClInclude Include="..\..\beast\utility\EnableIf.h" />
|
||||||
|
<ClInclude Include="..\..\beast\utility\Error.h" />
|
||||||
<ClInclude Include="..\..\beast\utility\Journal.h" />
|
<ClInclude Include="..\..\beast\utility\Journal.h" />
|
||||||
<ClInclude Include="..\..\beast\Version.h" />
|
<ClInclude Include="..\..\beast\Version.h" />
|
||||||
|
<ClInclude Include="..\..\config\BeastConfig.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\async\AbstractHandler.h" />
|
<ClInclude Include="..\..\modules\beast_asio\async\AbstractHandler.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\async\AsyncObject.h" />
|
<ClInclude Include="..\..\modules\beast_asio\async\AsyncObject.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\async\ComposedAsyncOperation.h" />
|
<ClInclude Include="..\..\modules\beast_asio\async\ComposedAsyncOperation.h" />
|
||||||
@@ -217,13 +222,10 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_core\containers\SparseSet.h" />
|
<ClInclude Include="..\..\modules\beast_core\containers\SparseSet.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\containers\DynamicList.h" />
|
<ClInclude Include="..\..\modules\beast_core\containers\DynamicList.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\containers\Variant.h" />
|
<ClInclude Include="..\..\modules\beast_core\containers\Variant.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\Debug.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\Error.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\FatalError.h" />
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\FatalError.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\ProtectedCall.h" />
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\ProtectedCall.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\FPUFlags.h" />
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\FPUFlags.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\LeakChecked.h" />
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\LeakChecked.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\SafeBool.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\SemanticVersion.h" />
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\SemanticVersion.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\Throw.h" />
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\Throw.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\UnitTest.h" />
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\UnitTest.h" />
|
||||||
@@ -392,7 +394,6 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_sqlite\beast_sqlite.h" />
|
<ClInclude Include="..\..\modules\beast_sqlite\beast_sqlite.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3.h" />
|
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3ext.h" />
|
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3ext.h" />
|
||||||
<ClInclude Include="BeastConfig.h" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\beast\chrono\Chrono.cpp" />
|
<ClCompile Include="..\..\beast\chrono\Chrono.cpp" />
|
||||||
@@ -490,6 +491,18 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\beast\strings\Strings.cpp" />
|
<ClCompile Include="..\..\beast\strings\Strings.cpp" />
|
||||||
|
<ClCompile Include="..\..\beast\utility\impl\Debug.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\beast\utility\impl\Error.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\beast\utility\impl\Journal.cpp">
|
<ClCompile Include="..\..\beast\utility\impl\Journal.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
@@ -701,18 +714,6 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\diagnostic\Debug.cpp">
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\diagnostic\Error.cpp">
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\diagnostic\FatalError.cpp">
|
<ClCompile Include="..\..\modules\beast_core\diagnostic\FatalError.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -73,6 +73,9 @@
|
|||||||
<None Include="..\..\beast\crypto\impl\sha2\sha2test.pl">
|
<None Include="..\..\beast\crypto\impl\sha2\sha2test.pl">
|
||||||
<Filter>beast\crypto\impl\sha2</Filter>
|
<Filter>beast\crypto\impl\sha2</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="..\..\scripts\compile.sh">
|
||||||
|
<Filter>scripts</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="beast_core">
|
<Filter Include="beast_core">
|
||||||
@@ -270,6 +273,9 @@
|
|||||||
<Filter Include="beast\chrono\impl">
|
<Filter Include="beast\chrono\impl">
|
||||||
<UniqueIdentifier>{39886e0f-1607-4b7a-81cf-011d83dadee3}</UniqueIdentifier>
|
<UniqueIdentifier>{39886e0f-1607-4b7a-81cf-011d83dadee3}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="scripts">
|
||||||
|
<UniqueIdentifier>{c65af439-8c23-46c3-9b95-7da15651e5f6}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\modules\beast_core\beast_core.h">
|
<ClInclude Include="..\..\modules\beast_core\beast_core.h">
|
||||||
@@ -578,21 +584,12 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_core\containers\SortedLookupTable.h">
|
<ClInclude Include="..\..\modules\beast_core\containers\SortedLookupTable.h">
|
||||||
<Filter>beast_core\containers</Filter>
|
<Filter>beast_core\containers</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\Debug.h">
|
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\Error.h">
|
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\FPUFlags.h">
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\FPUFlags.h">
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
<Filter>beast_core\diagnostic</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\LeakChecked.h">
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\LeakChecked.h">
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
<Filter>beast_core\diagnostic</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\SafeBool.h">
|
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\diagnostic\Throw.h">
|
<ClInclude Include="..\..\modules\beast_core\diagnostic\Throw.h">
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
<Filter>beast_core\diagnostic</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -1178,7 +1175,6 @@
|
|||||||
<ClInclude Include="..\..\beast\http\ParsedURL.h">
|
<ClInclude Include="..\..\beast\http\ParsedURL.h">
|
||||||
<Filter>beast\http</Filter>
|
<Filter>beast\http</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="BeastConfig.h" />
|
|
||||||
<ClInclude Include="..\..\beast\FixedArray.h">
|
<ClInclude Include="..\..\beast\FixedArray.h">
|
||||||
<Filter>beast</Filter>
|
<Filter>beast</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -1209,6 +1205,16 @@
|
|||||||
<ClInclude Include="..\..\beast\chrono\RelativeTime.h">
|
<ClInclude Include="..\..\beast\chrono\RelativeTime.h">
|
||||||
<Filter>beast\chrono</Filter>
|
<Filter>beast\chrono</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\beast\SafeBool.h">
|
||||||
|
<Filter>beast</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\config\BeastConfig.h" />
|
||||||
|
<ClInclude Include="..\..\beast\utility\Error.h">
|
||||||
|
<Filter>beast\utility</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\beast\utility\Debug.h">
|
||||||
|
<Filter>beast\utility</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
|
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
|
||||||
@@ -1451,12 +1457,6 @@
|
|||||||
<ClCompile Include="..\..\modules\beast_core\native\bsd_Threads.cpp">
|
<ClCompile Include="..\..\modules\beast_core\native\bsd_Threads.cpp">
|
||||||
<Filter>beast_core\native</Filter>
|
<Filter>beast_core\native</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\diagnostic\Debug.cpp">
|
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\diagnostic\Error.cpp">
|
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\diagnostic\FPUFlags.cpp">
|
<ClCompile Include="..\..\modules\beast_core\diagnostic\FPUFlags.cpp">
|
||||||
<Filter>beast_core\diagnostic</Filter>
|
<Filter>beast_core\diagnostic</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -1781,6 +1781,12 @@
|
|||||||
<ClCompile Include="..\..\beast\chrono\Chrono.cpp">
|
<ClCompile Include="..\..\beast\chrono\Chrono.cpp">
|
||||||
<Filter>beast\chrono</Filter>
|
<Filter>beast\chrono</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\beast\utility\impl\Debug.cpp">
|
||||||
|
<Filter>beast\utility\impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\beast\utility\impl\Error.cpp">
|
||||||
|
<Filter>beast\utility\impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="..\..\TODO.txt">
|
<Text Include="..\..\TODO.txt">
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace beast {
|
|||||||
/** Contains static methods for converting the byte order between different
|
/** Contains static methods for converting the byte order between different
|
||||||
endiannesses.
|
endiannesses.
|
||||||
*/
|
*/
|
||||||
class BEAST_API ByteOrder : public Uncopyable
|
class ByteOrder : public Uncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|||||||
@@ -20,23 +20,11 @@
|
|||||||
#ifndef BEAST_SAFEBOOL_H_INCLUDED
|
#ifndef BEAST_SAFEBOOL_H_INCLUDED
|
||||||
#define BEAST_SAFEBOOL_H_INCLUDED
|
#define BEAST_SAFEBOOL_H_INCLUDED
|
||||||
|
|
||||||
/** Safe evaluation of class as `bool`.
|
namespace beast {
|
||||||
|
|
||||||
This allows a class to be safely evaluated as a bool without the usual
|
namespace detail {
|
||||||
harmful side effects of the straightforward operator conversion approach.
|
|
||||||
To use it, derive your class from SafeBool and implement `asBoolean()` as:
|
|
||||||
|
|
||||||
@code
|
class SafeBoolBase
|
||||||
|
|
||||||
bool asBoolean () const;
|
|
||||||
|
|
||||||
@endcode
|
|
||||||
|
|
||||||
Ideas from http://www.artima.com/cppsource/safebool.html
|
|
||||||
|
|
||||||
@class SafeBool
|
|
||||||
*/
|
|
||||||
class BEAST_API SafeBoolBase
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
void disallowed () const { }
|
void disallowed () const { }
|
||||||
@@ -56,11 +44,29 @@ protected:
|
|||||||
~SafeBoolBase () { }
|
~SafeBoolBase () { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Safe evaluation of class as `bool`.
|
||||||
|
|
||||||
|
This allows a class to be safely evaluated as a bool without the usual
|
||||||
|
harmful side effects of the straightforward operator conversion approach.
|
||||||
|
To use it, derive your class from SafeBool and implement `asBoolean()` as:
|
||||||
|
|
||||||
|
@code
|
||||||
|
|
||||||
|
bool asBoolean () const;
|
||||||
|
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
Ideas from http://www.artima.com/cppsource/safebool.html
|
||||||
|
|
||||||
|
@class SafeBool
|
||||||
|
*/
|
||||||
template <typename T = void>
|
template <typename T = void>
|
||||||
class SafeBool : public SafeBoolBase
|
class SafeBool : public detail::SafeBoolBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
operator boolean_t () const
|
operator detail::SafeBoolBase::boolean_t () const
|
||||||
{
|
{
|
||||||
return (static_cast <T const*> (this))->asBoolean ()
|
return (static_cast <T const*> (this))->asBoolean ()
|
||||||
? &SafeBoolBase::allowed : 0;
|
? &SafeBoolBase::allowed : 0;
|
||||||
@@ -82,6 +88,8 @@ void operator!= (SafeBool <T> const& lhs, SafeBool <U> const& rhs)
|
|||||||
lhs.disallowed ();
|
lhs.disallowed ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +20,9 @@
|
|||||||
#ifndef BEAST_UTILITY_H_INCLUDED
|
#ifndef BEAST_UTILITY_H_INCLUDED
|
||||||
#define BEAST_UTILITY_H_INCLUDED
|
#define BEAST_UTILITY_H_INCLUDED
|
||||||
|
|
||||||
|
#include "utility/Debug.h"
|
||||||
#include "utility/EnableIf.h"
|
#include "utility/EnableIf.h"
|
||||||
|
#include "utility/Error.h"
|
||||||
#include "utility/Journal.h"
|
#include "utility/Journal.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include "RelativeTime.h"
|
#include "../RelativeTime.h"
|
||||||
|
|
||||||
// VFALCO TODO Migrate the localizable strings interfaces for this file
|
// VFALCO TODO Migrate the localizable strings interfaces for this file
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#ifndef BEAST_DEBUG_H_INCLUDED
|
#ifndef BEAST_UTILITY_DEBUG_H_INCLUDED
|
||||||
#define BEAST_DEBUG_H_INCLUDED
|
#define BEAST_UTILITY_DEBUG_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../strings/String.h"
|
||||||
|
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
// Auxiliary outines for debugging
|
// Auxiliary outines for debugging
|
||||||
|
|
||||||
@@ -83,4 +87,6 @@ extern void checkHeap ();
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -17,8 +17,17 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#ifndef BEAST_ERROR_H_INCLUDED
|
#ifndef BEAST_UTILITY_ERROR_H_INCLUDED
|
||||||
#define BEAST_ERROR_H_INCLUDED
|
#define BEAST_UTILITY_ERROR_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../Config.h"
|
||||||
|
|
||||||
|
#include "../SafeBool.h"
|
||||||
|
#include "../strings/String.h"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
/** A concise error report.
|
/** A concise error report.
|
||||||
|
|
||||||
@@ -32,7 +41,7 @@
|
|||||||
|
|
||||||
@ingroup beast_core
|
@ingroup beast_core
|
||||||
*/
|
*/
|
||||||
class BEAST_API Error
|
class Error
|
||||||
: public std::exception
|
: public std::exception
|
||||||
, public SafeBool <Error>
|
, public SafeBool <Error>
|
||||||
{
|
{
|
||||||
@@ -119,4 +128,6 @@ private:
|
|||||||
mutable char const* m_szWhat;
|
mutable char const* m_szWhat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -19,6 +19,10 @@
|
|||||||
|
|
||||||
#include "BeastConfig.h"
|
#include "BeastConfig.h"
|
||||||
|
|
||||||
#include "../../modules/beast_core/beast_core.h"
|
#include "impl/Error.cpp"
|
||||||
|
|
||||||
|
|
||||||
|
// For Journal and Debug
|
||||||
|
#include "../../modules/beast_core/beast_core.h"
|
||||||
#include "impl/Journal.cpp"
|
#include "impl/Journal.cpp"
|
||||||
|
#include "impl/Debug.cpp"
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
namespace Debug
|
namespace beast {
|
||||||
{
|
|
||||||
|
namespace Debug {
|
||||||
|
|
||||||
void breakPoint ()
|
void breakPoint ()
|
||||||
{
|
{
|
||||||
@@ -358,3 +359,5 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static DebugTests debugTests;
|
static DebugTests debugTests;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,6 +17,19 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
|
#include "../Error.h"
|
||||||
|
#include "../Debug.h"
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
// VFALCO TODO Localizable strings
|
||||||
|
#ifndef TRANS
|
||||||
|
#define TRANS(s) (s)
|
||||||
|
#define UNDEF_TRANS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
Error::Error ()
|
Error::Error ()
|
||||||
: m_code (success)
|
: m_code (success)
|
||||||
, m_lineNumber (0)
|
, m_lineNumber (0)
|
||||||
@@ -241,3 +254,11 @@ String const Error::getReasonTextForCode (Code code)
|
|||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef UNDEF_TRANS
|
||||||
|
#undef TRANs
|
||||||
|
#undef UNDEF_TRANS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -138,8 +138,6 @@ namespace beast
|
|||||||
#include "containers/DynamicList.cpp"
|
#include "containers/DynamicList.cpp"
|
||||||
#include "containers/HashMap.cpp"
|
#include "containers/HashMap.cpp"
|
||||||
|
|
||||||
#include "diagnostic/Debug.cpp"
|
|
||||||
#include "diagnostic/Error.cpp"
|
|
||||||
#include "diagnostic/FatalError.cpp"
|
#include "diagnostic/FatalError.cpp"
|
||||||
#include "diagnostic/FPUFlags.cpp"
|
#include "diagnostic/FPUFlags.cpp"
|
||||||
#include "diagnostic/LeakChecked.cpp"
|
#include "diagnostic/LeakChecked.cpp"
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
#include "../../beast/Memory.h"
|
#include "../../beast/Memory.h"
|
||||||
#include "../../beast/Intrusive.h"
|
#include "../../beast/Intrusive.h"
|
||||||
#include "../../beast/Net.h"
|
#include "../../beast/Net.h"
|
||||||
|
#include "../../beast/SafeBool.h"
|
||||||
#include "../../beast/Strings.h"
|
#include "../../beast/Strings.h"
|
||||||
#include "../../beast/TypeTraits.h"
|
#include "../../beast/TypeTraits.h"
|
||||||
#include "../../beast/Thread.h"
|
#include "../../beast/Thread.h"
|
||||||
@@ -146,7 +147,6 @@ class FileOutputStream;
|
|||||||
#include "memory/MemoryAlignment.h"
|
#include "memory/MemoryAlignment.h"
|
||||||
#include "memory/CacheLine.h"
|
#include "memory/CacheLine.h"
|
||||||
#include "threads/ReadWriteMutex.h"
|
#include "threads/ReadWriteMutex.h"
|
||||||
#include "diagnostic/SafeBool.h"
|
|
||||||
#include "threads/WaitableEvent.h"
|
#include "threads/WaitableEvent.h"
|
||||||
#include "threads/Thread.h"
|
#include "threads/Thread.h"
|
||||||
#include "threads/SpinLock.h"
|
#include "threads/SpinLock.h"
|
||||||
@@ -154,8 +154,6 @@ class FileOutputStream;
|
|||||||
#include "thread/MutexTraits.h"
|
#include "thread/MutexTraits.h"
|
||||||
#include "thread/TrackedMutex.h"
|
#include "thread/TrackedMutex.h"
|
||||||
#include "diagnostic/FatalError.h"
|
#include "diagnostic/FatalError.h"
|
||||||
#include "diagnostic/Error.h"
|
|
||||||
#include "diagnostic/Debug.h"
|
|
||||||
#include "text/LexicalCast.h"
|
#include "text/LexicalCast.h"
|
||||||
#include "memory/ContainerDeletePolicy.h"
|
#include "memory/ContainerDeletePolicy.h"
|
||||||
#include "maths/Math.h"
|
#include "maths/Math.h"
|
||||||
|
|||||||
@@ -17,84 +17,45 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
|
Stoppable::Stoppable (char const* name, RootStoppable& root)
|
||||||
Stoppable::Stoppable (char const* name, Stoppable& parent)
|
|
||||||
: m_name (name)
|
: m_name (name)
|
||||||
, m_root (false)
|
, m_root (root)
|
||||||
, m_child (this)
|
, m_child (this)
|
||||||
, m_calledStop (false)
|
|
||||||
, m_stopped (false)
|
, m_stopped (false)
|
||||||
, m_childrenStopped (false)
|
, m_childrenStopped (false)
|
||||||
{
|
{
|
||||||
// must not have had stop called
|
}
|
||||||
|
|
||||||
|
Stoppable::Stoppable (char const* name, Stoppable& parent)
|
||||||
|
: m_name (name)
|
||||||
|
, m_root (parent.m_root)
|
||||||
|
, m_child (this)
|
||||||
|
, m_stopped (false)
|
||||||
|
, m_childrenStopped (false)
|
||||||
|
{
|
||||||
|
// Must not have stopping parent.
|
||||||
bassert (! parent.isStopping());
|
bassert (! parent.isStopping());
|
||||||
|
|
||||||
parent.m_children.push_front (&m_child);
|
parent.m_children.push_front (&m_child);
|
||||||
}
|
}
|
||||||
|
|
||||||
Stoppable::Stoppable (char const* name, Stoppable* parent)
|
|
||||||
: m_name (name)
|
|
||||||
, m_root (parent == nullptr)
|
|
||||||
, m_child (this)
|
|
||||||
, m_calledStop (false)
|
|
||||||
, m_stopped (false)
|
|
||||||
, m_childrenStopped (false)
|
|
||||||
{
|
|
||||||
if (parent != nullptr)
|
|
||||||
{
|
|
||||||
// must not have had stop called
|
|
||||||
bassert (! parent->isStopping());
|
|
||||||
|
|
||||||
parent->m_children.push_front (&m_child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Stoppable::~Stoppable ()
|
Stoppable::~Stoppable ()
|
||||||
{
|
{
|
||||||
// must be stopped
|
// Children must be stopped.
|
||||||
bassert (m_stopped);
|
|
||||||
|
|
||||||
// children must be stopped
|
|
||||||
bassert (m_childrenStopped);
|
bassert (m_childrenStopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stoppable::stop (Journal::Stream stream)
|
bool Stoppable::isStopping() const
|
||||||
{
|
{
|
||||||
// may only be called once
|
return m_root.isStopping();
|
||||||
if (m_calledStop)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_calledStop = true;
|
|
||||||
|
|
||||||
// must be called from a root stoppable
|
|
||||||
bassert (m_root);
|
|
||||||
|
|
||||||
// send the notification
|
|
||||||
stopAsync ();
|
|
||||||
|
|
||||||
// now block on the tree of Stoppable objects from the leaves up.
|
|
||||||
stopRecursive (stream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stoppable::stopAsync ()
|
bool Stoppable::isStopped () const
|
||||||
{
|
|
||||||
// must be called from a root stoppable
|
|
||||||
bassert (m_root);
|
|
||||||
|
|
||||||
stopAsyncRecursive ();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Stoppable::isStopping ()
|
|
||||||
{
|
|
||||||
return m_calledStopAsync.get() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Stoppable::isStopped ()
|
|
||||||
{
|
{
|
||||||
return m_stopped;
|
return m_stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stoppable::areChildrenStopped ()
|
bool Stoppable::areChildrenStopped () const
|
||||||
{
|
{
|
||||||
return m_childrenStopped;
|
return m_childrenStopped;
|
||||||
}
|
}
|
||||||
@@ -104,75 +65,134 @@ void Stoppable::stopped ()
|
|||||||
m_stoppedEvent.signal();
|
m_stoppedEvent.signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stoppable::onStop()
|
void Stoppable::onPrepare (Journal journal)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Stoppable::onStart (Journal journal)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Stoppable::onStop (Journal journal)
|
||||||
{
|
{
|
||||||
stopped();
|
stopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stoppable::onChildrenStopped ()
|
void Stoppable::onChildrenStopped (Journal journal)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
void Stoppable::stopAsyncRecursive ()
|
void Stoppable::prepareRecursive (Journal journal)
|
||||||
{
|
{
|
||||||
// make sure we only do this once
|
onPrepare (journal);
|
||||||
if (m_root)
|
|
||||||
{
|
|
||||||
// if this fails, some other thread got to it first
|
|
||||||
if (! m_calledStopAsync.compareAndSetBool (1, 0))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// can't possibly already be set
|
|
||||||
bassert (m_calledStopAsync.get() == 0);
|
|
||||||
|
|
||||||
m_calledStopAsync.set (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// notify this stoppable
|
|
||||||
onStop ();
|
|
||||||
|
|
||||||
// notify children
|
|
||||||
for (Children::const_iterator iter (m_children.cbegin ());
|
for (Children::const_iterator iter (m_children.cbegin ());
|
||||||
iter != m_children.cend(); ++iter)
|
iter != m_children.cend(); ++iter)
|
||||||
{
|
iter->stoppable->prepareRecursive (journal);
|
||||||
iter->stoppable->stopAsyncRecursive();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stoppable::stopRecursive (Journal::Stream stream)
|
void Stoppable::startRecursive (Journal journal)
|
||||||
{
|
{
|
||||||
// Block on each child recursively. Thinking of the Stoppable
|
onStart (journal);
|
||||||
// hierarchy as a tree with the root at the top, we will block
|
for (Children::const_iterator iter (m_children.cbegin ());
|
||||||
// first on leaves, and then at each successivly higher level.
|
iter != m_children.cend(); ++iter)
|
||||||
|
iter->stoppable->startRecursive (journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Stoppable::stopAsyncRecursive (Journal journal)
|
||||||
|
{
|
||||||
|
onStop (journal);
|
||||||
|
for (Children::const_iterator iter (m_children.cbegin ());
|
||||||
|
iter != m_children.cend(); ++iter)
|
||||||
|
iter->stoppable->stopAsyncRecursive (journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Stoppable::stopRecursive (Journal journal)
|
||||||
|
{
|
||||||
|
// Block on each child from the bottom of the tree up.
|
||||||
//
|
//
|
||||||
for (Children::const_iterator iter (m_children.cbegin ());
|
for (Children::const_iterator iter (m_children.cbegin ());
|
||||||
iter != m_children.cend(); ++iter)
|
iter != m_children.cend(); ++iter)
|
||||||
{
|
iter->stoppable->stopRecursive (journal);
|
||||||
iter->stoppable->stopRecursive (stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once we get here, we either have no children, or all of
|
// if we get here then all children have stopped
|
||||||
// our children have stopped, so update state accordingly.
|
|
||||||
//
|
//
|
||||||
|
memoryBarrier ();
|
||||||
m_childrenStopped = true;
|
m_childrenStopped = true;
|
||||||
|
onChildrenStopped (journal);
|
||||||
|
|
||||||
// Notify derived class that children have stopped.
|
// Now block on this Stoppable.
|
||||||
onChildrenStopped ();
|
|
||||||
|
|
||||||
// Block until this stoppable stops. First we do a timed wait of 1 second, and
|
|
||||||
// if that times out we report to the Journal and then do an infinite wait.
|
|
||||||
//
|
//
|
||||||
bool const timedOut (! m_stoppedEvent.wait (1 * 1000)); // milliseconds
|
bool const timedOut (! m_stoppedEvent.wait (1 * 1000)); // milliseconds
|
||||||
if (timedOut)
|
if (timedOut)
|
||||||
{
|
{
|
||||||
stream << "Waiting for '" << m_name << "' to stop";
|
journal.warning << "Waiting for '" << m_name << "' to stop";
|
||||||
m_stoppedEvent.wait ();
|
m_stoppedEvent.wait ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// once we get here, we know the stoppable has stopped.
|
// once we get here, we know the stoppable has stopped.
|
||||||
m_stopped = true;
|
m_stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
RootStoppable::RootStoppable (char const* name)
|
||||||
|
: Stoppable (name, *this)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RootStoppable::~RootStoppable ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RootStoppable::isStopping() const
|
||||||
|
{
|
||||||
|
return m_calledStopAsync.get() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RootStoppable::prepare (Journal journal)
|
||||||
|
{
|
||||||
|
if (! m_prepared.compareAndSetBool (1, 0))
|
||||||
|
{
|
||||||
|
journal.warning << "Stoppable::prepare called again";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareRecursive (journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RootStoppable::start (Journal journal)
|
||||||
|
{
|
||||||
|
// Courtesy call to prepare.
|
||||||
|
if (m_prepared.compareAndSetBool (1, 0))
|
||||||
|
prepareRecursive (journal);
|
||||||
|
|
||||||
|
if (! m_started.compareAndSetBool (1, 0))
|
||||||
|
{
|
||||||
|
journal.warning << "Stoppable::start called again";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
startRecursive (journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RootStoppable::stop (Journal journal)
|
||||||
|
{
|
||||||
|
if (! m_calledStop.compareAndSetBool (1, 0))
|
||||||
|
{
|
||||||
|
journal.warning << "Stoppable::stop called again";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopAsync (journal);
|
||||||
|
stopRecursive (journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RootStoppable::stopAsync (Journal journal)
|
||||||
|
{
|
||||||
|
if (! m_calledStopAsync.compareAndSetBool (1, 0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
stopAsyncRecursive (journal);
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,16 +20,66 @@
|
|||||||
#ifndef BEAST_CORE_STOPPABLE_H_INCLUDED
|
#ifndef BEAST_CORE_STOPPABLE_H_INCLUDED
|
||||||
#define BEAST_CORE_STOPPABLE_H_INCLUDED
|
#define BEAST_CORE_STOPPABLE_H_INCLUDED
|
||||||
|
|
||||||
/** Provides an interface for stopping.
|
class RootStoppable;
|
||||||
|
|
||||||
|
/** Provides an interface for starting and stopping.
|
||||||
|
|
||||||
|
A common method of structuring server or peer to peer code is to isolate
|
||||||
|
conceptual portions of functionality into individual classes, aggregated
|
||||||
|
into some larger "application" or "core" object which holds all the parts.
|
||||||
|
Frequently, these components are dependent on each other in unavoidably
|
||||||
|
complex ways. They also often use threads and perform asynchronous i/o
|
||||||
|
operations involving sockets or other operating system objects. The process
|
||||||
|
of starting and stopping such a system can be complex. This interface
|
||||||
|
provides a set of behaviors for ensuring that the start and stop of a
|
||||||
|
composite application-style object is well defined.
|
||||||
|
|
||||||
|
Upon the initialization of the composite object these steps are peformed:
|
||||||
|
|
||||||
|
1. Construct sub-components.
|
||||||
|
|
||||||
|
These are all typically derived from Stoppable. There can be a deep
|
||||||
|
hierarchy: Stoppable objects may themselves have Stoppable child
|
||||||
|
objects. This captures the relationship of dependencies.
|
||||||
|
|
||||||
|
2. prepare()
|
||||||
|
|
||||||
|
Because some components may depend on others, preparatory steps require
|
||||||
|
that all objects be first constructed. The prepare step calls all
|
||||||
|
Stoppable objects in the tree starting from the leaves and working up
|
||||||
|
to the root. In this stage we are guaranteed that all objects have been
|
||||||
|
constructed and are in a well-defined state.
|
||||||
|
|
||||||
|
3. onPrepare()
|
||||||
|
|
||||||
|
This override is called for all Stoppable objects in the hierarchy
|
||||||
|
during the prepare stage. Objects are called from the bottom up.
|
||||||
|
It is guaranteed that all child Stoppable objects have already been
|
||||||
|
prepared when this is called.
|
||||||
|
|
||||||
|
4. start()
|
||||||
|
|
||||||
|
At this point all sub-components have been constructed and prepared,
|
||||||
|
so it should be safe for them to be started. While some Stoppable
|
||||||
|
objects may do nothing in their start function, others will start
|
||||||
|
threads or call asynchronous i/o initiating functions like timers or
|
||||||
|
sockets.
|
||||||
|
|
||||||
|
5. onStart()
|
||||||
|
|
||||||
|
This override is called for all Stoppable objects in the hierarchy
|
||||||
|
during the start stage. Objects are called from the bottom up.
|
||||||
|
It is guaranteed that all child Stoppable objects have already been
|
||||||
|
started when this is called.
|
||||||
|
|
||||||
This is the sequence of events involved in stopping:
|
This is the sequence of events involved in stopping:
|
||||||
|
|
||||||
1. stopAsync() [optional]
|
6. stopAsync() [optional]
|
||||||
|
|
||||||
This notifies the root Stoppable and all its children that a stop is
|
This notifies the root Stoppable and all its children that a stop is
|
||||||
requested.
|
requested.
|
||||||
|
|
||||||
2. stop()
|
7. stop()
|
||||||
|
|
||||||
This first calls stopAsync(), and then blocks on each child Stoppable in
|
This first calls stopAsync(), and then blocks on each child Stoppable in
|
||||||
the in the tree from the bottom up, until the Stoppable indicates it has
|
the in the tree from the bottom up, until the Stoppable indicates it has
|
||||||
@@ -37,21 +87,21 @@
|
|||||||
when some external signal indicates that the process should stop. For
|
when some external signal indicates that the process should stop. For
|
||||||
example, an RPC 'stop' command, or a SIGINT POSIX signal.
|
example, an RPC 'stop' command, or a SIGINT POSIX signal.
|
||||||
|
|
||||||
3. onStop()
|
8. onStop()
|
||||||
|
|
||||||
This override is called for the root Stoppable and all its children when
|
This override is called for the root Stoppable and all its children when
|
||||||
stopAsync() is called. Derived classes should cancel pending I/O and
|
stopAsync() is called. Derived classes should cancel pending I/O and
|
||||||
timers, signal that threads should exit, queue cleanup jobs, and perform
|
timers, signal that threads should exit, queue cleanup jobs, and perform
|
||||||
any other necessary final actions in preparation for exit.
|
any other necessary final actions in preparation for exit.
|
||||||
|
|
||||||
4. onChildrenStopped()
|
9. onChildrenStopped()
|
||||||
|
|
||||||
This override is called when all the children have stopped. This informs
|
This override is called when all the children have stopped. This informs
|
||||||
the Stoppable that there should not be any more dependents making calls
|
the Stoppable that there should not be any more dependents making calls
|
||||||
into its member functions. A Stoppable that has no children will still
|
into its member functions. A Stoppable that has no children will still
|
||||||
have this function called.
|
have this function called.
|
||||||
|
|
||||||
5. stopped()
|
10. stopped()
|
||||||
|
|
||||||
The derived class calls this function to inform the Stoppable API that
|
The derived class calls this function to inform the Stoppable API that
|
||||||
it has completed the stop. This unblocks the caller of stop().
|
it has completed the stop. This unblocks the caller of stop().
|
||||||
@@ -102,85 +152,44 @@
|
|||||||
|
|
||||||
@note A Stoppable may not be restarted.
|
@note A Stoppable may not be restarted.
|
||||||
*/
|
*/
|
||||||
|
/** @{ */
|
||||||
class Stoppable
|
class Stoppable
|
||||||
{
|
{
|
||||||
public:
|
protected:
|
||||||
/** Create the stoppable.
|
Stoppable (char const* name, RootStoppable& root);
|
||||||
A stoppable without a parent is a root stoppable.
|
|
||||||
@param name A name used in log output.
|
|
||||||
@param parent Optional parent of this stoppable.
|
|
||||||
*/
|
|
||||||
/** @{ */
|
|
||||||
Stoppable (char const* name, Stoppable& parent);
|
|
||||||
explicit Stoppable (char const* name, Stoppable* parent = nullptr);
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
/** Destroy the stoppable.
|
public:
|
||||||
Undefined behavior results if the object is not stopped first.
|
/** Create the Stoppable. */
|
||||||
Stoppable objects should not be created and destroyed dynamically during
|
Stoppable (char const* name, Stoppable& parent);
|
||||||
the process lifetime. Rather, the set of stoppables should be static and
|
|
||||||
well-defined after initialization. If the set of domain-specific objects
|
/** Destroy the Stoppable. */
|
||||||
which need to stop is dynamic, use a single parent Stoppable to manage
|
|
||||||
those objects. For example, make an HTTP server implementation a
|
|
||||||
Stoppable, rather than each of its active connections.
|
|
||||||
*/
|
|
||||||
virtual ~Stoppable ();
|
virtual ~Stoppable ();
|
||||||
|
|
||||||
/** Notify a root stoppable and children to stop, and block until stopped.
|
/** Returns `true` if the stoppable should stop. */
|
||||||
Has no effect if the stoppable was already notified.
|
bool isStopping () const;
|
||||||
This blocks until the stoppable and all of its children have stopped.
|
|
||||||
@param stream An optional Journal::Stream on which to log progress.
|
|
||||||
|
|
||||||
Thread safety:
|
/** Returns `true` if the requested stop has completed. */
|
||||||
Safe to call from any thread not associated with a Stoppable.
|
bool isStopped () const;
|
||||||
*/
|
|
||||||
void stop (Journal::Stream stream = Journal::Stream());
|
|
||||||
|
|
||||||
/** Notify a root stoppable and children to stop, without waiting.
|
/** Returns `true` if all children have stopped. */
|
||||||
Has no effect if the stoppable was already notified.
|
bool areChildrenStopped () const;
|
||||||
|
|
||||||
Thread safety:
|
/** Called by derived classes to indicate that the stoppable has stopped. */
|
||||||
Safe to call from any thread at any time.
|
|
||||||
*/
|
|
||||||
void stopAsync ();
|
|
||||||
|
|
||||||
/** Returns `true` if the stoppable should stop.
|
|
||||||
Call from the derived class to determine if a long-running operation
|
|
||||||
should be canceled. This is not appropriate for either threads, or
|
|
||||||
asynchronous I/O. For threads, use the thread-specific facilities
|
|
||||||
available to inform the thread that it should exit. For asynchronous
|
|
||||||
I/O, cancel all pending operations inside the onStop override.
|
|
||||||
@see onStop
|
|
||||||
|
|
||||||
Thread safety:
|
|
||||||
Safe to call from any thread at any time.
|
|
||||||
*/
|
|
||||||
bool isStopping ();
|
|
||||||
|
|
||||||
/** Returns `true` if the stoppable has completed its stop.
|
|
||||||
Thread safety:
|
|
||||||
Safe to call from any thread at any time.
|
|
||||||
*/
|
|
||||||
bool isStopped ();
|
|
||||||
|
|
||||||
/** Returns `true` if all children have stopped.
|
|
||||||
For stoppables without children, this returns `true` immediately
|
|
||||||
after a stop notification is received.
|
|
||||||
|
|
||||||
Thread safety:
|
|
||||||
Safe to call from any thread at any time.
|
|
||||||
*/
|
|
||||||
bool areChildrenStopped ();
|
|
||||||
|
|
||||||
/** Called by derived classes to indicate that the stoppable has stopped.
|
|
||||||
The derived class must call this either after isStopping returns `true`,
|
|
||||||
or when onStop is called, or else the call to stop will never unblock.
|
|
||||||
|
|
||||||
Thread safety:
|
|
||||||
Safe to call from any thread at any time.
|
|
||||||
*/
|
|
||||||
void stopped ();
|
void stopped ();
|
||||||
|
|
||||||
|
/** Override called during preparation.
|
||||||
|
Since all other Stoppable objects in the tree have already been
|
||||||
|
constructed, this provides an opportunity to perform initialization which
|
||||||
|
depends on calling into other Stoppable objects.
|
||||||
|
This call is made on the same thread that called prepare().
|
||||||
|
The default implementation does nothing.
|
||||||
|
Guaranteed to only be called once.
|
||||||
|
*/
|
||||||
|
virtual void onPrepare (Journal journal);
|
||||||
|
|
||||||
|
/** Override called during start. */
|
||||||
|
virtual void onStart (Journal journal);
|
||||||
|
|
||||||
/** Override called when the stop notification is issued.
|
/** Override called when the stop notification is issued.
|
||||||
|
|
||||||
The call is made on an unspecified, implementation-specific thread.
|
The call is made on an unspecified, implementation-specific thread.
|
||||||
@@ -202,7 +211,7 @@ public:
|
|||||||
Guaranteed only to be called once.
|
Guaranteed only to be called once.
|
||||||
Must be safe to call from any thread at any time.
|
Must be safe to call from any thread at any time.
|
||||||
*/
|
*/
|
||||||
virtual void onStop ();
|
virtual void onStop (Journal journal);
|
||||||
|
|
||||||
/** Override called when all children have stopped.
|
/** Override called when all children have stopped.
|
||||||
|
|
||||||
@@ -222,9 +231,11 @@ public:
|
|||||||
Guaranteed only to be called once.
|
Guaranteed only to be called once.
|
||||||
Must be safe to call from any thread at any time.
|
Must be safe to call from any thread at any time.
|
||||||
*/
|
*/
|
||||||
virtual void onChildrenStopped ();
|
virtual void onChildrenStopped (Journal journal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class RootStoppable;
|
||||||
|
|
||||||
struct Child;
|
struct Child;
|
||||||
typedef LockFreeStack <Child> Children;
|
typedef LockFreeStack <Child> Children;
|
||||||
|
|
||||||
@@ -237,28 +248,70 @@ private:
|
|||||||
Stoppable* stoppable;
|
Stoppable* stoppable;
|
||||||
};
|
};
|
||||||
|
|
||||||
void stopAsyncRecursive ();
|
void prepareRecursive (Journal journal);
|
||||||
void stopRecursive (Journal::Stream stream);
|
void startRecursive (Journal journal);
|
||||||
|
void stopAsyncRecursive (Journal journal);
|
||||||
|
void stopRecursive (Journal journal);
|
||||||
|
|
||||||
|
protected:
|
||||||
char const* m_name;
|
char const* m_name;
|
||||||
bool m_root;
|
RootStoppable& m_root;
|
||||||
Child m_child;
|
Child m_child;
|
||||||
Children m_children;
|
|
||||||
|
|
||||||
// Flag that we called stop. This is for diagnostics.
|
|
||||||
bool m_calledStop;
|
|
||||||
|
|
||||||
// Atomic flag to make sure we only call stopAsync once.
|
|
||||||
Atomic <int> m_calledStopAsync;
|
|
||||||
|
|
||||||
// Flag that this service stopped. Never goes back to false.
|
|
||||||
bool volatile m_stopped;
|
bool volatile m_stopped;
|
||||||
|
|
||||||
// Flag that all children have stopped (recursive). Never goes back to false.
|
|
||||||
bool volatile m_childrenStopped;
|
bool volatile m_childrenStopped;
|
||||||
|
Children m_children;
|
||||||
// stop() blocks on this event until stopped() is called.
|
|
||||||
WaitableEvent m_stoppedEvent;
|
WaitableEvent m_stoppedEvent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class RootStoppable : public Stoppable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit RootStoppable (char const* name);
|
||||||
|
|
||||||
|
~RootStoppable ();
|
||||||
|
|
||||||
|
bool isStopping() const;
|
||||||
|
|
||||||
|
/** Prepare all contained Stoppable objects.
|
||||||
|
This calls onPrepare for all Stoppable objects in the tree.
|
||||||
|
Calls made after the first have no effect.
|
||||||
|
Thread safety:
|
||||||
|
May be called from any thread.
|
||||||
|
*/
|
||||||
|
void prepare (Journal journal = Journal());
|
||||||
|
|
||||||
|
/** Start all contained Stoppable objects.
|
||||||
|
The default implementation does nothing.
|
||||||
|
Calls made after the first have no effect.
|
||||||
|
Thread safety:
|
||||||
|
May be called from any thread.
|
||||||
|
*/
|
||||||
|
void start (Journal journal = Journal());
|
||||||
|
|
||||||
|
/** Notify a root stoppable and children to stop, and block until stopped.
|
||||||
|
Has no effect if the stoppable was already notified.
|
||||||
|
This blocks until the stoppable and all of its children have stopped.
|
||||||
|
Thread safety:
|
||||||
|
Safe to call from any thread not associated with a Stoppable.
|
||||||
|
*/
|
||||||
|
void stop (Journal journal = Journal());
|
||||||
|
|
||||||
|
/** Notify a root stoppable and children to stop, without waiting.
|
||||||
|
Has no effect if the stoppable was already notified.
|
||||||
|
|
||||||
|
Thread safety:
|
||||||
|
Safe to call from any thread at any time.
|
||||||
|
*/
|
||||||
|
void stopAsync (Journal journal = Journal());
|
||||||
|
|
||||||
|
private:
|
||||||
|
Atomic <int> m_prepared;
|
||||||
|
Atomic <int> m_started;
|
||||||
|
Atomic <int> m_calledStop;
|
||||||
|
Atomic <int> m_calledStopAsync;
|
||||||
|
};
|
||||||
|
/** @} */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ for f in $1/*/*.cpp
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
echo "Compilng '$f'"
|
echo "Compilng '$f'"
|
||||||
g++ -xc++ -I$1/../scripts/ "$f" -c -o /dev/null
|
g++ -xc++ -I$1/../config/ "$f" -c -o /dev/null
|
||||||
g++ -xc++ -std=c++11 -I$1/../scripts/ "$f" -c -o /dev/null
|
g++ -xc++ -std=c++11 -I$1/../config/ "$f" -c -o /dev/null
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user