Migrate some headers and general tidying

This commit is contained in:
Vinnie Falco
2013-09-21 16:37:09 -07:00
parent 1a3cddc002
commit 9d9c822efb
30 changed files with 262 additions and 391 deletions

View File

@@ -69,12 +69,17 @@
<None Include="..\..\README.md" /> <None Include="..\..\README.md" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\beast\Atomic.h" />
<ClInclude Include="..\..\beast\Config.h" /> <ClInclude Include="..\..\beast\Config.h" />
<ClInclude Include="..\..\beast\CStdInt.h" /> <ClInclude Include="..\..\beast\CStdInt.h" />
<ClInclude Include="..\..\beast\Intrusive.h" />
<ClInclude Include="..\..\beast\intrusive\ForwardList.h" /> <ClInclude Include="..\..\beast\intrusive\ForwardList.h" />
<ClInclude Include="..\..\beast\intrusive\List.h" />
<ClInclude Include="..\..\beast\intrusive\LockFreeStack.h" />
<ClInclude Include="..\..\beast\intrusive\PointerTraits.h" /> <ClInclude Include="..\..\beast\intrusive\PointerTraits.h" />
<ClInclude Include="..\..\beast\MPL.h" /> <ClInclude Include="..\..\beast\MPL.h" />
<ClInclude Include="..\..\beast\mpl\AddConst.h" /> <ClInclude Include="..\..\beast\mpl\AddConst.h" />
<ClInclude Include="..\..\beast\mpl\CopyConst.h" />
<ClInclude Include="..\..\beast\mpl\IfCond.h" /> <ClInclude Include="..\..\beast\mpl\IfCond.h" />
<ClInclude Include="..\..\beast\mpl\IsCallPossible.h" /> <ClInclude Include="..\..\beast\mpl\IsCallPossible.h" />
<ClInclude Include="..\..\beast\mpl\PointerToOther.h" /> <ClInclude Include="..\..\beast\mpl\PointerToOther.h" />
@@ -155,14 +160,10 @@
<ClInclude Include="..\..\modules\beast_core\containers\ArrayAllocationBase.h" /> <ClInclude Include="..\..\modules\beast_core\containers\ArrayAllocationBase.h" />
<ClInclude Include="..\..\modules\beast_core\containers\DynamicObject.h" /> <ClInclude Include="..\..\modules\beast_core\containers\DynamicObject.h" />
<ClInclude Include="..\..\modules\beast_core\containers\ElementComparator.h" /> <ClInclude Include="..\..\modules\beast_core\containers\ElementComparator.h" />
<ClInclude Include="..\..\modules\beast_core\containers\detail\copyconst.h" />
<ClInclude Include="..\..\modules\beast_core\containers\detail\removecv.h" />
<ClInclude Include="..\..\modules\beast_core\containers\DynamicArray.h" /> <ClInclude Include="..\..\modules\beast_core\containers\DynamicArray.h" />
<ClInclude Include="..\..\modules\beast_core\containers\HashMap.h" /> <ClInclude Include="..\..\modules\beast_core\containers\HashMap.h" />
<ClInclude Include="..\..\modules\beast_core\containers\LinkedListPointer.h" /> <ClInclude Include="..\..\modules\beast_core\containers\LinkedListPointer.h" />
<ClInclude Include="..\..\modules\beast_core\containers\List.h" />
<ClInclude Include="..\..\modules\beast_core\containers\LockFreeQueue.h" /> <ClInclude Include="..\..\modules\beast_core\containers\LockFreeQueue.h" />
<ClInclude Include="..\..\modules\beast_core\containers\LockFreeStack.h" />
<ClInclude Include="..\..\modules\beast_core\containers\NamedValueSet.h" /> <ClInclude Include="..\..\modules\beast_core\containers\NamedValueSet.h" />
<ClInclude Include="..\..\modules\beast_core\containers\OwnedArray.h" /> <ClInclude Include="..\..\modules\beast_core\containers\OwnedArray.h" />
<ClInclude Include="..\..\modules\beast_core\containers\PropertySet.h" /> <ClInclude Include="..\..\modules\beast_core\containers\PropertySet.h" />
@@ -208,7 +209,6 @@
<ClInclude Include="..\..\modules\beast_core\maths\Range.h" /> <ClInclude Include="..\..\modules\beast_core\maths\Range.h" />
<ClInclude Include="..\..\modules\beast_core\maths\uint24.h" /> <ClInclude Include="..\..\modules\beast_core\maths\uint24.h" />
<ClInclude Include="..\..\modules\beast_core\memory\AllocatedBy.h" /> <ClInclude Include="..\..\modules\beast_core\memory\AllocatedBy.h" />
<ClInclude Include="..\..\modules\beast_core\memory\Atomic.h" />
<ClInclude Include="..\..\modules\beast_core\memory\AtomicCounter.h" /> <ClInclude Include="..\..\modules\beast_core\memory\AtomicCounter.h" />
<ClInclude Include="..\..\modules\beast_core\memory\AtomicFlag.h" /> <ClInclude Include="..\..\modules\beast_core\memory\AtomicFlag.h" />
<ClInclude Include="..\..\modules\beast_core\memory\AtomicPointer.h" /> <ClInclude Include="..\..\modules\beast_core\memory\AtomicPointer.h" />

View File

