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 class Container,
- class Params>
-class Config
- : public State
- , public ElementConfig
-{
-public:
- typedef Config ConfigType;
- typedef Params ParamsType;
- typedef State StateType;
- typedef ElementConfig ElementConfigType;
- typedef Element ElementType;
- typedef Container <
- ElementType,
- std::allocator > ContainerType;
-
- typedef StateBase::SeedType SeedType;
-
- // default seed
- static SeedType const seedValue = 69;
-};
-
-//------------------------------------------------------------------------------
-
-/** A generic container test. */
-template
-class Test : public Params
-{
-public:
- typedef typename Params::StateType StateType;
- typedef typename Params::ElementConfigType ElementConfigType;
- typedef typename Params::ContainerType ContainerType;
-
- void doInsert ()
- {
- m_container.reserve (Params::elementCount);
- for (typename ContainerType::size_type i = 0;
- i < Params::elementCount; ++i)
- {
- m_container.push_back (typename Params::ElementType ());
- }
- }
-
-private:
- typename Params::ContainerType m_container;
-};
-
-//------------------------------------------------------------------------------
-
-class DynamicListTests : public UnitTest
-{
-public:
- struct Params : Config
- {
- static SeedType const seedValue = 42;
- static ContainerType::size_type const elementCount = 100 * 1000;
- };
-
- typedef Test TestType;
-
- void runTest ()
- {
- TestType test;
-
- beginTestCase ("insert");
-
- {
- ScopedCounts counts (TestType::getCounts ());
- test.doInsert ();
- this->logMessage (counts.get ().toString ());
- }
-
- pass ();
- }
-
- DynamicListTests () : UnitTest ("DynamicList", "beast")
- {
- }
-};
-
-static DynamicListTests dynamicListTests;
-
-}
diff --git a/modules/beast_core/containers/DynamicList.h b/modules/beast_core/containers/DynamicList.h
deleted file mode 100644
index d3768239..00000000
--- a/modules/beast_core/containers/DynamicList.h
+++ /dev/null
@@ -1,473 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_CORE_CONTAINERS_DYNAMICLIST_H_INCLUDED
-#define BEAST_CORE_CONTAINERS_DYNAMICLIST_H_INCLUDED
-
-template
-class DynamicList;
-
-template
-class DynamicListIterator
- : public std::iterator <
- std::bidirectional_iterator_tag,
- typename Container::value_type,
- typename Container::difference_type,
- typename mpl::IfCond ::type,
- typename mpl::IfCond ::type>
-{
-private:
- typedef typename mpl::IfCond ::const_iterator,
- typename List ::iterator>::type iterator_type;
-
- typedef typename mpl::IfCond ::type pointer;
-
- typedef typename mpl::IfCond ::type reference;
-
-public:
- DynamicListIterator ()
- {
- }
-
- DynamicListIterator (iterator_type iter)
- : m_iter (iter)
- {
- }
-
- DynamicListIterator (DynamicListIterator const& other)
- : m_iter (other.m_iter)
- {
- }
-
- template
- DynamicListIterator (DynamicListIterator const& other)
- : m_iter (other.m_iter)
- {
- }
-
- DynamicListIterator& operator= (DynamicListIterator const& other)
- {
- m_iter = other.m_iter;
- return *this;
- }
-
- template
- DynamicListIterator& operator= (DynamicListIterator <
- Container, OtherIsConst> const& other)
- {
- m_iter = other.m_iter;
- return *this;
- }
-
- template
- bool operator== (DynamicListIterator const& other) const
- {
- return m_iter == other.m_iter;
- }
-
- template
- bool operator!= (DynamicListIterator const& other) const
- {
- return ! ((*this) == other);
- }
-
- reference operator* () const
- {
- return dereference ();
- }
-
- pointer operator-> () const
- {
- return &dereference ();
- }
-
- DynamicListIterator& operator++ ()
- {
- increment ();
- return *this;
- }
-
- DynamicListIterator operator++ (int)
- {
- DynamicListIterator const result (*this);
- increment ();
- return result;
- }
-
- DynamicListIterator& operator-- ()
- {
- decrement ();
- return *this;
- }
-
- DynamicListIterator operator-- (int)
- {
- DynamicListIterator const result (*this);
- decrement ();
- return result;
- }
-
-private:
- template
- friend class DynamicList;
-
- reference dereference () const
- {
- return *(m_iter->get ());
- }
-
- void increment ()
- {
- ++m_iter;
- }
-
- void decrement ()
- {
- --m_iter;
- }
-
- iterator_type m_iter;
-};
-
-//------------------------------------------------------------------------------
-
-/** A list that uses a very small number of dynamic allocations.
-
- Once an element is allocated, its address does not change. Elements
- can be erased, and they are placed onto a deleted list for re-use.
- Allocations occur in configurable batches.
-
- Iterators to elements never become invalid, they can be safely
- stored elsewhere, as long as the underlying element is not erased.
-
- T may support these concepts:
- DefaultConstructible
- MoveConstructible (C++11)
-
- T must support these concepts:
- Destructible
-*/
-template >
-class DynamicList
-{
-private:
- typedef PARAMETER_TYPE (T) TParam;
-
-public:
- enum
- {
- defaultBlocksize = 1000
- };
-
- typedef T value_type;
- typedef Allocator allocator_type;
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
- typedef T* pointer;
- typedef T& reference;
- typedef T const* const_pointer;
- typedef T const& const_reference;
-
- typedef DynamicList <
- T,
- Allocator> container_type;
-
- typedef DynamicListIterator iterator;
- typedef DynamicListIterator const_iterator;
-
-public:
- explicit DynamicList (
- size_type blocksize = defaultBlocksize,
- Allocator const& allocator = Allocator ())
- : m_allocator (allocator)
- , m_blocksize (blocksize)
- , m_capacity (0)
- {
- }
-
- ~DynamicList ()
- {
- clear ();
- shrink_to_fit ();
- }
-
- allocator_type get_allocator () const noexcept
- {
- return m_allocator;
- }
-
- //--------------------------------------------------------------------------
-
- reference front () noexcept
- {
- return *m_items.front ().get ();
- }
-
- const_reference front () const noexcept
- {
- return *m_items.front ().get ();
- }
-
- reference back () noexcept
- {
- return *m_items.back ().get ();
- }
-
- const_reference back () const noexcept
- {
- return *m_items.back ().get ();
- }
-
- //--------------------------------------------------------------------------
-
- iterator begin () noexcept
- {
- return iterator (m_items.begin ());
- }
-
- const_iterator begin () const noexcept
- {
- return const_iterator (m_items.begin ());
- }
-
- const_iterator cbegin () const noexcept
- {
- return const_iterator (m_items.cbegin ());
- }
-
- iterator end () noexcept
- {
- return iterator (m_items.end ());
- }
-
- const_iterator end () const noexcept
- {
- return const_iterator (m_items.end ());
- }
-
- const_iterator cend () const noexcept
- {
- return const_iterator (m_items.cend ());
- }
-
- iterator iterator_to (T& value) noexcept
- {
- std::ptrdiff_t const offset (
- (std::ptrdiff_t)(((Item const*)0)->get ()));
- Item& item (*addBytesToPointer (((Item*)&value), -offset));
- return iterator (m_items.iterator_to (item));
- }
-
- const_iterator const_iterator_to (T const& value) const noexcept
- {
- std::ptrdiff_t const offset (
- (std::ptrdiff_t)(((Item const*)0)->get ()));
- Item const& item (*addBytesToPointer (((Item const*)&value), -offset));
- return const_iterator (m_items.const_iterator_to (item));
- }
-
- //--------------------------------------------------------------------------
-
- bool empty () const noexcept
- {
- return m_items.empty ();
- }
-
- size_type size () const noexcept
- {
- return m_items.size ();
- }
-
- size_type max_size () const noexcept
- {
- return std::numeric_limits ::max ();
- }
-
- void reserve (size_type new_cap) noexcept
- {
- new_cap = m_blocksize * (
- (new_cap + m_blocksize - 1) / m_blocksize);
- if (new_cap > max_size ())
- Throw (std::length_error ("new_cap > max_size"), __FILE__, __LINE__);
- if (new_cap <= m_capacity)
- return;
- size_type const n (new_cap / m_blocksize);
- m_handles.reserve (n);
- for (size_type i = m_handles.size (); i < n; ++i)
- m_handles.push_back (static_cast - (std::malloc (
- m_blocksize * sizeof (Item))));
- m_capacity = new_cap;
- }
-
- size_type capacity () const noexcept
- {
- return m_capacity;
- }
-
- void shrink_to_fit ()
- {
- // Special case when all allocated
- // items are part of the free list.
- if (m_items.empty ())
- m_free.clear ();
-
- size_type const used (m_items.size () + m_free.size ());
- size_type const handles ((used + m_blocksize - 1) / m_blocksize);
- m_capacity = handles * m_blocksize;
- for (size_type i = m_handles.size (); i-- > handles;)
- {
- std::free (m_handles [i]);
- m_handles.erase (m_handles.begin () + i);
- }
- }
-
- //--------------------------------------------------------------------------
-
- void clear ()
- {
- // Might want to skip this if is_pod is true
- for (typename List
- ::iterator iter = m_items.begin ();
- iter != m_items.end ();)
- {
- Item& item (*iter++);
- item.get ()->~T ();
- m_free.push_back (item);
- }
- }
-
- /** Allocate a new default-constructed element and return the iterator.
- If there are deleted elements in the free list, the new element
- may not be created at the end of the storage area.
- */
- iterator emplace_back ()
- {
- return iterator_to (*new (alloc ()->get ()) T ());
- }
-
- template
- iterator emplace_back (A1 a1)
- {
- return iterator_to (*new (alloc ()->get ()) T (a1));
- }
-
- template
- iterator emplace_back (A1 a1, A2 a2)
- {
- return iterator_to (*new (alloc ()->get ()) T (a1, a2));
- }
-
- template
- iterator emplace_back (A1 a1, A2 a2, A3 a3)
- {
- return iterator_to (*new (alloc ()->get ()) T (a1, a2, a3));
- }
-
- template
- iterator emplace_back (A1 a1, A2 a2, A3 a3, A4 a4)
- {
- return iterator_to (*new (alloc ()->get ()) T (a1, a2, a3, a4));
- }
-
- template
- iterator emplace_back (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
- {
- return iterator_to (*new (alloc ()->get ()) T (a1, a2, a3, a4, a5));
- }
-
- /** Allocate a new copy-constructed element and return the index. */
- iterator push_back (TParam value) noexcept
- {
- return iterator_to (*new (alloc ()->get ()) T (value));
- }
-
- /** Erase the element at the specified position. */
- iterator erase (iterator pos)
- {
- Item& item (*pos.m_iter);
- item.get ()->~T ();
- pos = m_items.erase (m_items.iterator_to (item));
- m_free.push_front (item);
- return pos;
- }
-
-private:
- template
- friend class DynamicListIterator;
-
- struct Item : List
- ::Node
- {
- typedef T value_type;
-
- T* get () noexcept
- {
- return reinterpret_cast (&storage [0]);
- }
-
- T const* get () const noexcept
- {
- return reinterpret_cast (&storage [0]);
- }
-
- private:
- // Lets hope this is padded correctly
- uint8 storage [sizeof (T)];
- };
-
- Item* alloc () noexcept
- {
- Item* item;
- if (m_free.empty ())
- {
- if (m_capacity <= m_items.size ())
- reserve (m_items.size () + 1);
-
- size_type const index (m_items.size () / m_blocksize);
- size_type const offset (m_items.size () - index * m_blocksize);
- item = m_handles [index] + offset;
- }
- else
- {
- item = &m_free.pop_front ();
- }
-
- m_items.push_back (*item);
- return item;
- }
-
- typedef std::vector
- blocks_t;
-
- Allocator m_allocator;
- size_type m_blocksize;
- size_type m_capacity;
- std::vector
- m_handles;
- List
- m_items;
- List
- m_free;
-};
-
-#endif
diff --git a/modules/beast_core/memory/AllocatedBy.h b/modules/beast_core/memory/AllocatedBy.h
deleted file mode 100644
index c790b6f5..00000000
--- a/modules/beast_core/memory/AllocatedBy.h
+++ /dev/null
@@ -1,63 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_ALLOCATEDBY_H_INCLUDED
-#define BEAST_ALLOCATEDBY_H_INCLUDED
-
-/*============================================================================*/
-/**
- Customized allocation for heap objects.
-
- Derived classes will use the specified allocator for new and delete.
-
- @param AllocatorType The type of allocator to use.
-
- @ingroup beast_concurrent
-*/
-template
-class AllocatedBy
-{
-public:
- static inline void* operator new (size_t bytes, AllocatorType& allocator) noexcept
- {
- return allocator.allocate (bytes);
- }
-
- static inline void* operator new (size_t bytes, AllocatorType* allocator) noexcept
- {
- return allocator->allocate (bytes);
- }
-
- static inline void operator delete (void* p, AllocatorType&) noexcept
- {
- AllocatorType::deallocate (p);
- }
-
- static inline void operator delete (void* p, AllocatorType*) noexcept
- {
- AllocatorType::deallocate (p);
- }
-
- static inline void operator delete (void* p) noexcept
- {
- AllocatorType::deallocate (p);
- }
-};
-
-#endif
diff --git a/modules/beast_core/memory/FifoFreeStore.h b/modules/beast_core/memory/FifoFreeStore.h
deleted file mode 100644
index 1acbbf79..00000000
--- a/modules/beast_core/memory/FifoFreeStore.h
+++ /dev/null
@@ -1,38 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_FIFOFREESTORE_H_INCLUDED
-#define BEAST_FIFOFREESTORE_H_INCLUDED
-
-/** Selected free store based on compilation settings.
-
- @ingroup beast_concurrent
-*/
-// VFALCO NOTE Disabled this because it seems that the TLS
-// implementation has a leak. Although the other
-// one also seems to have a leak.
-//
-//#if BEAST_USE_BOOST_FEATURES
-#if 0
-typedef FifoFreeStoreWithTLS FifoFreeStoreType;
-#else
-typedef FifoFreeStoreWithoutTLS FifoFreeStoreType;
-#endif
-
-#endif
diff --git a/modules/beast_core/memory/FifoFreeStoreWithTLS.cpp b/modules/beast_core/memory/FifoFreeStoreWithTLS.cpp
deleted file mode 100644
index d277ba02..00000000
--- a/modules/beast_core/memory/FifoFreeStoreWithTLS.cpp
+++ /dev/null
@@ -1,198 +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.
-*/
-//==============================================================================
-
-// Implementation notes
-//
-// - A Page is a large allocation from a global PageAllocator.
-//
-// - Each thread maintains an 'active' page from which it makes allocations.
-//
-// - When the active page is full, a new one takes it's place.
-//
-// - Page memory is deallocated when it is not active and no longer referenced.
-//
-// - Each instance of FifoFreeStoreWithTLS maintains its own set of per-thread active pages,
-// but uses a global PageAllocator. This reduces memory consumption without
-// affecting performance.
-//
-
-#if BEAST_USE_BOOST_FEATURES
-
-// This precedes every allocation
-//
-struct FifoFreeStoreWithTLS::Header
-{
- FifoFreeStoreWithTLS::Page* page;
-};
-
-//------------------------------------------------------------------------------
-
-class FifoFreeStoreWithTLS::Page : LeakChecked , public Uncopyable
-{
-public:
- explicit Page (const size_t bytes) : m_refs (1)
- {
- m_end = reinterpret_cast (this) + bytes;
- m_free = reinterpret_cast (
- Memory::pointerAdjustedForAlignment (this + 1));
- }
-
- ~Page ()
- {
- bassert (! m_refs.isSignaled ());
- }
-
- inline bool release ()
- {
- bassert (! m_refs.isSignaled ());
-
- return m_refs.release ();
- }
-
- void* allocate (size_t bytes)
- {
- bassert (bytes > 0);
-
- char* p = Memory::pointerAdjustedForAlignment (m_free);
- char* free = p + bytes;
-
- if (free <= m_end)
- {
- m_free = free;
-
- m_refs.addref ();
- }
- else
- {
- p = 0;
- }
-
- return p;
- }
-
-private:
- AtomicCounter m_refs; // reference count
- char* m_free; // next free byte
- char* m_end; // last free byte + 1
-};
-
-//------------------------------------------------------------------------------
-
-class FifoFreeStoreWithTLS::PerThreadData : LeakChecked , public Uncopyable
-{
-public:
- explicit PerThreadData (FifoFreeStoreWithTLS* allocator)
- : m_allocator (*allocator)
- , m_active (m_allocator.newPage ())
- {
- }
-
- ~PerThreadData ()
- {
- if (m_active->release ())
- m_allocator.deletePage (m_active);
- }
-
- inline void* allocate (const size_t bytes)
- {
- const size_t headerBytes = Memory::sizeAdjustedForAlignment (sizeof (Header));
- const size_t bytesNeeded = headerBytes + bytes;
-
- if (bytesNeeded > m_allocator.m_pages->getPageBytes ())
- fatal_error ("the memory request was too large");
-
- Header* header;
-
- header = reinterpret_cast (m_active->allocate (bytesNeeded));
-
- if (!header)
- {
- if (m_active->release ())
- deletePage (m_active);
-
- m_active = m_allocator.newPage ();
-
- header = reinterpret_cast (m_active->allocate (bytesNeeded));
- }
-
- header->page = m_active;
-
- return reinterpret_cast (header) + headerBytes;
- }
-
-private:
- FifoFreeStoreWithTLS& m_allocator;
- Page* m_active;
-};
-
-//------------------------------------------------------------------------------
-
-inline FifoFreeStoreWithTLS::Page* FifoFreeStoreWithTLS::newPage ()
-{
- return new (m_pages->allocate ()) Page (m_pages->getPageBytes ());
-}
-
-inline void FifoFreeStoreWithTLS::deletePage (Page* page)
-{
- // Safe, because each thread maintains its own active page.
- page->~Page ();
- PagedFreeStoreType::deallocate (page);
-}
-
-FifoFreeStoreWithTLS::FifoFreeStoreWithTLS ()
- : m_pages (PagedFreeStoreType::getInstance ())
-{
- //bassert (m_pages->getPageBytes () >= sizeof (Page) + Memory::allocAlignBytes);
-}
-
-FifoFreeStoreWithTLS::~FifoFreeStoreWithTLS ()
-{
- // Clean up this thread's data before we release
- // the reference to the global page allocator.
- m_tsp.reset (0);
-}
-
-//------------------------------------------------------------------------------
-
-void* FifoFreeStoreWithTLS::allocate (const size_t bytes)
-{
- PerThreadData* data = m_tsp.get ();
-
- if (!data)
- {
- data = new PerThreadData (this);
- m_tsp.reset (data);
- }
-
- return data->allocate (bytes);
-}
-
-//------------------------------------------------------------------------------
-
-void FifoFreeStoreWithTLS::deallocate (void* p)
-{
- const size_t headerBytes = Memory::sizeAdjustedForAlignment (sizeof (Header));
- Header* const header = reinterpret_cast (reinterpret_cast (p) - headerBytes);
- Page* const page = header->page;
-
- if (page->release ())
- deletePage (page);
-}
-
-#endif
diff --git a/modules/beast_core/memory/FifoFreeStoreWithTLS.h b/modules/beast_core/memory/FifoFreeStoreWithTLS.h
deleted file mode 100644
index f53e3271..00000000
--- a/modules/beast_core/memory/FifoFreeStoreWithTLS.h
+++ /dev/null
@@ -1,69 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_FIFOFREESTOREWITHTLS_H_INCLUDED
-#define BEAST_FIFOFREESTOREWITHTLS_H_INCLUDED
-
-#if BEAST_USE_BOOST_FEATURES
-
-/*============================================================================*/
-/**
- Lock-free and mostly wait-free FIFO memory allocator.
-
- This allocator is suitable for use with CallQueue and Listeners. It is
- expected that over time, deallocations will occur in roughly the same order
- as allocations.
-
- @note This implementation uses Thread Local Storage to further improve
- performance. However, it requires boost style thread_specific_ptr.
-
- @invariant allocate() and deallocate() are fully concurrent.
-
- @invariant The ABA problem is handled automatically.
-
- @ingroup beast_concurrent
-*/
-class BEAST_API FifoFreeStoreWithTLS : public LeakChecked
-{
-public:
- FifoFreeStoreWithTLS ();
- ~FifoFreeStoreWithTLS ();
-
- void* allocate (const size_t bytes);
- static void deallocate (void* const p);
-
-private:
- typedef GlobalPagedFreeStore PagedFreeStoreType;
- struct Header;
-
- class Page;
-
- inline Page* newPage ();
- static inline void deletePage (Page* page);
-
-private:
- class PerThreadData;
- boost::thread_specific_ptr m_tsp;
-
- PagedFreeStoreType::Ptr m_pages;
-};
-
-#endif
-
-#endif
diff --git a/modules/beast_core/memory/FifoFreeStoreWithoutTLS.cpp b/modules/beast_core/memory/FifoFreeStoreWithoutTLS.cpp
deleted file mode 100644
index da07d46f..00000000
--- a/modules/beast_core/memory/FifoFreeStoreWithoutTLS.cpp
+++ /dev/null
@@ -1,241 +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.
-*/
-//==============================================================================
-
-// This precedes every allocation
-struct FifoFreeStoreWithoutTLS::Header
-{
- union
- {
- FifoFreeStoreWithoutTLS::Block* block; // backpointer to the page
-
- char pad [Memory::allocAlignBytes];
- };
-};
-
-//------------------------------------------------------------------------------
-
-class FifoFreeStoreWithoutTLS::Block : public Uncopyable
-{
-public:
- explicit Block (const size_t bytes) : m_refs (1)
- {
- m_end = reinterpret_cast (this) + bytes;
- m_free = reinterpret_cast (
- Memory::pointerAdjustedForAlignment (this + 1));
- }
-
- ~Block ()
- {
- bassert (!m_refs.isSignaled ());
- }
-
- inline void addref ()
- {
- m_refs.addref ();
- }
-
- inline bool release ()
- {
- return m_refs.release ();
- }
-
- enum Result
- {
- success, // successful allocation
- ignore, // disregard the block
- consumed // block is consumed (1 thread sees this)
- };
-
- Result allocate (size_t bytes, void* pBlock)
- {
- bassert (bytes > 0);
-
- Result result;
-
- for (;;)
- {
- char* base = m_free.get ();
-
- if (base)
- {
- char* p = Memory::pointerAdjustedForAlignment (base);
- char* free = p + bytes;
-
- if (free <= m_end)
- {
- // Try to commit the allocation
- if (m_free.compareAndSet (free, base))
- {
- * (reinterpret_cast (pBlock)) = p;
- result = success;
- break;
- }
- else
- {
- // Someone changed m_free, retry.
- }
- }
- else
- {
- // Mark the block consumed.
- if (m_free.compareAndSet (0, base))
- {
- // Only one caller sees this, the rest get 'ignore'
- result = consumed;
- break;
- }
- else
- {
- // Happens with another concurrent allocate(), retry.
- }
- }
- }
- else
- {
- // Block is consumed, ignore it.
- result = ignore;
- break;
- }
- }
-
- return result;
- }
-
-private:
- AtomicCounter m_refs; // reference count
- AtomicPointer m_free; // next free byte or 0 if inactive.
- char* m_end; // last free byte + 1
-};
-
-//------------------------------------------------------------------------------
-
-inline FifoFreeStoreWithoutTLS::Block* FifoFreeStoreWithoutTLS::newBlock ()
-{
- return new (m_pages->allocate ()) Block (m_pages->getPageBytes ());
-}
-
-inline void FifoFreeStoreWithoutTLS::deleteBlock (Block* b)
-{
- // It is critical that we do not call the destructor,
- // because due to the lock-free implementation, a Block
- // can be accessed for a short time after it is deleted.
- /* b->~Block (); */ // DO NOT CALL!!!
-
- PagedFreeStoreType::deallocate (b);
-}
-
-FifoFreeStoreWithoutTLS::FifoFreeStoreWithoutTLS ()
- : m_pages (GlobalPagedFreeStore::getInstance ())
-{
- if (m_pages->getPageBytes () < sizeof (Block) + 256)
- fatal_error ("the block size is too small");
-
- m_active = newBlock ();
-}
-
-FifoFreeStoreWithoutTLS::~FifoFreeStoreWithoutTLS ()
-{
- deleteBlock (m_active);
-}
-
-//------------------------------------------------------------------------------
-
-void* FifoFreeStoreWithoutTLS::allocate (const size_t bytes)
-{
- const size_t actual = sizeof (Header) + bytes;
-
- if (actual > m_pages->getPageBytes ())
- fatal_error ("the memory request was too large");
-
- Header* h;
-
- for (;;)
- {
- // Get an active block.
- Block* b = m_active;
-
- while (!b)
- {
- Thread::yield ();
- b = m_active;
- }
-
- // (*) It is possible for the block to get a final release here
- // In this case it will have been put in the garbage, and
- // m_active will not match.
-
- // Acquire a reference.
- b->addref ();
-
- // Is it still active?
- if (m_active == b)
- {
- // Yes so try to allocate from it.
- const Block::Result result = b->allocate (actual, &h);
-
- if (result == Block::success)
- {
- // Keep the reference and return the allocation.
- h->block = b;
- break;
- }
- else if (result == Block::consumed)
- {
- // Remove block from active.
- m_active = 0;
-
- // Take away the reference we added
- b->release ();
-
- // Take away the original active reference.
- if (b->release ())
- deleteBlock (b);
-
- // Install a fresh empty active block.
- m_active = newBlock ();
- }
- else
- {
- if (b->release ())
- deleteBlock (b);
- }
-
- // Try again.
- }
- else
- {
- // Block became inactive, so release our reference.
- b->release ();
-
- // (*) It is possible for this to be a duplicate final release.
- }
- }
-
- return h + 1;
-}
-
-//------------------------------------------------------------------------------
-
-void FifoFreeStoreWithoutTLS::deallocate (void* p)
-{
- Block* const b = (reinterpret_cast (p) - 1)->block;
-
- if (b->release ())
- deleteBlock (b);
-}
diff --git a/modules/beast_core/memory/FifoFreeStoreWithoutTLS.h b/modules/beast_core/memory/FifoFreeStoreWithoutTLS.h
deleted file mode 100644
index 2b9fc9da..00000000
--- a/modules/beast_core/memory/FifoFreeStoreWithoutTLS.h
+++ /dev/null
@@ -1,65 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_FIFOFREESTOREWITHOUTTLS_H_INCLUDED
-#define BEAST_FIFOFREESTOREWITHOUTTLS_H_INCLUDED
-
-/*============================================================================*/
-/**
- Lock-free FIFO memory allocator.
-
- This allocator is suitable for use with CallQueue and Listeners. It is
- expected that over time, deallocations will occur in roughly the same order
- as allocations.
-
- @note This version of the fifo free store uses less memory and doesn't require
- thread specific storage. However, it runs slower. The performance
- differences are negligible for desktop class applications.
-
- @invariant allocate() and deallocate() are fully concurrent.
-
- @invariant The ABA problem is handled automatically.
-
- @ingroup beast_concurrent
-*/
-class BEAST_API FifoFreeStoreWithoutTLS : LeakChecked
-{
-public:
- explicit FifoFreeStoreWithoutTLS ();
- ~FifoFreeStoreWithoutTLS ();
-
- void* allocate (const size_t bytes);
- static void deallocate (void* const p);
-
-private:
- typedef GlobalPagedFreeStore PagedFreeStoreType;
-
- struct Header;
-
- class Block;
-
- inline Block* newBlock ();
- static inline void deleteBlock (Block* b);
-
-private:
- Block* volatile m_active;
- PagedFreeStoreType::Ptr m_pages;
-};
-
-#endif
diff --git a/modules/beast_core/memory/GlobalFifoFreeStore.h b/modules/beast_core/memory/GlobalFifoFreeStore.h
deleted file mode 100644
index a7c6ecc9..00000000
--- a/modules/beast_core/memory/GlobalFifoFreeStore.h
+++ /dev/null
@@ -1,63 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_GLOBALFIFOFREESTORE_H_INCLUDED
-#define BEAST_GLOBALFIFOFREESTORE_H_INCLUDED
-
-/*============================================================================*/
-/**
- A @ref FifoFreeStoreType singleton.
-
- @ingroup beast_concurrent
-*/
-template
-class GlobalFifoFreeStore
-{
-public:
- inline void* allocate (size_t bytes)
- {
- return m_allocator.allocate (bytes);
- }
-
- static inline void deallocate (void* const p)
- {
- FifoFreeStoreType::deallocate (p);
- }
-
- typedef SharedPtr > Ptr;
-
- static Ptr getInstance ()
- {
- return SharedSingleton ::getInstance();
- }
-
-public:
- GlobalFifoFreeStore ()
- {
- }
-
- ~GlobalFifoFreeStore ()
- {
- }
-
-private:
- FifoFreeStoreType m_allocator;
-};
-
-#endif
diff --git a/modules/beast_core/memory/GlobalPagedFreeStore.h b/modules/beast_core/memory/GlobalPagedFreeStore.h
deleted file mode 100644
index 9b573dfb..00000000
--- a/modules/beast_core/memory/GlobalPagedFreeStore.h
+++ /dev/null
@@ -1,59 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_GLOBALPAGEDFREESTORE_H_INCLUDED
-#define BEAST_GLOBALPAGEDFREESTORE_H_INCLUDED
-
-/*============================================================================*/
-/**
- A PagedFreeStore singleton.
-
- @ingroup beast_concurrent
-*/
-class BEAST_API GlobalPagedFreeStore : public LeakChecked
-{
-public:
- GlobalPagedFreeStore ();
- ~GlobalPagedFreeStore ();
-
-public:
- inline size_t getPageBytes ()
- {
- return m_allocator.getPageBytes ();
- }
-
- inline void* allocate ()
- {
- return m_allocator.allocate ();
- }
-
- static inline void deallocate (void* const p)
- {
- PagedFreeStore::deallocate (p);
- }
-
- typedef SharedPtr > Ptr;
-
- static Ptr getInstance ();
-
-private:
- PagedFreeStore m_allocator;
-};
-
-#endif
diff --git a/modules/beast_core/memory/PagedFreeStore.cpp b/modules/beast_core/memory/PagedFreeStore.cpp
deleted file mode 100644
index 05b92ba3..00000000
--- a/modules/beast_core/memory/PagedFreeStore.cpp
+++ /dev/null
@@ -1,227 +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.
-*/
-//==============================================================================
-
-#define LOG_GC 0
-
-namespace
-{
-
-// This is the upper limit on the amount of physical memory an instance of the
-// allocator will allow. Going over this limit means that consumers cannot keep
-// up with producers, and application logic should be re-examined.
-//
-// TODO: ENFORCE THIS GLOBALLY? MEASURE IN KILOBYTES AND FORCE KILOBYTE PAGE SIZES
-#define HARD_LIMIT 1
-const size_t hardLimitMegaBytes = 256;
-
-}
-
-/*
-
-Implementation notes
-
-- There are two pools, the 'hot' pool and the 'cold' pool.
-
-- When a new page is needed we pop from the 'fresh' stack of the hot pool.
-
-- When a page is deallocated it is pushed to the 'garbage' stack of the hot pool.
-
-- Every so often, a garbage collection is performed on a separate thread.
- During collection, fresh and garbage are swapped in the cold pool.
- Then, the hot and cold pools are atomically swapped.
-
-*/
-//------------------------------------------------------------------------------
-
-struct PagedFreeStore::Page : Pages::Node, LeakChecked
-{
- explicit Page (PagedFreeStore* const allocator)
- : m_allocator (*allocator)
- {
- }
-
- PagedFreeStore& getAllocator () const
- {
- return m_allocator;
- }
-
-private:
- PagedFreeStore& m_allocator;
-};
-
-inline void* PagedFreeStore::fromPage (Page* const p)
-{
- return reinterpret_cast (p) +
- Memory::sizeAdjustedForAlignment (sizeof (Page));
-}
-
-inline PagedFreeStore::Page* PagedFreeStore::toPage (void* const p)
-{
- return reinterpret_cast (
- (reinterpret_cast (p) -
- Memory::sizeAdjustedForAlignment (sizeof (Page))));
-}
-
-//------------------------------------------------------------------------------
-
-PagedFreeStore::PagedFreeStore (const size_t pageBytes)
- : m_timer (this)
- , m_pageBytes (pageBytes)
- , m_pageBytesAvailable (pageBytes - Memory::sizeAdjustedForAlignment (sizeof (Page)))
- , m_newPagesLeft (int ((hardLimitMegaBytes * 1024 * 1024) / m_pageBytes))
-#if LOG_GC
- , m_swaps (0)
-#endif
-{
- m_hot = m_pool1;
- m_cold = m_pool2;
-
- m_timer.setExpiration (1.0);
-}
-
-PagedFreeStore::~PagedFreeStore ()
-{
- m_timer.cancel ();
-
-#if LOG_GC
- bassert (!m_used.isSignaled ());
-#endif
-
- dispose (m_pool1);
- dispose (m_pool2);
-
-#if LOG_GC
- bassert (!m_total.isSignaled ());
-#endif
-}
-
-//------------------------------------------------------------------------------
-
-void* PagedFreeStore::allocate ()
-{
- Page* page = m_hot->fresh->pop_front ();
-
- if (!page)
- {
-#if HARD_LIMIT
- const bool exhausted = m_newPagesLeft.release ();
-
- if (exhausted)
- fatal_error ("the limit of memory allocations was reached");
-
-#endif
-
- void* storage = ::malloc (m_pageBytes);
-
- if (!storage)
- fatal_error ("a memory allocation failed");
-
- page = new (storage) Page (this);
-
-#if LOG_GC
- m_total.addref ();
-#endif
- }
-
-#if LOG_GC
- m_used.addref ();
-#endif
-
- return fromPage (page);
-}
-
-void PagedFreeStore::deallocate (void* const p)
-{
- Page* const page = toPage (p);
- PagedFreeStore& allocator = page->getAllocator ();
-
- allocator.m_hot->garbage->push_front (page);
-
-#if LOG_GC
- allocator.m_used.release ();
-#endif
-}
-
-//
-// Perform garbage collection.
-//
-void PagedFreeStore::onDeadlineTimer (DeadlineTimer&)
-{
- // Physically free one page.
- // This will reduce the working set over time after a spike.
- {
- Page* page = m_cold->garbage->pop_front ();
-
- if (page)
- {
- page->~Page ();
- ::free (page);
- m_newPagesLeft.addref ();
-#ifdef LOG_GC
- m_total.release ();
-#endif
- }
- }
-
- std::swap (m_cold->fresh, m_cold->garbage);
-
- // Swap atomically with respect to m_hot
- Pool* temp = m_hot;
- m_hot = m_cold; // atomic
- m_cold = temp;
-
-#if LOG_GC
- String s;
- s << "swap " << String (++m_swaps);
- s << " (" << String (m_used.get ()) << "/"
- << String (m_total.get ()) << " of "
- << String (m_newPagesLeft.get ()) << ")";
- Logger::outputDebugString (s);
-#endif
-
- m_timer.setExpiration (1.0);
-}
-
-void PagedFreeStore::dispose (Pages& pages)
-{
- for (;;)
- {
- Page* const page = pages.pop_front ();
-
- if (page)
- {
- page->~Page ();
- ::free (page);
-
-#if LOG_GC
- m_total.release ();
-#endif
- }
- else
- {
- break;
- }
- }
-}
-
-void PagedFreeStore::dispose (Pool& pool)
-{
- dispose (pool.fresh_c);
- dispose (pool.garbage_c);
-}
diff --git a/modules/beast_core/memory/PagedFreeStore.h b/modules/beast_core/memory/PagedFreeStore.h
deleted file mode 100644
index bcad772c..00000000
--- a/modules/beast_core/memory/PagedFreeStore.h
+++ /dev/null
@@ -1,102 +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.
-*/
-//==============================================================================
-
-#ifndef BEAST_PAGEDFREESTORE_H_INCLUDED
-#define BEAST_PAGEDFREESTORE_H_INCLUDED
-
-/*============================================================================*/
-/**
- Lock-free memory allocator for fixed size pages.
-
- The ABA problem (http://en.wikipedia.org/wiki/ABA_problem) is avoided by
- treating freed pages as garbage, and performing a collection every second.
-
- @ingroup beast_concurrent
-*/
-class BEAST_API PagedFreeStore : private DeadlineTimer::Listener
-{
-public:
- explicit PagedFreeStore (const size_t pageBytes);
- ~PagedFreeStore ();
-
- // The available bytes per page is a little bit less
- // than requested in the constructor, due to overhead.
- //
- inline size_t getPageBytes () const
- {
- return m_pageBytesAvailable;
- }
-
- inline void* allocate (const size_t bytes)
- {
- if (bytes > m_pageBytes)
- fatal_error ("the size is too large");
-
- return allocate ();
- }
-
- void* allocate ();
- static void deallocate (void* const p);
-
-private:
- void* newPage ();
- void onDeadlineTimer (DeadlineTimer&);
-
-private:
- struct Page;
- typedef LockFreeStack Pages;
-
- struct Pool
- {
- Pool()
- : fresh (&fresh_c.get())
- , garbage (&garbage_c.get())
- {
- }
-
- Pages* fresh;
- Pages* garbage;
- CacheLine::Padded fresh_c;
- CacheLine::Padded garbage_c;
- };
-
- static inline void* fromPage (Page* const p);
- static inline Page* toPage (void* const p);
-
- void dispose (Pages& pages);
- void dispose (Pool& pool);
-
-private:
- DeadlineTimer m_timer;
- const size_t m_pageBytes;
- const size_t m_pageBytesAvailable;
- CacheLine::Aligned m_pool1; // pair of pools
- CacheLine::Aligned m_pool2;
- Pool* volatile m_cold; // pool which is cooling down
- Pool* volatile m_hot; // pool we are currently using
- AtomicCounter m_newPagesLeft; // limit of system allocations
-
-#if 1
- int m_swaps;
- AtomicCounter m_total;
- AtomicCounter m_used;
-#endif
-};
-
-#endif
diff --git a/modules/beast_core/memory/StaticObject.h b/modules/beast_core/memory/StaticObject.h
index 29f16d9e..8b0d5a93 100644
--- a/modules/beast_core/memory/StaticObject.h
+++ b/modules/beast_core/memory/StaticObject.h
@@ -20,18 +20,6 @@
#ifndef BEAST_STATICOBJECT_H_INCLUDED
#define BEAST_STATICOBJECT_H_INCLUDED
-//
-// A full suite of thread-safe objects designed for static storage duration.
-//
-// Wraps an object with a thread-safe initialization preamble so that it can
-// properly exist with static storage duration.
-//
-// Implementation notes:
-//
-// This is accomplished by omitting the constructor and relying on the C++
-// specification that plain data types with static storage duration are filled
-// with zeroes before any other initialization code executes.
-//
// Spec: N2914=09-0104
//
// [3.6.2] Initialization of non-local objects
@@ -40,84 +28,8 @@
// duration (3.7.2) shall be zero-initialized (8.5) before any
// other initialization takes place.
//
-// Requirements:
-//
-// Object must be constructible without parameters.
-// The StaticObject must be declared with static storage duration or
-// the behavior is undefined.
-//
-// Usage example:
-//
-// Object* getInstance ()
-// {
-// static StaticObject