From ac37c38133564d07449ed142302341371f72ea05 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 3 Oct 2013 17:38:04 -0700 Subject: [PATCH] Beast class refactor --- Builds/VisualStudio2012/beast.vcxproj | 78 +- Builds/VisualStudio2012/beast.vcxproj.filters | 90 +- .../SmartPtr.h | 27 +- .../smart_ptr}/ContainerDeletePolicy.h | 8 +- .../smart_ptr}/ScopedPointer.h | 15 +- modules/beast_asio/beast_asio.cpp | 3 +- modules/beast_asio/beast_asio.h | 3 +- modules/beast_asio/http/HTTPParser.cpp | 4 + modules/beast_asio/http/HTTPParser.h | 4 + modules/beast_core/beast_core.cpp | 10 - modules/beast_core/beast_core.h | 17 +- modules/beast_core/containers/DynamicList.cpp | 327 ------- modules/beast_core/containers/DynamicList.h | 473 ----------- modules/beast_core/memory/AllocatedBy.h | 63 -- modules/beast_core/memory/FifoFreeStore.h | 38 - .../memory/FifoFreeStoreWithTLS.cpp | 198 ----- .../beast_core/memory/FifoFreeStoreWithTLS.h | 69 -- .../memory/FifoFreeStoreWithoutTLS.cpp | 241 ------ .../memory/FifoFreeStoreWithoutTLS.h | 65 -- .../beast_core/memory/GlobalFifoFreeStore.h | 63 -- .../beast_core/memory/GlobalPagedFreeStore.h | 59 -- modules/beast_core/memory/PagedFreeStore.cpp | 227 ----- modules/beast_core/memory/PagedFreeStore.h | 102 --- modules/beast_core/memory/StaticObject.h | 90 +- modules/beast_core/thread/CallQueue.cpp | 305 ------- modules/beast_core/thread/CallQueue.h | 506 ----------- modules/beast_core/thread/DeadlineTimer.h | 5 +- .../beast_core/thread/InterruptibleThread.cpp | 275 ------ .../beast_core/thread/InterruptibleThread.h | 180 ---- modules/beast_core/thread/Listeners.cpp | 758 ----------------- modules/beast_core/thread/Listeners.h | 797 ------------------ modules/beast_core/thread/ManualCallQueue.cpp | 54 -- modules/beast_core/thread/ManualCallQueue.h | 108 --- .../beast_core/thread/ThreadWithCallQueue.cpp | 283 ------- .../beast_core/thread/ThreadWithCallQueue.h | 155 ---- 35 files changed, 59 insertions(+), 5641 deletions(-) rename modules/beast_core/memory/GlobalPagedFreeStore.cpp => beast/SmartPtr.h (74%) rename {modules/beast_core/memory => beast/smart_ptr}/ContainerDeletePolicy.h (92%) rename {modules/beast_core/memory => beast/smart_ptr}/ScopedPointer.h (98%) delete mode 100644 modules/beast_core/containers/DynamicList.cpp delete mode 100644 modules/beast_core/containers/DynamicList.h delete mode 100644 modules/beast_core/memory/AllocatedBy.h delete mode 100644 modules/beast_core/memory/FifoFreeStore.h delete mode 100644 modules/beast_core/memory/FifoFreeStoreWithTLS.cpp delete mode 100644 modules/beast_core/memory/FifoFreeStoreWithTLS.h delete mode 100644 modules/beast_core/memory/FifoFreeStoreWithoutTLS.cpp delete mode 100644 modules/beast_core/memory/FifoFreeStoreWithoutTLS.h delete mode 100644 modules/beast_core/memory/GlobalFifoFreeStore.h delete mode 100644 modules/beast_core/memory/GlobalPagedFreeStore.h delete mode 100644 modules/beast_core/memory/PagedFreeStore.cpp delete mode 100644 modules/beast_core/memory/PagedFreeStore.h delete mode 100644 modules/beast_core/thread/CallQueue.cpp delete mode 100644 modules/beast_core/thread/CallQueue.h delete mode 100644 modules/beast_core/thread/InterruptibleThread.cpp delete mode 100644 modules/beast_core/thread/InterruptibleThread.h delete mode 100644 modules/beast_core/thread/Listeners.cpp delete mode 100644 modules/beast_core/thread/Listeners.h delete mode 100644 modules/beast_core/thread/ManualCallQueue.cpp delete mode 100644 modules/beast_core/thread/ManualCallQueue.h delete mode 100644 modules/beast_core/thread/ThreadWithCallQueue.cpp delete mode 100644 modules/beast_core/thread/ThreadWithCallQueue.h diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index 7db57353..0b56b695 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -133,6 +133,9 @@ + + + @@ -228,7 +231,6 @@ - @@ -257,26 +259,17 @@ - - - - - - - - - @@ -334,15 +327,10 @@ - - - - - @@ -697,12 +685,6 @@ true true - - true - true - true - true - true true @@ -827,36 +809,12 @@ true true - - true - true - true - true - - - true - true - true - true - - - true - true - true - true - true true true true - - true - true - true - true - true true @@ -1175,36 +1133,12 @@ true true - - true - true - true - true - true true true true - - true - true - true - true - - - true - true - true - true - - - true - true - true - true - true true @@ -1223,12 +1157,6 @@ true true - - true - true - true - true - true true diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters index cb4ccd72..35e52891 100644 --- a/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -285,6 +285,12 @@ {7243e5e5-ad7e-4d81-8444-d545919e850c} + + {549430fc-36f6-450e-9d8d-38f4b9e72fb5} + + + {4e9c54da-1581-41d7-ac75-48140e4a13d4} + @@ -377,9 +383,6 @@ beast_core\memory - - beast_core\memory - beast_core\memory @@ -704,9 +707,6 @@ beast_core\maths - - beast_core\memory - beast_core\diagnostic @@ -737,51 +737,15 @@ beast_core\thread - - beast_core\thread - - - beast_core\thread - - - beast_core\thread - - - beast_core\thread - beast_core\thread - - beast_core\thread - beast_core\thread beast_core\maths - - beast_core\memory - - - beast_core\memory - - - beast_core\memory - - - beast_core\memory - - - beast_core\memory - - - beast_core\memory - - - beast_core\memory - beast_asio\sockets @@ -818,9 +782,6 @@ beast_core\system - - beast_core\containers - beast\intrusive @@ -1245,6 +1206,15 @@ beast\config + + beast\smart_ptr + + + beast\smart_ptr + + + beast + @@ -1580,39 +1550,12 @@ beast_core\thread - - beast_core\thread - - - beast_core\thread - - - beast_core\thread - - - beast_core\thread - beast_core\thread - - beast_core\thread - beast_core\thread - - beast_core\memory - - - beast_core\memory - - - beast_core\memory - - - beast_core\memory - beast_asio\basics @@ -1622,9 +1565,6 @@ beast_core\system - - beast_core\containers - beast_asio\async diff --git a/modules/beast_core/memory/GlobalPagedFreeStore.cpp b/beast/SmartPtr.h similarity index 74% rename from modules/beast_core/memory/GlobalPagedFreeStore.cpp rename to beast/SmartPtr.h index 8a464ed6..1bdf1d91 100644 --- a/modules/beast_core/memory/GlobalPagedFreeStore.cpp +++ b/beast/SmartPtr.h @@ -17,27 +17,12 @@ */ //============================================================================== -namespace -{ +#ifndef BEAST_SMARTPTR_H_INCLUDED +#define BEAST_SMARTPTR_H_INCLUDED -// Size of a page -// -static const size_t globalPageBytes = 8 * 1024; - -} - -GlobalPagedFreeStore::GlobalPagedFreeStore () - : m_allocator (globalPageBytes) -{ -} - -GlobalPagedFreeStore::~GlobalPagedFreeStore () -{ -} - -GlobalPagedFreeStore::Ptr GlobalPagedFreeStore::getInstance () -{ - return SharedSingleton ::getInstance(); -} +#include "Config.h" +#include "smart_ptr/ContainerDeletePolicy.h" +#include "smart_ptr/ScopedPointer.h" +#endif diff --git a/modules/beast_core/memory/ContainerDeletePolicy.h b/beast/smart_ptr/ContainerDeletePolicy.h similarity index 92% rename from modules/beast_core/memory/ContainerDeletePolicy.h rename to beast/smart_ptr/ContainerDeletePolicy.h index 2a282b29..9d65bf11 100644 --- a/modules/beast_core/memory/ContainerDeletePolicy.h +++ b/beast/smart_ptr/ContainerDeletePolicy.h @@ -17,8 +17,10 @@ */ //============================================================================== -#ifndef BEAST_CONTAINERDELETEPOLICY_H_INCLUDED -#define BEAST_CONTAINERDELETEPOLICY_H_INCLUDED +#ifndef BEAST_SMARTPTR_CONTAINERDELETEPOLICY_H_INCLUDED +#define BEAST_SMARTPTR_CONTAINERDELETEPOLICY_H_INCLUDED + +namespace beast { /** The DeletePolicy provides a way to destroy objects stored in containers. @@ -45,4 +47,6 @@ struct ContainerDeletePolicy } }; +} + #endif diff --git a/modules/beast_core/memory/ScopedPointer.h b/beast/smart_ptr/ScopedPointer.h similarity index 98% rename from modules/beast_core/memory/ScopedPointer.h rename to beast/smart_ptr/ScopedPointer.h index 09906874..51d214d6 100644 --- a/modules/beast_core/memory/ScopedPointer.h +++ b/beast/smart_ptr/ScopedPointer.h @@ -21,8 +21,14 @@ */ //============================================================================== -#ifndef BEAST_SCOPEDPOINTER_H_INCLUDED -#define BEAST_SCOPEDPOINTER_H_INCLUDED +#ifndef BEAST_SMARTPTR_SCOPEDPOINTER_H_INCLUDED +#define BEAST_SMARTPTR_SCOPEDPOINTER_H_INCLUDED + +#include "ContainerDeletePolicy.h" +#include "../Uncopyable.h" +#include "../StaticAssert.h" + +namespace beast { //============================================================================== /** @@ -248,4 +254,7 @@ template void deleteAndZero (ScopedPointer&) { static_bassert (sizeof (Type) == 12345); } #endif -#endif // BEAST_SCOPEDPOINTER_H_INCLUDED +} + +#endif + diff --git a/modules/beast_asio/beast_asio.cpp b/modules/beast_asio/beast_asio.cpp index 1df4f9d6..624bafaf 100644 --- a/modules/beast_asio/beast_asio.cpp +++ b/modules/beast_asio/beast_asio.cpp @@ -39,7 +39,6 @@ namespace beast { #include "protocol/HandshakeDetectLogicPROXY.cpp" # include "http/HTTPParserImpl.h" -#include "http/HTTPParser.cpp" #include "http/HTTPClientType.cpp" #include "http/HTTPField.cpp" #include "http/HTTPHeaders.cpp" @@ -61,3 +60,5 @@ namespace beast { #include "system/BoostUnitTests.cpp" } + +#include "http/HTTPParser.cpp" diff --git a/modules/beast_asio/beast_asio.h b/modules/beast_asio/beast_asio.h index 3ca6fa4f..67eebfc1 100644 --- a/modules/beast_asio/beast_asio.h +++ b/modules/beast_asio/beast_asio.h @@ -89,10 +89,11 @@ namespace beast { # include "http/HTTPMessage.h" # include "http/HTTPRequest.h" # include "http/HTTPResponse.h" -# include "http/HTTPParser.h" } +# include "http/HTTPParser.h" + #include "http/HTTPClientType.h" namespace beast { diff --git a/modules/beast_asio/http/HTTPParser.cpp b/modules/beast_asio/http/HTTPParser.cpp index 6c5a5e41..db11fda6 100644 --- a/modules/beast_asio/http/HTTPParser.cpp +++ b/modules/beast_asio/http/HTTPParser.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +namespace beast { + HTTPParser::HTTPParser (Type type) : m_type (type) , m_impl (new HTTPParserImpl ( @@ -102,3 +104,5 @@ SharedPtr const& HTTPParser::response () return m_response; } + +} diff --git a/modules/beast_asio/http/HTTPParser.h b/modules/beast_asio/http/HTTPParser.h index 675e4a43..2788eea9 100644 --- a/modules/beast_asio/http/HTTPParser.h +++ b/modules/beast_asio/http/HTTPParser.h @@ -20,6 +20,8 @@ #ifndef BEAST_ASIO_HTTPPARSER_H_INCLUDED #define BEAST_ASIO_HTTPPARSER_H_INCLUDED +namespace beast { + class HTTPParserImpl; /** A parser for HTTPRequest and HTTPResponse objects. */ @@ -82,4 +84,6 @@ private: SharedPtr m_response; }; +} + #endif diff --git a/modules/beast_core/beast_core.cpp b/modules/beast_core/beast_core.cpp index d6fff72a..ba83844d 100644 --- a/modules/beast_core/beast_core.cpp +++ b/modules/beast_core/beast_core.cpp @@ -134,7 +134,6 @@ namespace beast #include "containers/NamedValueSet.cpp" #include "containers/PropertySet.cpp" #include "containers/Variant.cpp" -#include "containers/DynamicList.cpp" #include "diagnostic/FatalError.cpp" #include "diagnostic/FPUFlags.cpp" @@ -162,10 +161,6 @@ namespace beast #include "maths/Random.cpp" #include "memory/MemoryBlock.cpp" -#include "memory/FifoFreeStoreWithTLS.cpp" -#include "memory/FifoFreeStoreWithoutTLS.cpp" -#include "memory/GlobalPagedFreeStore.cpp" -#include "memory/PagedFreeStore.cpp" #include "memory/StaticObject.cpp" #include "misc/Main.cpp" @@ -197,13 +192,8 @@ namespace beast #include "thread/impl/TrackedMutex.cpp" #include "thread/DeadlineTimer.cpp" -#include "thread/InterruptibleThread.cpp" #include "thread/Stoppable.cpp" #include "thread/Semaphore.cpp" -#include "thread/CallQueue.cpp" -#include "thread/Listeners.cpp" -#include "thread/ManualCallQueue.cpp" -#include "thread/ThreadWithCallQueue.cpp" #include "thread/Workers.cpp" #include "threads/ChildProcess.cpp" diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h index bd09ac42..c43fdce6 100644 --- a/modules/beast_core/beast_core.h +++ b/modules/beast_core/beast_core.h @@ -45,6 +45,7 @@ // New header-only library modeled more closely according to boost #include "../../beast/CStdInt.h" +#include "../../beast/SmartPtr.h" #include "../../beast/StaticAssert.h" #include "../../beast/Uncopyable.h" #include "../../beast/Atomic.h" @@ -155,7 +156,6 @@ class FileOutputStream; #include "thread/TrackedMutex.h" #include "diagnostic/FatalError.h" #include "text/LexicalCast.h" -#include "memory/ContainerDeletePolicy.h" #include "maths/Math.h" #include "maths/uint24.h" #include "logging/Logger.h" @@ -180,8 +180,6 @@ class FileOutputStream; #include "containers/SortedSet.h" #include "maths/Range.h" #include "containers/SparseSet.h" -# include "containers/DynamicList.h" -#include "memory/ScopedPointer.h" #include "files/DirectoryIterator.h" #include "streams/InputStream.h" #include "files/FileInputStream.h" @@ -242,21 +240,8 @@ class FileOutputStream; #include "thread/DeadlineTimer.h" -#include "memory/AllocatedBy.h" -#include "memory/PagedFreeStore.h" -#include "memory/GlobalPagedFreeStore.h" -#include "memory/FifoFreeStoreWithTLS.h" -#include "memory/FifoFreeStoreWithoutTLS.h" -#include "memory/FifoFreeStore.h" -#include "memory/GlobalFifoFreeStore.h" - #include "thread/Semaphore.h" -#include "thread/InterruptibleThread.h" #include "thread/Stoppable.h" -#include "thread/CallQueue.h" -#include "thread/Listeners.h" -#include "thread/ManualCallQueue.h" -#include "thread/ThreadWithCallQueue.h" #include "thread/Workers.h" } diff --git a/modules/beast_core/containers/DynamicList.cpp b/modules/beast_core/containers/DynamicList.cpp deleted file mode 100644 index 35d2ac15..00000000 --- a/modules/beast_core/containers/DynamicList.cpp +++ /dev/null @@ -1,327 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -namespace ContainerTests -{ - -//------------------------------------------------------------------------------ - -/** Counts the number of occurrences of each type of operation. */ -class Counts -{ -public: - typedef std::size_t count_type; - - Counts () - : default_ctor (0) - , copy_ctor (0) - , copy_assign (0) - #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - , move_ctor (0) - , move_assign (0) - #endif - { - } - - Counts (Counts const& other) - : default_ctor (other.default_ctor) - , copy_ctor (other.copy_ctor) - , copy_assign (other.copy_assign) - #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - , move_ctor (other.move_ctor) - , move_assign (other.move_assign) - #endif - { - } - - Counts& operator= (Counts const& other) - { - default_ctor = other.default_ctor; - copy_ctor = other.copy_ctor; - copy_assign = other.copy_assign; - #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - move_ctor = other.move_ctor; - move_assign = other.move_assign; - #endif - return *this; - } - - friend inline Counts operator- (Counts const& lhs, Counts const& rhs) - { - Counts result; - result.default_ctor = lhs.default_ctor - rhs.default_ctor; - result.copy_ctor = lhs.copy_ctor - rhs.copy_ctor; - result.copy_assign = lhs.copy_assign - rhs.copy_assign; - #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - result.move_ctor = lhs.move_ctor - rhs.move_ctor; - result.move_assign = lhs.move_assign - rhs.move_assign; - #endif - return result; - } - - String toString () const - { - return String() - + "default_ctor(" + String::fromNumber (default_ctor) + ") " - + ", copy_ctor(" + String::fromNumber (copy_ctor) + ")" - + ", copy_assign(" + String::fromNumber (copy_assign) + ")" - #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - + ", move_ctor(" + String::fromNumber (move_ctor) + ")" - + ", move_assign(" + String::fromNumber (move_assign) + ")" - #endif - ; - } - - count_type default_ctor; - count_type copy_ctor; - count_type copy_assign; -#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - count_type move_ctor; - count_type move_assign; -#endif -}; - -//------------------------------------------------------------------------------ - -/** Counts the number of element operations performed in a scope. */ -class ScopedCounts : public Uncopyable -{ -public: - ScopedCounts (Counts const& counts) - : m_start (counts) - , m_counts (counts) - { - } - - Counts get () const - { - return m_counts - m_start; - } - -private: - Counts const m_start; - Counts const& m_counts; -}; - -//------------------------------------------------------------------------------ - -/* Base for element configurations. */ -class ElementConfigBase : public Uncopyable -{ -public: - typedef std::size_t IdType; -}; - -/** Provides the element-specific configuration members. */ -template -class ElementConfig : public ElementConfigBase -{ -public: - static Counts& getCounts () - { - static Counts counts; - return counts; - } -}; - -//------------------------------------------------------------------------------ - -/** Base for elements used in container unit tests. */ -class ElementBase -{ -public: -}; - -/** An object placed into a container for unit testing. */ -template -class Element : public ElementBase -{ -public: - typedef typename Config::IdType IdType; - - Element () - : m_id (0) - , m_msg (String::empty) - { - ++Config::getCounts ().default_ctor; - } - - explicit Element (IdType id) - : m_id (id) - , m_msg (String::fromNumber (id)) - { - } - - Element (Element const& other) - : m_id (other.m_id) - , m_msg (other.m_msg) - { - ++Config::getCounts ().copy_ctor; - } - - Element& operator= (Element const& other) - { - m_id = other.m_id; - m_msg = other.m_msg; - ++Config::getCounts ().copy_assign; - } - -#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - Element (Element&& other) - : m_id (other.m_id) - , m_msg (other.m_msg) - { - other.m_msg = String::empty; - ++Config::getCounts ().move_ctor; - } - - Element& operator= (Element&& other) - { - m_id = other.m_id; - m_msg = other.m_msg; - other.m_msg = String::empty; - ++Config::getCounts ().move_assign; - } -#endif - - IdType id () const - { - return m_id; - } - - String msg () const - { - return m_msg; - } - -private: - IdType m_id; - String m_msg; -}; - -//------------------------------------------------------------------------------ - -/** Base for test state parameters. */ -class StateBase : public Uncopyable -{ -public: - typedef int64 SeedType; -}; - -/** Provides configuration-specific test state parameters. */ -template -class State : public StateBase -{ -public: - static Random& random () - { - static Random generator (Params::seedValue); - return generator; - } -}; - -//------------------------------------------------------------------------------ - -class ConfigBase -{ -}; - -template