@@ -165,9 +165,6 @@
<Filter Include="beast_extras\traits"> <Filter Include="beast_extras\traits">
<UniqueIdentifier>{bf498396-2e1f-4903-be68-3053ba439af5}</UniqueIdentifier> <UniqueIdentifier>{bf498396-2e1f-4903-be68-3053ba439af5}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="beast_core\containers\detail">
<UniqueIdentifier>{08ec13ba-4058-4ad7-afbb-cbb1c6e2fc4a}</UniqueIdentifier>
</Filter>
<Filter Include="beast"> <Filter Include="beast">
<UniqueIdentifier>{92d1bb42-289a-4444-85c7-cb87540f2fff}</UniqueIdentifier> <UniqueIdentifier>{92d1bb42-289a-4444-85c7-cb87540f2fff}</UniqueIdentifier>
</Filter> </Filter>
@@ -296,9 +293,6 @@
<ClInclude Include="..\..\modules\beast_core\maths\Range.h"> <ClInclude Include="..\..\modules\beast_core\maths\Range.h">
<Filter>beast_core\maths</Filter> <Filter>beast_core\maths</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\Atomic.h">
<Filter>beast_core\memory</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\ByteOrder.h"> <ClInclude Include="..\..\modules\beast_core\memory\ByteOrder.h">
<Filter>beast_core\memory</Filter> <Filter>beast_core\memory</Filter>
</ClInclude> </ClInclude>
@@ -549,9 +543,6 @@
<ClInclude Include="..\..\modules\beast_core\containers\LockFreeQueue.h"> <ClInclude Include="..\..\modules\beast_core\containers\LockFreeQueue.h">
<Filter>beast_core\containers</Filter> <Filter>beast_core\containers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\containers\LockFreeStack.h">
<Filter>beast_core\containers</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\threads\SpinDelay.h"> <ClInclude Include="..\..\modules\beast_core\threads\SpinDelay.h">
<Filter>beast_core\threads</Filter> <Filter>beast_core\threads</Filter>
</ClInclude> </ClInclude>
@@ -822,15 +813,6 @@
<ClInclude Include="..\..\modules\beast_core\containers\HashMap.h"> <ClInclude Include="..\..\modules\beast_core\containers\HashMap.h">
<Filter>beast_core\containers</Filter> <Filter>beast_core\containers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\containers\List.h">
<Filter>beast_core\containers</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\containers\detail\copyconst.h">
<Filter>beast_core\containers\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\containers\detail\removecv.h">
<Filter>beast_core\containers\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\text\StringCharPointerType.h"> <ClInclude Include="..\..\modules\beast_core\text\StringCharPointerType.h">
<Filter>beast_core\text</Filter> <Filter>beast_core\text</Filter>
</ClInclude> </ClInclude>
@@ -1104,6 +1086,21 @@
<ClInclude Include="..\..\modules\beast_asio\basics\SharedArg.h"> <ClInclude Include="..\..\modules\beast_asio\basics\SharedArg.h">
<Filter>beast_asio\basics</Filter> <Filter>beast_asio\basics</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\beast\Intrusive.h">
<Filter>beast</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\Atomic.h">
<Filter>beast</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\intrusive\LockFreeStack.h">
<Filter>beast\intrusive</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\intrusive\List.h">
<Filter>beast\intrusive</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\mpl\CopyConst.h">
<Filter>beast\mpl</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp"> <ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">

View File

@@ -24,6 +24,7 @@
#ifndef BEAST_ATOMIC_H_INCLUDED #ifndef BEAST_ATOMIC_H_INCLUDED
#define BEAST_ATOMIC_H_INCLUDED #define BEAST_ATOMIC_H_INCLUDED
namespace beast {
//============================================================================== //==============================================================================
/** /**
@@ -385,5 +386,6 @@ inline void memoryBarrier() noexcept
#pragma warning (pop) #pragma warning (pop)
#endif #endif
#endif }
#endif

View File

@@ -17,57 +17,11 @@
*/ */
//============================================================================== //==============================================================================
#ifndef BEAST_CORE_CONTAINERS_DETAIL_REMOVECV_H_INCLUDED #ifndef BEAST_INTRUSIVE_H_INCLUDED
#define BEAST_CORE_CONTAINERS_DETAIL_REMOVECV_H_INCLUDED #define BEAST_INTRUSIVE_H_INCLUDED
namespace detail #include "intrusive/ForwardList.h"
{ #include "intrusive/List.h"
#include "intrusive/LockFreeStack.h"
// Strip all cv qualifiers from T
template <typename T>
struct removecv
{
typedef T type;
};
template <typename T>
struct removecv <const T>
{
typedef typename removecv <T>::type type;
};
template <typename T>
struct removecv <volatile T>
{
typedef typename removecv <T>::type type;
};
template <typename T>
struct removecv <const volatile T>
{
typedef typename removecv <T>::type type;
};
template <typename T>
struct removecv <T*>
{
typedef typename removecv <T>::type type;
};
template <typename T>
struct removecv <T&>
{
typedef typename removecv <T>::type type;
};
#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS
template <typename T>
struct removecv <T&&>
{
typedef typename removecv <T>::type type;
};
#endif
}
#endif #endif

View File

@@ -21,6 +21,7 @@
#define BEAST_MPL_H_INCLUDED #define BEAST_MPL_H_INCLUDED
#include "mpl/AddConst.h" #include "mpl/AddConst.h"
#include "mpl/CopyConst.h"
#include "mpl/IfCond.h" #include "mpl/IfCond.h"
#include "mpl/IsCallPossible.h" #include "mpl/IsCallPossible.h"
#include "mpl/PointerToOther.h" #include "mpl/PointerToOther.h"

View File

@@ -21,7 +21,6 @@
#define BEAST_INTRUSIVE_FORWARDLIST_H_INCLUDED #define BEAST_INTRUSIVE_FORWARDLIST_H_INCLUDED
#include <iterator> #include <iterator>
#include "PointerTraits.h" #include "PointerTraits.h"
#include "../MPL.h" #include "../MPL.h"

View File

@@ -17,8 +17,14 @@
*/ */
//============================================================================== //==============================================================================
#ifndef BEAST_CORE_CONTAINERS_LIST_H_INCLUDED #ifndef BEAST_INTRUSIVE_LIST_H_INCLUDED
#define BEAST_CORE_CONTAINERS_LIST_H_INCLUDED #define BEAST_INTRUSIVE_LIST_H_INCLUDED
#include <iterator>
#include "../mpl/CopyConst.h"
#include "../Uncopyable.h"
namespace beast {
/** Intrusive Containers /** Intrusive Containers
@@ -225,8 +231,7 @@ class ListIterator : public std::iterator <
std::bidirectional_iterator_tag, std::size_t> std::bidirectional_iterator_tag, std::size_t>
{ {
public: public:
typedef typename copyconst <N, typename N::value_type>::type typedef typename mpl::CopyConst<N, typename N::value_type>::type
value_type; value_type;
typedef value_type* pointer; typedef value_type* pointer;
typedef value_type& reference; typedef value_type& reference;
@@ -243,14 +248,6 @@ public:
{ {
} }
#if 0
template <typename M>
ListIterator& operator= (ListIterator <M> const& other) noexcept
{
m_node = other.m_node;
return *this;
}
#endif
template <typename M> template <typename M>
bool operator== (ListIterator <M> const& other) const noexcept bool operator== (ListIterator <M> const& other) const noexcept
{ {
@@ -307,14 +304,11 @@ private:
void increment () noexcept void increment () noexcept
{ {
bassert (m_node->m_next);
m_node = m_node->m_next; m_node = m_node->m_next;
} }
void decrement () noexcept void decrement () noexcept
{ {
bassert (m_node->m_prev &&
m_node->m_prev->m_prev != nullptr);
m_node = m_node->m_prev; m_node = m_node->m_prev;
} }
@@ -323,8 +317,7 @@ private:
} }
/** /** Intrusive doubly linked list.
Intrusive doubly linked list.
This intrusive List is a container similar in operation to std::list in the This intrusive List is a container similar in operation to std::list in the
Standard Template Library (STL). Like all @ref intrusive containers, List Standard Template Library (STL). Like all @ref intrusive containers, List
@@ -583,7 +576,6 @@ public:
@param pos The location to insert after. @param pos The location to insert after.
@param other The list to insert. @param other The list to insert.
*/ */
void insert (iterator pos, List& other) noexcept void insert (iterator pos, List& other) noexcept
{ {
if (!other.empty ()) if (!other.empty ())
@@ -717,4 +709,6 @@ private:
Node m_tail; Node m_tail;
}; };
}
#endif #endif

View File

@@ -17,12 +17,17 @@
*/ */
//============================================================================== //==============================================================================
#ifndef BEAST_LOCKFREESTACK_H_INCLUDED #ifndef BEAST_INTRUSIVE_LOCKFREESTACK_H_INCLUDED
#define BEAST_LOCKFREESTACK_H_INCLUDED #define BEAST_INTRUSIVE_LOCKFREESTACK_H_INCLUDED
struct LockFreeStackDefaultTag; #include <iterator>
#include "../mpl/IfCond.h"
#include "../Atomic.h"
#include "../Uncopyable.h"
/*============================================================================*/ namespace beast {
//------------------------------------------------------------------------------
template <class Container, bool IsConst> template <class Container, bool IsConst>
class LockFreeStackIterator class LockFreeStackIterator
@@ -74,7 +79,7 @@ public:
LockFreeStackIterator& operator++ () LockFreeStackIterator& operator++ ()
{ {
m_node = m_node->m_next; m_node = m_node->m_next.get();
return static_cast <LockFreeStackIterator&> (*this); return static_cast <LockFreeStackIterator&> (*this);
} }
@@ -85,16 +90,9 @@ public:
return result; return result;
} }
template <bool OtherIsConst> NodePtr node() const
bool operator== (LockFreeStackIterator <Container, OtherIsConst> const& other)
{ {
return m_node == other.m_node; return m_node;
}
template <bool OtherIsConst>
bool operator!= (LockFreeStackIterator <Container, OtherIsConst> const& other)
{
return m_node != other.m_node;
} }
reference operator* () const reference operator* () const
@@ -111,20 +109,35 @@ private:
NodePtr m_node; NodePtr m_node;
}; };
/** //------------------------------------------------------------------------------
Multiple Producer, Multiple Consumer (MPMC) intrusive stack.
This stack is implemented using the same intrusive interface as List. All template <class Container, bool LhsIsConst, bool RhsIsConst>
operations are lock-free. bool operator== (LockFreeStackIterator <Container, LhsIsConst> const& lhs,
LockFreeStackIterator <Container, RhsIsConst> const& rhs)
{
return lhs.node() == rhs.node();
}
The caller is responsible for preventing the "ABA" problem template <class Container, bool LhsIsConst, bool RhsIsConst>
(http://en.wikipedia.org/wiki/ABA_problem) bool operator!= (LockFreeStackIterator <Container, LhsIsConst> const& lhs,
LockFreeStackIterator <Container, RhsIsConst> const& rhs)
{
return lhs.node() != rhs.node();
}
//------------------------------------------------------------------------------
/** Multiple Producer, Multiple Consumer (MPMC) intrusive stack.
This stack is implemented using the same intrusive interface as List.
All mutations are lock-free.
The caller is responsible for preventing the "ABA" problem:
http://en.wikipedia.org/wiki/ABA_problem
@param Tag A type name used to distinguish lists and nodes, for @param Tag A type name used to distinguish lists and nodes, for
putting objects in multiple lists. If this parameter is putting objects in multiple lists. If this parameter is
omitted, the default tag is used. omitted, the default tag is used.
@ingroup beast_core intrusive
*/ */
template <class Element, class Tag = void> template <class Element, class Tag = void>
class LockFreeStack : public Uncopyable class LockFreeStack : public Uncopyable
@@ -147,8 +160,7 @@ public:
template <class Container, bool IsConst> template <class Container, bool IsConst>
friend class LockFreeStackIterator; friend class LockFreeStackIterator;
// VFALCO TODO Use regular Atomic<> Atomic <Node*> m_next;
AtomicPointer <Node> m_next;
}; };
public: public:
@@ -164,36 +176,15 @@ public:
typedef LockFreeStackIterator < typedef LockFreeStackIterator <
LockFreeStack <Element, Tag>, true> const_iterator; LockFreeStack <Element, Tag>, true> const_iterator;
LockFreeStack () : m_head (nullptr) LockFreeStack ()
: m_end (nullptr)
, m_head (&m_end)
{ {
} }
#if 0
/** Create a LockFreeStack from another stack.
The contents of the other stack are atomically acquired.
The other stack is cleared.
@param other The other stack to acquire.
*/
explicit LockFreeStack (LockFreeStack& other)
{
Node* head;
do
{
head = other.m_head.get ();
}
while (!other.m_head.compareAndSet (0, head));
m_head = head;
}
#endif
/** Return the number of elements in the stack. /** Return the number of elements in the stack.
Thread safety: Thread safety:
Safe to call from any thread but the value may be inaccurate. Safe to call from any thread.
*/ */
size_type size () const size_type size () const
{ {
@@ -201,77 +192,63 @@ public:
} }
/** Push a node onto the stack. /** Push a node onto the stack.
The caller is responsible for preventing the ABA problem.
The caller is responsible for preventing the ABA problem. This operation This operation is lock-free.
is lock-free. Thread safety:
Safe to call from any thread.
@param node The node to push. @param node The node to push.
@return True if the stack was previously empty. If multiple threads @return `true` if the stack was previously empty. If multiple threads
are attempting to push, only one will receive true. are attempting to push, only one will receive `true`.
*/ */
bool push_front (Node* node) bool push_front (Node* node)
{ {
bool first; bool first;
Node* head; Node* head;
do do
{ {
head = m_head.get (); head = m_head.get ();
first = head == 0; first = head == &m_end;
node->m_next = head; node->m_next = head;
} }
while (!m_head.compareAndSet (node, head)); while (!m_head.compareAndSetBool (node, head));
++m_size; ++m_size;
return first; return first;
} }
/** Pop an element off the stack. /** Pop an element off the stack.
The caller is responsible for preventing the ABA problem.
This operation is lock-free.
Thread safety:
Safe to call from any thread.
The caller is responsible for preventing the ABA problem. This operation @return The element that was popped, or `nullptr` if the stack
is lock-free. was empty.
@return The element that was popped, or nullptr if the stack was empty.
*/ */
Element* pop_front () Element* pop_front ()
{ {
Node* node; Node* node;
Node* head; Node* head;
do do
{ {
node = m_head.get (); node = m_head.get ();
if (node == &m_end)
if (node == 0) return nullptr;
break;
head = node->m_next.get (); head = node->m_next.get ();
} }
while (!m_head.compareAndSet (head, node)); while (!m_head.compareAndSetBool (head, node));
--m_size; --m_size;
return static_cast <Element*> (node);
return node ? static_cast <Element*> (node) : nullptr;
} }
/** Swap the contents of this stack with another stack. /** Return a forward iterator to the beginning or end of the stack.
Undefined behavior results if push_front or pop_front is called
This call is not thread safe or atomic. The caller is responsible for while an iteration is in progress.
synchronizing access. Thread safety:
Caller is responsible for synchronization.
@param other The other stack to swap contents with.
*/ */
void swap (LockFreeStack& other) /** @{ */
{
Node* temp = other.m_head.get ();
other.m_head.set (m_head.get ());
m_head.set (temp);
std::swap (m_size.value, other.m_size.value);
}
iterator begin () iterator begin ()
{ {
return iterator (m_head.get ()); return iterator (m_head.get ());
@@ -279,7 +256,7 @@ public:
iterator end () iterator end ()
{ {
return iterator (); return iterator (&m_end);
} }
const_iterator begin () const const_iterator begin () const
@@ -289,7 +266,7 @@ public:
const_iterator end () const const_iterator end () const
{ {
return const_iterator (); return const_iterator (&m_end);
} }
const_iterator cbegin () const const_iterator cbegin () const
@@ -299,12 +276,16 @@ public:
const_iterator cend () const const_iterator cend () const
{ {
return const_iterator (); return const_iterator (&m_end);
} }
/** @} */
private: private:
Node m_end;
Atomic <size_type> m_size; Atomic <size_type> m_size;
AtomicPointer <Node> m_head; Atomic <Node*> m_head;
}; };
}
#endif #endif

View File

@@ -20,16 +20,18 @@
#ifndef BEAST_MPL_ADDCONST_H_INCLUDED #ifndef BEAST_MPL_ADDCONST_H_INCLUDED
#define BEAST_MPL_ADDCONST_H_INCLUDED #define BEAST_MPL_ADDCONST_H_INCLUDED
#include "RemoveConst.h"
// Ideas based on boost // Ideas based on boost
namespace beast { namespace beast {
namespace mpl { namespace mpl {
/// Add the `const` qualifier to a type. /** Add the `const` qualifier to a type. */
template <typename T> template <typename T>
struct AddConst struct AddConst
{ {
typedef T const type; typedef typename RemoveConst<T>::type const type;
}; };
} }

View File

@@ -17,25 +17,30 @@
*/ */
//============================================================================== //==============================================================================
#ifndef BEAST_CORE_CONTAINERS_DETAIL_COPYCONST_H_INCLUDED #ifndef BEAST_MPL_COPYCONST_H_INCLUDED
#define BEAST_CORE_CONTAINERS_DETAIL_COPYCONST_H_INCLUDED #define BEAST_MPL_COPYCONST_H_INCLUDED
namespace detail #include "RemoveConst.h"
{
// Copy const attribute from T to U if present namespace beast {
namespace mpl {
/** Copy `const` attribute from T to U if present. */
/** @{ */
template <typename T, typename U> template <typename T, typename U>
struct copyconst struct CopyConst
{ {
typedef typename removecv <U>::type type; typedef typename RemoveConst<U>::type type;
}; };
template <typename T, typename U> template <typename T, typename U>
struct copyconst <T const, U> struct CopyConst <T const, U>
{ {
typedef typename removecv <U>::type const type; typedef typename RemoveConst<U>::type const type;
}; };
/** @} */
}
} }
#endif #endif

View File

@@ -25,8 +25,8 @@ namespace mpl {
// Ideas based on boost // Ideas based on boost
/// Select between T1 or T2 depending on Condition. /** Select between T1 or T2 depending on Condition. */
/// @{ /** @{ */
template <bool Condition, typename T1, typename T2> template <bool Condition, typename T1, typename T2>
struct IfCond struct IfCond
{ {
@@ -38,7 +38,7 @@ struct IfCond <false, T1, T2>
{ {
typedef T2 type; typedef T2 type;
}; };
/// @} /** @} */
} }
} }

View File

@@ -30,7 +30,7 @@ namespace mpl {
parameters. More specializations can be added for containers with parameters. More specializations can be added for containers with
more than three template parameters. more than three template parameters.
*/ */
/// @{ /** @{ */
template <class T, class U> template <class T, class U>
struct PointerToOther; struct PointerToOther;
@@ -60,7 +60,7 @@ struct PointerToOther <T*, U>
{ {
typedef U* type; typedef U* type;
}; };
/// @} /** @} */
} }
} }

View File

@@ -25,8 +25,8 @@
namespace beast { namespace beast {
namespace mpl { namespace mpl {
/// Remove the `const` qualifier from a type. /** Remove the `const` qualifier from a type. */
/// @{ /** @{ */
template <typename T> template <typename T>
struct RemoveConst struct RemoveConst
{ {
@@ -38,7 +38,7 @@ struct RemoveConst <T const>
{ {
typedef T type; typedef T type;
}; };
/// @} /** @} */
} }
} }

View File

@@ -28,7 +28,7 @@
namespace beast { namespace beast {
namespace mpl { namespace mpl {
/// Remove both the `const` and `volatile` qualifiers from a type. /** Remove both the `const` and `volatile` qualifiers from a type. */
template <typename T> template <typename T>
struct RemoveConstVolatile struct RemoveConstVolatile
{ {

View File

@@ -25,8 +25,8 @@ namespace mpl {
// Ideas based on boost // Ideas based on boost
/// Remove the reference qualifier from a type. /** Remove the reference qualifier from a type. */
/// @{ /** @{ */
template <class T> template <class T>
struct RemoveReference struct RemoveReference
{ {
@@ -38,7 +38,7 @@ struct RemoveReference <T&>
{ {
typedef T type; typedef T type;
}; };
/// @} /** @} */
} }
} }

View File

@@ -25,8 +25,8 @@
namespace beast { namespace beast {
namespace mpl { namespace mpl {
/// Remove the `volatile` qualifier from a type. /** Remove the `volatile` qualifier from a type. */
/// @{ /** @{ */
template <typename T> template <typename T>
struct RemoveVolatile struct RemoveVolatile
{ {
@@ -38,7 +38,7 @@ struct RemoveVolatile <T volatile>
{ {
typedef T type; typedef T type;
}; };
/// @} /** @} */
} }
} }

View File

@@ -120,8 +120,6 @@ public:
template <typename IntegralType> template <typename IntegralType>
Proxy& operator= (IntegralType v) Proxy& operator= (IntegralType v)
{ {
bassert (v >= 0 && v <= 255);
(*m_value)= (*m_value)=
(*m_value)&(!((0xff)<<m_shift)) | (*m_value)&(!((0xff)<<m_shift)) |
((v&0xff)<<m_shift); ((v&0xff)<<m_shift);

View File

@@ -20,8 +20,7 @@
#ifndef BEAST_TYPE_TRAITS_INTEGRALCONSTANT_H_INCLUDED #ifndef BEAST_TYPE_TRAITS_INTEGRALCONSTANT_H_INCLUDED
#define BEAST_TYPE_TRAITS_INTEGRALCONSTANT_H_INCLUDED #define BEAST_TYPE_TRAITS_INTEGRALCONSTANT_H_INCLUDED
namespace beast namespace beast {
{
// ideas from boost // ideas from boost

View File

@@ -22,10 +22,7 @@
#include "IntegralConstant.h" #include "IntegralConstant.h"
namespace beast namespace beast {
{
namespace detail
template <typename T> struct IsIntegral : FalseType { }; template <typename T> struct IsIntegral : FalseType { };

View File

@@ -22,8 +22,7 @@
#include "IntegralConstant.h" #include "IntegralConstant.h"
namespace beast namespace beast {
{
template <typename T> struct IsSigned : FalseType { }; template <typename T> struct IsSigned : FalseType { };

View File

@@ -22,8 +22,7 @@
#include "IntegralConstant.h" #include "IntegralConstant.h"
namespace beast namespace beast {
{
/** Returns an equally sized, unsigned type. /** Returns an equally sized, unsigned type.
Requires: Requires:
@@ -33,12 +32,12 @@ template <typename T>
struct RemoveSigned struct RemoveSigned
{ {
typedef T type; typedef T type;
} };
template <> struct RemoveSigned <int8> { typedef uint8 type; } template <> struct RemoveSigned <int8> { typedef uint8 type; };
template <> struct RemoveSigned <int16> { typedef uint16 type; } template <> struct RemoveSigned <int16> { typedef uint16 type; };
template <> struct RemoveSigned <int32> { typedef uint32 type; } template <> struct RemoveSigned <int32> { typedef uint32 type; };
template <> struct RemoveSigned <int64> { typedef uint64 type; } template <> struct RemoveSigned <int64> { typedef uint64 type; };
} }

View File

@@ -76,21 +76,28 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace beast {
extern BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger();
extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) noexcept;
}
// New header-only library modeled more closely according to boost
#include "../../beast/CStdInt.h" #include "../../beast/CStdInt.h"
#include "../../beast/StaticAssert.h" #include "../../beast/StaticAssert.h"
#include "../../beast/Uncopyable.h" #include "../../beast/Uncopyable.h"
#include "../../beast/Atomic.h"
#include "../../beast/Intrusive.h"
#include "../../beast/Net.h"
#include "../../beast/TypeTraits.h"
#include "../../beast/Thread.h"
namespace beast namespace beast {
{
class InputStream; class InputStream;
class OutputStream; class OutputStream;
class FileInputStream; class FileInputStream;
class FileOutputStream; class FileOutputStream;
extern BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger();
extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) noexcept;
// Order matters, since headers don't have their own #include lines. // Order matters, since headers don't have their own #include lines.
// Add new includes to the bottom. // Add new includes to the bottom.
@@ -98,23 +105,8 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n
#include "memory/Memory.h" #include "memory/Memory.h"
#include "maths/MathsFunctions.h" #include "maths/MathsFunctions.h"
#include "memory/ByteOrder.h" #include "memory/ByteOrder.h"
#include "memory/Atomic.h"
#include "text/CharacterFunctions.h" #include "text/CharacterFunctions.h"
}
//------------------------------------------------------------------------------
// New header-only library modeled more closely according to boost
#include "../../beast/intrusive/ForwardList.h"
#include "../../beast/Net.h"
#include "../../beast/Thread.h"
//------------------------------------------------------------------------------
namespace beast
{
#if BEAST_MSVC #if BEAST_MSVC
# pragma warning (push) # pragma warning (push)
# pragma warning (disable: 4514 4996) # pragma warning (disable: 4514 4996)
@@ -127,16 +119,12 @@ namespace beast
# pragma warning (pop) # pragma warning (pop)
#endif #endif
# include "containers/detail/removecv.h"
#include "containers/detail/copyconst.h"
#include "diagnostic/Throw.h" #include "diagnostic/Throw.h"
#include "system/Functional.h" #include "system/Functional.h"
#include "memory/AtomicCounter.h" #include "memory/AtomicCounter.h"
#include "memory/AtomicFlag.h" #include "memory/AtomicFlag.h"
#include "memory/AtomicPointer.h" #include "memory/AtomicPointer.h"
#include "memory/AtomicState.h" #include "memory/AtomicState.h"
#include "containers/List.h"
#include "containers/LockFreeStack.h"
#include "threads/SpinDelay.h" #include "threads/SpinDelay.h"
#include "memory/StaticObject.h" #include "memory/StaticObject.h"

View File

@@ -32,7 +32,7 @@ class DynamicArrayIterator
typename V::size_type> typename V::size_type>
{ {
public: public:
typedef typename copyconst <V, typename V::value_type>::type typedef typename mpl::CopyConst <V, typename V::value_type>::type
value_type; value_type;
typedef value_type* pointer; typedef value_type* pointer;
@@ -216,7 +216,7 @@ class DynamicArrayReverseIterator
typename V::size_type> typename V::size_type>
{ {
public: public:
typedef typename copyconst <V, typename V::value_type>::type typedef typename mpl::CopyConst<V, typename V::value_type>::type
value_type; value_type;
typedef value_type* pointer; typedef value_type* pointer;

View File

@@ -193,9 +193,9 @@ class HashMapIterator
private: private:
typedef typename M::Item Item; typedef typename M::Item Item;
typedef typename M::Bucket Bucket; typedef typename M::Bucket Bucket;
typedef detail::ListIterator <typename detail::copyconst <M, typedef detail::ListIterator <typename mpl::CopyConst <M,
typename List <Bucket>::Node>::type> bucket_iterator; typename List <Bucket>::Node>::type> bucket_iterator;
typedef detail::ListIterator <typename detail::copyconst <M, typedef detail::ListIterator <typename mpl::CopyConst <M,
typename List <Item, detail::BucketTag>::Node>::type> item_iterator; typename List <Item, detail::BucketTag>::Node>::type> item_iterator;
public: public:

View File

@@ -17,14 +17,8 @@
*/ */
//============================================================================== //==============================================================================
#ifndef BEAST_LOCKFREEQUEUE_H_INCLUDED #ifndef BEAST_INTRUSIVE_LOCKFREEQUEUE_H_INCLUDED
#define BEAST_LOCKFREEQUEUE_H_INCLUDED #define BEAST_INTRUSIVE_LOCKFREEQUEUE_H_INCLUDED
/** Default tag for LockFreeQueue
@ingroup beast_core intrusive
*/
struct LockFreeQueueDefaultTag { };
/** Multiple Producer, Single Consumer (MPSC) intrusive FIFO. /** Multiple Producer, Single Consumer (MPSC) intrusive FIFO.
@@ -46,7 +40,7 @@ struct LockFreeQueueDefaultTag { };
@ingroup beast_core intrusive @ingroup beast_core intrusive
*/ */
template <class Element, class Tag = LockFreeQueueDefaultTag> template <class Element, class Tag = void>
class LockFreeQueue class LockFreeQueue
{ {
public: public:

View File

@@ -30,10 +30,7 @@ namespace CacheLine
#if GLOBAL_PADDING_ENABLED #if GLOBAL_PADDING_ENABLED
// Pads an object so that it starts on a cache line boundary.
//
/** Pad an object to start on a cache line boundary. /** Pad an object to start on a cache line boundary.
Up to 8 constructor parameters are passed through. Up to 8 constructor parameters are passed through.
*/ */
template <typename T> template <typename T>
@@ -42,80 +39,80 @@ class Aligned
public: public:
Aligned () Aligned ()
{ {
new (ptr ()) T; new (&get()) T;
} }
template <class T1> template <class T1>
Aligned (T1 t1) Aligned (T1 t1)
{ {
new (ptr ()) T (t1); new (&get()) T (t1);
} }
template <class T1, class T2> template <class T1, class T2>
Aligned (T1 t1, T2 t2) Aligned (T1 t1, T2 t2)
{ {
new (ptr ()) T (t1, t2); new (&get()) T (t1, t2);
} }
template <class T1, class T2, class T3> template <class T1, class T2, class T3>
Aligned (T1 t1, T2 t2, T3 t3) Aligned (T1 t1, T2 t2, T3 t3)
{ {
new (ptr ()) T (t1, t2, t3); new (&get()) T (t1, t2, t3);
} }
template <class T1, class T2, class T3, class T4> template <class T1, class T2, class T3, class T4>
Aligned (T1 t1, T2 t2, T3 t3, T4 t4) Aligned (T1 t1, T2 t2, T3 t3, T4 t4)
{ {
new (ptr ()) T (t1, t2, t3, t4); new (&get()) T (t1, t2, t3, t4);
} }
template <class T1, class T2, class T3, class T4, class T5> template <class T1, class T2, class T3, class T4, class T5>
Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{ {
new (ptr ()) T (t1, t2, t3, t4, t5); new (&get()) T (t1, t2, t3, t4, t5);
} }
template <class T1, class T2, class T3, class T4, class T5, class T6> template <class T1, class T2, class T3, class T4, class T5, class T6>
Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
{ {
new (ptr ()) T (t1, t2, t3, t4, t5, t6); new (&get()) T (t1, t2, t3, t4, t5, t6);
} }
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
{ {
new (ptr ()) T (t1, t2, t3, t4, t5, t6, t7); new (&get()) T (t1, t2, t3, t4, t5, t6, t7);
} }
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> template <class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) Aligned (T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
{ {
new (ptr ()) T (t1, t2, t3, t4, t5, t6, t7, t8); new (&get()) T (t1, t2, t3, t4, t5, t6, t7, t8);
} }
~Aligned () ~Aligned ()
{ {
ptr ()->~T (); get().~T ();
} }
T& operator= (T const& other) T& operator= (T const& other)
{ {
*ptr () = other; return (get() = other);
return *ptr ();
} }
inline T& operator* () noexcept { return *ptr (); } T& get () noexcept { return *ptr(); }
inline T* operator-> () noexcept { return ptr (); } T& operator* () noexcept { return get(); }
inline operator T& () noexcept { return *ptr (); } T* operator-> () noexcept { return &get(); }
inline operator T* () noexcept { return ptr (); } operator T& () noexcept { return get(); }
operator T* () noexcept { return &get(); }
inline const T& operator* () const noexcept { return *ptr (); } T const& get () const noexcept { return *ptr(); }
inline const T* operator-> () const noexcept { return ptr (); } const T& operator* () const noexcept { return get(); }
inline operator T const& () const noexcept { return *ptr (); } const T* operator-> () const noexcept { return &get(); }
inline operator T const* () const noexcept { return ptr (); } operator T const& () const noexcept { return get(); }
operator T const* () const noexcept { return &get(); }
private: private:
inline T* ptr () noexcept T* ptr () const noexcept
{ {
return (T*) ((uintptr_t (m_storage) + Memory::cacheLineAlignMask) return (T*) ((uintptr_t (m_storage) + Memory::cacheLineAlignMask)
& ~Memory::cacheLineAlignMask); & ~Memory::cacheLineAlignMask);
@@ -128,8 +125,9 @@ private:
char m_storage [ (sizeof (T) + Memory::cacheLineAlignMask) & ~Memory::cacheLineAlignMask]; char m_storage [ (sizeof (T) + Memory::cacheLineAlignMask) & ~Memory::cacheLineAlignMask];
}; };
/** End-pads an object to completely fill straddling CPU cache lines. //------------------------------------------------------------------------------
/** End-pads an object to completely fill straddling CPU cache lines.
The caller must ensure that this object starts at the beginning The caller must ensure that this object starts at the beginning
of a cache line. of a cache line.
*/ */
@@ -195,15 +193,16 @@ public:
return m_t; return m_t;
} }
T& operator* () noexcept { return m_t; } T& get() noexcept { return m_t;}
T* operator-> () noexcept { return &m_t; } T& operator* () noexcept { return get(); }
operator T& () noexcept { return m_t; } T* operator-> () noexcept { return &get(); }
operator T* () noexcept { return &m_t; } operator T& () noexcept { return get(); }
operator T* () noexcept { return &get(); }
const T& operator* () const noexcept { return m_t; } T const& get () const noexcept { return m_t; }
const T* operator-> () const noexcept { return &m_t; } const T& operator* () const noexcept { return get(); }
operator T const& () const noexcept { return m_t; } const T* operator-> () const noexcept { return &get(); }
operator T const* () const noexcept { return &m_t; } operator T const& () const noexcept { return get(); }
operator T const* () const noexcept { return &get(); }
private: private:
T m_t; T m_t;
@@ -257,32 +256,21 @@ public:
const T5& t5, const T6& t6, const T7& t7, const T8& t8) const T5& t5, const T6& t6, const T7& t7, const T8& t8)
: m_t (t1, t2, t3, t4, t5, t6, t7, t8) { } : m_t (t1, t2, t3, t4, t5, t6, t7, t8) { }
void operator= (const T& other) T& operator= (const T& other)
{ {
m_t = other; reutrn (m_t = other);
} }
T& operator* () noexcept { return m_t; } T& get () noexcept { return m_t; }
T* operator-> () noexcept { return &m_t; } T& operator* () noexcept { return get(); }
operator T& () noexcept { return m_t; } T* operator-> () noexcept { return &get(); }
operator T* () noexcept { return &m_t; } operator T& () noexcept { return get(); }
operator T* () noexcept { return &get(); }
const T& operator* () const noexcept T const& get () const noexcept { return m_t; }
{ const T& operator* () const noexcept { return get(); }
return m_t; const T* operator-> () const noexcept { return &get(); }
} operator T const& () const noexcept { return get(); }
const T* operator-> () const noexcept operator T const* () const noexcept { return &get(); }
{
return &m_t;
}
operator const T& () const noexcept
{
return m_t;
}
operator const T* () const noexcept
{
return &m_t;
}
private: private:
T m_t; T m_t;
@@ -338,27 +326,16 @@ public:
m_t = other; m_t = other;
} }
T& operator* () noexcept { return m_t; } T& get () noexcept { return m_t; }
T* operator-> () noexcept { return &m_t; } T& operator* () noexcept { return get(); }
operator T& () noexcept { return m_t; } T* operator-> () noexcept { return &get(); }
operator T* () noexcept { return &m_t; } operator T& () noexcept { return get(); }
operator T* () noexcept { return &get(); }
const T& operator* () const noexcept T const& get () const noexcept { return m_t; }
{ const T& operator* () const noexcept { return get(); }
return m_t; const T* operator-> () const noexcept { return &get(); }
} operator T const& () const noexcept { return get(); }
const T* operator-> () const noexcept operator T const* () const noexcept { return &get(); }
{
return &m_t;
}
operator const T& () const noexcept
{
return m_t;
}
operator const T* () const noexcept
{
return &m_t;
}
private: private:
T m_t; T m_t;
@@ -415,44 +392,21 @@ public:
const T5& t5, const T6& t6, const T7& t7, const T8& t8) const T5& t5, const T6& t6, const T7& t7, const T8& t8)
: m_t (t1, t2, t3, t4, t5, t6, t7, t8) { } : m_t (t1, t2, t3, t4, t5, t6, t7, t8) { }
void operator= (const T& other) T* operator= (const T& other)
{ {
m_t = other; return (m_t = other);
} }
T& operator* () T& get () noexcept { return m_t; }
{ T& operator* () noexcept { return get(); }
return m_t; T* operator-> () noexcept { return &get(); }
} operator T& () noexcept { return get(); }
T* operator-> () operator T* () noexcept { return &get(); }
{ T const& get () const noexcept { return m_t; }
return &m_t; const T& operator* () const noexcept { return get(); }
} const T* operator-> () const noexcept { return &get(); }
operator T& () operator T const& () const noexcept { return get(); }
{ operator T const* () const noexcept { return &get(); }
return m_t;
}
operator T* ()
{
return &m_t;
}
const T& operator* () const
{
return m_t;
}
const T* operator-> () const
{
return &m_t;
}
operator const T& () const
{
return m_t;
}
operator const T* () const
{
return &m_t;
}
private: private:
T m_t; T m_t;

View File

@@ -181,7 +181,7 @@ void PagedFreeStore::onDeadlineTimer (DeadlineTimer&)
} }
} }
m_cold->fresh->swap (m_cold->garbage); std::swap (m_cold->fresh, m_cold->garbage);
// Swap atomically with respect to m_hot // Swap atomically with respect to m_hot
Pool* temp = m_hot; Pool* temp = m_hot;
@@ -224,6 +224,6 @@ void PagedFreeStore::dispose (Pages& pages)
void PagedFreeStore::dispose (Pool& pool) void PagedFreeStore::dispose (Pool& pool)
{ {
dispose (pool.fresh); dispose (pool.fresh_c);
dispose (pool.garbage); dispose (pool.garbage_c);
} }

View File

@@ -64,8 +64,16 @@ private:
struct Pool struct Pool
{ {
CacheLine::Padded <Pages> fresh; Pool()
CacheLine::Padded <Pages> garbage; : fresh (&fresh_c.get())
, garbage (&garbage_c.get())
{
}
Pages* fresh;
Pages* garbage;
CacheLine::Padded <Pages> fresh_c;
CacheLine::Padded <Pages> garbage_c;
}; };
static inline void* fromPage (Page* const p); static inline void* fromPage (Page* const p);

View File

@@ -275,10 +275,10 @@ public:
}; };
} }
for (std::size_t i = 0; i < threads.size(); ++i) for (int i = 0; i < threads.size(); ++i)
threads[i]->stop (); threads[i]->stop ();
for (std::size_t i = 0; i < threads.size(); ++i) for (int i = 0; i < threads.size(); ++i)
threads[i]->waitForThreadToExit(); threads[i]->waitForThreadToExit();
double const secondsElapsed ((Time::getCurrentTime() - startTime).inSeconds ()); double const secondsElapsed ((Time::getCurrentTime() - startTime).inSeconds ());

View File

@@ -222,7 +222,7 @@ public:
{ {
} }
void testThreads (std::size_t nThreads) void testThreads (int nThreads)
{ {
beginTestCase (String::fromNumber (nThreads) + " threads"); beginTestCase (String::fromNumber (nThreads) + " threads");