From 8b6b73691884ea8817ec245b2efd6a81c1c6cf2b Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Mon, 26 Jan 2015 10:56:54 +0100 Subject: [PATCH] containers_cpp: revised template argument names --- containers_cpp/include/embb/containers/internal/lock_free_mpmc_queue-inl.h | 49 +++++++++++++++++++++++++------------------------ containers_cpp/include/embb/containers/internal/lock_free_stack-inl.h | 36 ++++++++++++++++++------------------ containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- containers_cpp/include/embb/containers/internal/object_pool-inl.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------- containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h | 22 +++++++++++----------- containers_cpp/include/embb/containers/internal/wait_free_spsc_queue-inl.h | 22 +++++++++++----------- containers_cpp/include/embb/containers/lock_free_mpmc_queue.h | 38 +++++++++++++++++++------------------- containers_cpp/include/embb/containers/lock_free_stack.h | 30 +++++++++++++++--------------- containers_cpp/include/embb/containers/lock_free_tree_value_pool.h | 22 +++++++++++----------- containers_cpp/include/embb/containers/object_pool.h | 30 +++++++++++++++--------------- containers_cpp/include/embb/containers/wait_free_array_value_pool.h | 32 ++++++++++++++++---------------- containers_cpp/include/embb/containers/wait_free_spsc_queue.h | 22 +++++++++++----------- 12 files changed, 254 insertions(+), 239 deletions(-) diff --git a/containers_cpp/include/embb/containers/internal/lock_free_mpmc_queue-inl.h b/containers_cpp/include/embb/containers/internal/lock_free_mpmc_queue-inl.h index e4fb9ae..5afd975 100644 --- a/containers_cpp/include/embb/containers/internal/lock_free_mpmc_queue-inl.h +++ b/containers_cpp/include/embb/containers/internal/lock_free_mpmc_queue-inl.h @@ -62,19 +62,19 @@ T LockFreeMPMCQueueNode::GetElement() { } } // namespace internal -template< typename T, typename ValuePool > -void LockFreeMPMCQueue:: -DeletePointerCallback(internal::LockFreeMPMCQueueNode* to_delete) { +template< typename Type, typename ValuePool > +void LockFreeMPMCQueue:: +DeletePointerCallback(internal::LockFreeMPMCQueueNode* to_delete) { objectPool.Free(to_delete); } -template< typename T, typename ValuePool > -LockFreeMPMCQueue::~LockFreeMPMCQueue() { +template< typename Type, typename ValuePool > +LockFreeMPMCQueue::~LockFreeMPMCQueue() { // Nothing to do here, did not allocate anything. } -template< typename T, typename ValuePool > -LockFreeMPMCQueue::LockFreeMPMCQueue(size_t capacity) : +template< typename Type, typename ValuePool > +LockFreeMPMCQueue::LockFreeMPMCQueue(size_t capacity) : capacity(capacity), // Disable "this is used in base member initializer" warning. // We explicitly want this. @@ -82,7 +82,8 @@ capacity(capacity), #pragma warning(push) #pragma warning(disable:4355) #endif - delete_pointer_callback(*this, &LockFreeMPMCQueue::DeletePointerCallback), +delete_pointer_callback(*this, + &LockFreeMPMCQueue::DeletePointerCallback), #ifdef _MSC_VER #pragma warning(pop) #endif @@ -94,26 +95,26 @@ capacity(capacity), embb::base::Thread::GetThreadsMaxCount() + capacity + 1) { // Allocate dummy node to reduce the number of special cases to consider. - internal::LockFreeMPMCQueueNode* dummyNode = objectPool.Allocate(); + internal::LockFreeMPMCQueueNode* dummyNode = objectPool.Allocate(); // Initially, head and tail point to the dummy node. head = dummyNode; tail = dummyNode; } -template< typename T, typename ValuePool > -size_t LockFreeMPMCQueue::GetCapacity() { +template< typename Type, typename ValuePool > +size_t LockFreeMPMCQueue::GetCapacity() { return capacity; } -template< typename T, typename ValuePool > -bool LockFreeMPMCQueue::TryEnqueue(T const& element) { +template< typename Type, typename ValuePool > +bool LockFreeMPMCQueue::TryEnqueue(Type const& element) { // Get node from the pool containing element to enqueue. - internal::LockFreeMPMCQueueNode* node = objectPool.Allocate(element); + internal::LockFreeMPMCQueueNode* node = objectPool.Allocate(element); // Queue full, cannot enqueue if (node == NULL) return false; - internal::LockFreeMPMCQueueNode* my_tail; + internal::LockFreeMPMCQueueNode* my_tail; for (;;) { my_tail = tail; @@ -124,14 +125,14 @@ bool LockFreeMPMCQueue::TryEnqueue(T const& element) { continue; // Hazard pointer outdated, retry } - internal::LockFreeMPMCQueueNode* my_tail_next = my_tail->GetNext(); + internal::LockFreeMPMCQueueNode* my_tail_next = my_tail->GetNext(); if (my_tail == tail) { // If the next pointer of the tail node is null, the tail pointer // points to the last object. We try to set the next pointer of the // tail node to our new node. if (my_tail_next == NULL) { - internal::LockFreeMPMCQueueNode* expected = NULL; + internal::LockFreeMPMCQueueNode* expected = NULL; // This fails if the next pointer of the "cached" tail is not null // anymore, i.e., another thread added a node before we could complete. if (my_tail->GetNext().CompareAndSwap(expected, node)) @@ -151,13 +152,13 @@ bool LockFreeMPMCQueue::TryEnqueue(T const& element) { return true; } -template< typename T, typename ValuePool > -bool LockFreeMPMCQueue::TryDequeue(T & element) { - internal::LockFreeMPMCQueueNode* my_head; - internal::LockFreeMPMCQueueNode* my_tail; - internal::LockFreeMPMCQueueNode* my_next; - internal::LockFreeMPMCQueueNode* expected; - T data; +template< typename Type, typename ValuePool > +bool LockFreeMPMCQueue::TryDequeue(Type & element) { + internal::LockFreeMPMCQueueNode* my_head; + internal::LockFreeMPMCQueueNode* my_tail; + internal::LockFreeMPMCQueueNode* my_next; + internal::LockFreeMPMCQueueNode* expected; + Type data; for (;;) { my_head = head; hazardPointer.GuardPointer(0, my_head); diff --git a/containers_cpp/include/embb/containers/internal/lock_free_stack-inl.h b/containers_cpp/include/embb/containers/internal/lock_free_stack-inl.h index 1317fdd..c03d7fb 100644 --- a/containers_cpp/include/embb/containers/internal/lock_free_stack-inl.h +++ b/containers_cpp/include/embb/containers/internal/lock_free_stack-inl.h @@ -59,14 +59,14 @@ namespace internal { } } // namespace internal -template< typename T, typename ValuePool > -void LockFreeStack< T, ValuePool >:: -DeletePointerCallback(internal::LockFreeStackNode* to_delete) { +template< typename Type, typename ValuePool > +void LockFreeStack< Type, ValuePool >:: +DeletePointerCallback(internal::LockFreeStackNode* to_delete) { objectPool.Free(to_delete); } -template< typename T, typename ValuePool > -LockFreeStack< T, ValuePool >::LockFreeStack(size_t capacity) : +template< typename Type, typename ValuePool > +LockFreeStack< Type, ValuePool >::LockFreeStack(size_t capacity) : capacity(capacity), // Disable "this is used in base member initializer" warning. // We explicitly want this. @@ -75,7 +75,7 @@ capacity(capacity), #pragma warning(disable:4355) #endif delete_pointer_callback(*this, - &LockFreeStack::DeletePointerCallback), + &LockFreeStack::DeletePointerCallback), #ifdef _MSC_VER #pragma warning(pop) #endif @@ -88,19 +88,19 @@ capacity(capacity), capacity) { } -template< typename T, typename ValuePool > -size_t LockFreeStack< T, ValuePool >::GetCapacity() { +template< typename Type, typename ValuePool > +size_t LockFreeStack< Type, ValuePool >::GetCapacity() { return capacity; } -template< typename T, typename ValuePool > -LockFreeStack< T, ValuePool >::~LockFreeStack() { +template< typename Type, typename ValuePool > +LockFreeStack< Type, ValuePool >::~LockFreeStack() { // Nothing to do here, did not allocate anything. } -template< typename T, typename ValuePool > -bool LockFreeStack< T, ValuePool >::TryPush(T const& element) { - internal::LockFreeStackNode* newNode = +template< typename Type, typename ValuePool > +bool LockFreeStack< Type, ValuePool >::TryPush(Type const& element) { + internal::LockFreeStackNode* newNode = objectPool.Allocate(element); // Stack full, cannot push @@ -108,16 +108,16 @@ bool LockFreeStack< T, ValuePool >::TryPush(T const& element) { return false; for (;;) { - internal::LockFreeStackNode* top_cached = top; + internal::LockFreeStackNode* top_cached = top; newNode->SetNext(top_cached); if (top.CompareAndSwap(top_cached, newNode)) return true; } } -template< typename T, typename ValuePool > -bool LockFreeStack< T, ValuePool >::TryPop(T & element) { - internal::LockFreeStackNode* top_cached = top; +template< typename Type, typename ValuePool > +bool LockFreeStack< Type, ValuePool >::TryPop(Type & element) { + internal::LockFreeStackNode* top_cached = top; for (;;) { top_cached = top; @@ -146,7 +146,7 @@ bool LockFreeStack< T, ValuePool >::TryPop(T & element) { } } - T data = top_cached->GetElement(); + Type data = top_cached->GetElement(); // We don't need to read from this reference anymore, unguard it hazardPointer.GuardPointer(0, NULL); diff --git a/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h b/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h index 3b44b15..2e50e3b 100644 --- a/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h +++ b/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h @@ -29,39 +29,44 @@ namespace embb { namespace containers { -template -int LockFreeTreeValuePool:: +template +int LockFreeTreeValuePool:: GetSmallestPowerByTwoValue(int value) { int result = 1; while (result < value) result <<= 1; return result; } -template -bool LockFreeTreeValuePool::IsLeaf( - int node ) { +template +bool LockFreeTreeValuePool:: +IsLeaf(int node) { if (node >= size - 1 && node <= 2 * size - 1) { return true; } return false; } -template -bool LockFreeTreeValuePool:: +template +bool LockFreeTreeValuePool:: IsValid(int node) { return (node >= 0 && node <= 2 * size - 1); } -template -int LockFreeTreeValuePool:: +template +int LockFreeTreeValuePool:: GetLeftChildIndex(int node) { int index = 2 * node + 1; assert(IsValid(index)); return index; } -template -int LockFreeTreeValuePool:: +template +int LockFreeTreeValuePool:: GetRightChildIndex(int node) { int index = 2 * node + 2; assert(IsValid(index)); @@ -75,16 +80,18 @@ NodeIndexToPoolIndex(int node) { return(node - (size - 1)); } -template -int LockFreeTreeValuePool:: +template +int LockFreeTreeValuePool:: PoolIndexToNodeIndex(int index) { int node = index + (size - 1); assert(IsLeaf(node)); return node; } -template -bool LockFreeTreeValuePool:: +template +bool LockFreeTreeValuePool:: IsRoot(int node) { return(0 == node); } @@ -97,14 +104,15 @@ GetParentNode(int node) { return parent; } -template -int LockFreeTreeValuePool:: -allocate_rec(int node, T& element) { +template +int LockFreeTreeValuePool:: +allocate_rec(int node, Type& element) { // If we are a leaf, we try to allocate a cell using CAS. if (IsLeaf(node)) { int pool_index = NodeIndexToPoolIndex(node); - T expected = pool[pool_index]; + Type expected = pool[pool_index]; if (expected == Undefined) return -1; @@ -120,7 +128,7 @@ allocate_rec(int node, T& element) { int desired; // Try to decrement node value. // This is the point, where the algorithm becomes not wait-free. We have to - // atomically decrement the value in the node iff the result is greater than + // atomically decrement the value in the node if the result is greater than // or equal to zero. This cannot be done atomically. do { current = tree[node]; @@ -141,8 +149,9 @@ allocate_rec(int node, T& element) { return rightResult; } -template -void LockFreeTreeValuePool:: +template +void LockFreeTreeValuePool:: Fill(int node, int elementsToStore, int power2Value) { if (IsLeaf(node)) return; @@ -165,15 +174,17 @@ Fill(int node, int elementsToStore, int power2Value) { } } -template -int LockFreeTreeValuePool:: -Allocate(T & element) { +template +int LockFreeTreeValuePool:: +Allocate(Type & element) { return allocate_rec(0, element); } -template -void LockFreeTreeValuePool:: -Free(T element, int index) { +template +void LockFreeTreeValuePool:: +Free(Type element, int index) { assert(element != Undefined); // Put the element back @@ -188,9 +199,10 @@ Free(T element, int index) { } } -template< typename T, T Undefined, class PoolAllocator, class TreeAllocator > +template< typename Type, Type Undefined, class PoolAllocator, + class TreeAllocator > template< typename ForwardIterator > -LockFreeTreeValuePool:: +LockFreeTreeValuePool:: LockFreeTreeValuePool(ForwardIterator first, ForwardIterator last) { // Number of elements to store real_size = static_cast(::std::distance(first, last)); @@ -218,12 +230,14 @@ LockFreeTreeValuePool(ForwardIterator first, ForwardIterator last) { Fill(0, static_cast(::std::distance(first, last)), size); } -template -LockFreeTreeValuePool:: +template +LockFreeTreeValuePool:: ~LockFreeTreeValuePool() { poolAllocator.deallocate(pool, static_cast(real_size)); treeAllocator.deallocate(tree, static_cast(tree_size)); } + } // namespace containers } // namespace embb diff --git a/containers_cpp/include/embb/containers/internal/object_pool-inl.h b/containers_cpp/include/embb/containers/internal/object_pool-inl.h index bdc758a..38b14f7 100644 --- a/containers_cpp/include/embb/containers/internal/object_pool-inl.h +++ b/containers_cpp/include/embb/containers/internal/object_pool-inl.h @@ -29,60 +29,60 @@ namespace embb { namespace containers { -template -ObjectPool:: +template +ObjectPool:: ReturningTrueIterator::ReturningTrueIterator(size_t count_value) : count_value(count_value), ret_value(true) {} -template -typename ObjectPool:: +template +typename ObjectPool:: ReturningTrueIterator::self_type -ObjectPool:: +ObjectPool:: ReturningTrueIterator::operator++() { self_type i = *this; count_value++; return i; } -template -typename ObjectPool:: -ReturningTrueIterator::self_type ObjectPool:: +template +typename ObjectPool:: +ReturningTrueIterator::self_type ObjectPool:: ReturningTrueIterator::operator++(int) { count_value++; return *this; } -template -typename ObjectPool:: -ReturningTrueIterator::reference ObjectPool:: +template +typename ObjectPool:: +ReturningTrueIterator::reference ObjectPool:: ReturningTrueIterator::operator*() { return ret_value; } -template -typename ObjectPool:: -ReturningTrueIterator::pointer ObjectPool:: +template +typename ObjectPool:: +ReturningTrueIterator::pointer ObjectPool:: ReturningTrueIterator::operator->() { return &ret_value; } -template -bool ObjectPool:: +template +bool ObjectPool:: ReturningTrueIterator::operator==(const self_type& rhs) { return count_value == rhs.count_value; } -template -bool ObjectPool:: +template +bool ObjectPool:: ReturningTrueIterator::operator!=(const self_type& rhs) { return count_value != rhs.count_value; } -template -bool ObjectPool:: -IsContained(const T &obj) const { +template +bool ObjectPool:: +IsContained(const Type &obj) const { if ((&obj < &objects[0]) || (&obj > &objects[capacity - 1])) { return false; } else { @@ -90,104 +90,104 @@ IsContained(const T &obj) const { } } -template -int ObjectPool:: -GetIndexOfObject(const T &obj) const { +template +int ObjectPool:: +GetIndexOfObject(const Type &obj) const { assert(IsContained(obj)); return(static_cast(&obj - &objects[0])); } -template -T* ObjectPool::AllocateRaw() { +template +Type* ObjectPool::AllocateRaw() { bool val; int allocated_index = p.Allocate(val); if (allocated_index == -1) { return NULL; } else { - T* ret_pointer = &(objects[allocated_index]); + Type* ret_pointer = &(objects[allocated_index]); return ret_pointer; } } -template -size_t ObjectPool::GetCapacity() { +template +size_t ObjectPool::GetCapacity() { return capacity; } -template -ObjectPool::ObjectPool(size_t capacity) : +template +ObjectPool::ObjectPool(size_t capacity) : capacity(capacity), p(ReturningTrueIterator(0), ReturningTrueIterator(capacity)) { // Allocate the objects (without construction, just get the memory) objects = objectAllocator.allocate(capacity); } -template -void ObjectPool::Free(T* obj) { +template +void ObjectPool::Free(Type* obj) { int index = GetIndexOfObject(*obj); - obj->~T(); + obj->~Type(); p.Free(true, index); } -template -T* ObjectPool::Allocate() { - T* rawObject = AllocateRaw(); +template +Type* ObjectPool::Allocate() { + Type* rawObject = AllocateRaw(); if (rawObject != NULL) - new (rawObject)T(); + new (rawObject)Type(); return rawObject; } -template +template template -T* ObjectPool::Allocate( +Type* ObjectPool::Allocate( Param1 const& param1) { - T* rawObject = AllocateRaw(); + Type* rawObject = AllocateRaw(); if (rawObject != NULL) - new (rawObject)T(param1); + new (rawObject)Type(param1); return rawObject; } -template +template template -T* ObjectPool::Allocate( +Type* ObjectPool::Allocate( Param1 const& param1, Param2 const& param2) { - T* rawObject = AllocateRaw(); + Type* rawObject = AllocateRaw(); if (rawObject != NULL) - new (rawObject)T(param1, param2); + new (rawObject)Type(param1, param2); return rawObject; } -template +template template -T* ObjectPool::Allocate( +Type* ObjectPool::Allocate( Param1 const& param1, Param2 const& param2, Param3 const& param3) { - T* rawObject = AllocateRaw(); + Type* rawObject = AllocateRaw(); if (rawObject != NULL) - new (rawObject)T(param1, param2, param3); + new (rawObject)Type(param1, param2, param3); return rawObject; } -template +template template -T* ObjectPool::Allocate( +Type* ObjectPool::Allocate( Param1 const& param1, Param2 const& param2, Param3 const& param3, Param4 const& param4) { - T* rawObject = AllocateRaw(); + Type* rawObject = AllocateRaw(); if (rawObject != NULL) - new (rawObject)T(param1, param2, param3, param4); + new (rawObject)Type(param1, param2, param3, param4); return rawObject; } -template -ObjectPool::~ObjectPool() { +template +ObjectPool::~ObjectPool() { // Deallocate the objects objectAllocator.deallocate(objects, capacity); } diff --git a/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h b/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h index add64b2..01cfe4f 100644 --- a/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h +++ b/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h @@ -29,20 +29,20 @@ namespace embb { namespace containers { -template -void WaitFreeArrayValuePool:: -Free(T element, int index) { +template +void WaitFreeArrayValuePool:: +Free(Type element, int index) { assert(element != Undefined); // Just put back the element pool[index].Store(element); } -template -int WaitFreeArrayValuePool:: -Allocate(T & element) { +template +int WaitFreeArrayValuePool:: +Allocate(Type & element) { for (int i = 0; i != size; ++i) { - T expected; + Type expected; // If the memory cell is not available, go ahead if (Undefined == (expected = pool[i].Load())) @@ -58,9 +58,9 @@ Allocate(T & element) { return -1; } -template +template template -WaitFreeArrayValuePool:: +WaitFreeArrayValuePool:: WaitFreeArrayValuePool(ForwardIterator first, ForwardIterator last) { size_t dist = static_cast(std::distance(first, last)); @@ -77,8 +77,8 @@ WaitFreeArrayValuePool(ForwardIterator first, ForwardIterator last) { } } -template -WaitFreeArrayValuePool::~WaitFreeArrayValuePool() { +template +WaitFreeArrayValuePool::~WaitFreeArrayValuePool() { allocator.deallocate(pool, (size_t)size); } } // namespace containers diff --git a/containers_cpp/include/embb/containers/internal/wait_free_spsc_queue-inl.h b/containers_cpp/include/embb/containers/internal/wait_free_spsc_queue-inl.h index 318b2ce..f41e59b 100644 --- a/containers_cpp/include/embb/containers/internal/wait_free_spsc_queue-inl.h +++ b/containers_cpp/include/embb/containers/internal/wait_free_spsc_queue-inl.h @@ -36,21 +36,21 @@ namespace embb { namespace containers { -template -WaitFreeSPSCQueue::WaitFreeSPSCQueue(size_t capacity) : +template +WaitFreeSPSCQueue::WaitFreeSPSCQueue(size_t capacity) : capacity(capacity), head_index(0), tail_index(0) { queue_array = allocator.allocate(capacity); } -template -size_t WaitFreeSPSCQueue::GetCapacity() { +template +size_t WaitFreeSPSCQueue::GetCapacity() { return capacity; } -template -bool WaitFreeSPSCQueue::TryEnqueue(T const & element) { +template +bool WaitFreeSPSCQueue::TryEnqueue(Type const & element) { if (head_index - tail_index == capacity) return false; @@ -59,19 +59,19 @@ bool WaitFreeSPSCQueue::TryEnqueue(T const & element) { return true; } -template -bool WaitFreeSPSCQueue::TryDequeue(T & element) { +template +bool WaitFreeSPSCQueue::TryDequeue(Type & element) { if (tail_index - head_index == 0) return false; - T x = queue_array[head_index % capacity]; + Type x = queue_array[head_index % capacity]; this->head_index++; element = x; return true; } -template -WaitFreeSPSCQueue::~WaitFreeSPSCQueue() { +template +WaitFreeSPSCQueue::~WaitFreeSPSCQueue() { allocator.deallocate(queue_array, capacity); } } // namespace containers diff --git a/containers_cpp/include/embb/containers/lock_free_mpmc_queue.h b/containers_cpp/include/embb/containers/lock_free_mpmc_queue.h index ae1a232..1318836 100644 --- a/containers_cpp/include/embb/containers/lock_free_mpmc_queue.h +++ b/containers_cpp/include/embb/containers/lock_free_mpmc_queue.h @@ -46,20 +46,20 @@ namespace internal { * Single linked lists, contains the element (\c element) and a pointer to the * next node (\c next). * - * \tparam T Element type + * \tparam Type Element type */ -template< typename T > + template< typename Type > class LockFreeMPMCQueueNode { private: /** * Pointer to the next node */ - embb::base::Atomic< LockFreeMPMCQueueNode< T >* > next; + embb::base::Atomic< LockFreeMPMCQueueNode< Type >* > next; /** * The stored element */ - T element; + Type element; public: /** @@ -73,7 +73,7 @@ class LockFreeMPMCQueueNode { * Creates a queue node */ LockFreeMPMCQueueNode( - T const& element + Type const& element /**< [IN] The element of this queue node */); /** @@ -81,12 +81,12 @@ class LockFreeMPMCQueueNode { * * \return The next pointer */ - embb::base::Atomic< LockFreeMPMCQueueNode< T >* > & GetNext(); + embb::base::Atomic< LockFreeMPMCQueueNode< Type >* > & GetNext(); /** * Returns the element held by this node */ - T GetElement(); + Type GetElement(); }; } // namespace internal @@ -99,11 +99,11 @@ class LockFreeMPMCQueueNode { * * \see WaitFreeSPSCQueue * - * \tparam T Type of the queue elements + * \tparam Type Type of the queue elements * \tparam ValuePool Type of the value pool used as basis for the ObjectPool * which stores the elements. */ -template< typename T, +template< typename Type, typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false > > class LockFreeMPMCQueue { @@ -120,35 +120,35 @@ class LockFreeMPMCQueue { * Callback to the method that is called by hazard pointers if a pointer is * not hazardous anymore, i.e., can safely be reused. */ - embb::base::Function < void, internal::LockFreeMPMCQueueNode* > + embb::base::Function < void, internal::LockFreeMPMCQueueNode* > delete_pointer_callback; /** * The hazard pointer object, used for memory management. */ embb::containers::internal::HazardPointer - < internal::LockFreeMPMCQueueNode* > hazardPointer; + < internal::LockFreeMPMCQueueNode* > hazardPointer; /** * The object pool, used for lock-free memory allocation. */ - ObjectPool< internal::LockFreeMPMCQueueNode, ValuePool > objectPool; + ObjectPool< internal::LockFreeMPMCQueueNode, ValuePool > objectPool; /** * Atomic pointer to the head node of the queue */ - embb::base::Atomic< internal::LockFreeMPMCQueueNode* > head; + embb::base::Atomic< internal::LockFreeMPMCQueueNode* > head; /** * Atomic pointer to the tail node of the queue */ - embb::base::Atomic< internal::LockFreeMPMCQueueNode* > tail; + embb::base::Atomic< internal::LockFreeMPMCQueueNode* > tail; /** * The callback function, used to cleanup non-hazardous pointers. * \see delete_pointer_callback */ - void DeletePointerCallback(internal::LockFreeMPMCQueueNode* to_delete); + void DeletePointerCallback(internal::LockFreeMPMCQueueNode* to_delete); public: /** @@ -157,8 +157,8 @@ class LockFreeMPMCQueue { * \memory * Let \c t be the maximum number of threads and \c x be 2.5*t+1. * Then, x*(3*t+1) elements of size sizeof(void*), \c x - * elements of size sizeof(T), and \c capacity+1 elements of size - * sizeof(T) are allocated. + * elements of size sizeof(Type), and \c capacity+1 elements of size + * sizeof(Type) are allocated. * * \notthreadsafe * @@ -198,7 +198,7 @@ class LockFreeMPMCQueue { * \see CPP_CONCEPTS_QUEUE */ bool TryEnqueue( - T const& element + Type const& element /**< [IN] Const reference to the element that shall be enqueued */); /** @@ -212,7 +212,7 @@ class LockFreeMPMCQueue { * \see CPP_CONCEPTS_QUEUE */ bool TryDequeue( - T & element + Type & element /**< [IN, OUT] Reference to the dequeued element. Unchanged, if the operation was not successful. */); diff --git a/containers_cpp/include/embb/containers/lock_free_stack.h b/containers_cpp/include/embb/containers/lock_free_stack.h index 3d1fbd8..640cd16 100644 --- a/containers_cpp/include/embb/containers/lock_free_stack.h +++ b/containers_cpp/include/embb/containers/lock_free_stack.h @@ -53,9 +53,9 @@ * * \par Requirements * - Let \c Stack be the stack class - * - Let \c T be the element type of the stack + * - Let \c Type be the element type of the stack * - Let \c capacity be a value of type \c size_t - * - Let \c element be a reference to an element of type \c T + * - Let \c element be a reference to an element of type \c Type * * \par Valid Expressions * @@ -65,11 +65,11 @@ * * * - * + * * * * * @@ -165,11 +165,11 @@ class LockFreeStackNode { * * \ingroup CPP_CONTAINERS_STACKS * - * \tparam T Type of the stack elements + * \tparam Type Type of the stack elements * \tparam ValuePool Type of the value pool used as basis for the ObjectPool * which stores the elements. */ -template< typename T, +template< typename Type, typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false > > class LockFreeStack { private: @@ -183,29 +183,29 @@ class LockFreeStack { * Callback to the method that is called by hazard pointers if a pointer is * not hazardous anymore, i.e., can safely be reused. */ - embb::base::Function*> + embb::base::Function*> delete_pointer_callback; /** * The hazard pointer object, used for memory management. */ - internal::HazardPointer*> hazardPointer; + internal::HazardPointer*> hazardPointer; /** * The callback function, used to cleanup non-hazardous pointers. * \see delete_pointer_callback */ - void DeletePointerCallback(internal::LockFreeStackNode* to_delete); + void DeletePointerCallback(internal::LockFreeStackNode* to_delete); /** * The object pool, used for lock-free memory allocation. */ - ObjectPool< internal::LockFreeStackNode, ValuePool > objectPool; + ObjectPool< internal::LockFreeStackNode, ValuePool > objectPool; /** * Atomic pointer to the top node of the stack (element that is popped next) */ - embb::base::Atomic*> top; + embb::base::Atomic*> top; public: /** @@ -214,8 +214,8 @@ class LockFreeStack { * \memory * Let \c t be the maximum number of threads and \c x be 1.25*t+1. * Then, x*(3*t+1) elements of size sizeof(void*), \c x - * elements of size sizeof(T), and \c capacity elements of size - * sizeof(T) are allocated. + * elements of size sizeof(Type), and \c capacity elements of size + * sizeof(Type) are allocated. * * \notthreadsafe * @@ -256,7 +256,7 @@ class LockFreeStack { * \see CPP_CONCEPTS_STACK */ bool TryPush( - T const& element + Type const& element /**< [IN] Const reference to the element that shall be pushed */ ); @@ -271,7 +271,7 @@ class LockFreeStack { * \see CPP_CONCEPTS_STACK */ bool TryPop( - T & element + Type & element /**< [IN,OUT] Reference to the popped element. Unchanged, if the operation was not successful. */ ); diff --git a/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h b/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h index 0f5e149..83f9e17 100644 --- a/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h +++ b/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h @@ -41,15 +41,15 @@ namespace containers { * * \see WaitFreeArrayValuePool * - * \tparam T Element type (must support atomic operations such as \c int). + * \tparam Type Element type (must support atomic operations such as \c int). * \tparam Undefined Bottom element (cannot be stored in the pool) * \tparam PoolAllocator Allocator used to allocate the pool array * \tparam TreeAllocator Allocator used to allocate the array representing the * binary tree. */ -template >, +template >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic > > class LockFreeTreeValuePool { @@ -95,7 +95,7 @@ class LockFreeTreeValuePool { * * The algorithm for allocating an element starts at the root node and * recursively traverses the tree. It tries to decrement a node (a decrement - * is actually a conditional decrement, i.e., a node is decremented iff the + * is actually a conditional decrement, i.e., a node is decremented if the * result is not less than 0. This is the place, where the algorithm is not * wait-free anymore, as this cannot be implemented atomically.) and if * successful, calls itself on the left child, if not successful, on the right @@ -135,7 +135,7 @@ class LockFreeTreeValuePool { embb::base::Atomic* tree; // The actual pool - embb::base::Atomic* pool; + embb::base::Atomic* pool; PoolAllocator poolAllocator; TreeAllocator treeAllocator; @@ -235,7 +235,7 @@ class LockFreeTreeValuePool { int allocate_rec( int node, /**< [IN] Node index */ - T& element + Type& element /**< [IN,OUT] Allocated element, if there is any */ ); @@ -260,8 +260,8 @@ class LockFreeTreeValuePool { * * \memory Let n = \c std::distance(first, last)) and \c k be the * minimum number such that n <= 2^k holds. Then, - * ((2^k)-1) * sizeof(embb::Atomic) + n*sizeof(embb::Atomic) - * bytes of memory are allocated. + * ((2^k)-1) * sizeof(embb::Atomic) + + * n*sizeof(embb::Atomic) bytes of memory are allocated. * * \notthreadsafe * @@ -294,7 +294,7 @@ class LockFreeTreeValuePool { * \see CPP_CONCEPTS_VALUE_POOL */ int Allocate( - T & element + Type & element /**< [IN,OUT] Reference to the allocated element. Unchanged, if the operation was not successful. */ ); @@ -309,7 +309,7 @@ class LockFreeTreeValuePool { * \see CPP_CONCEPTS_VALUE_POOL */ void Free( - T element, + Type element, /**< [IN] Element to be returned to the pool */ int index /**< [IN] Index of the element as obtained by Allocate() */ diff --git a/containers_cpp/include/embb/containers/object_pool.h b/containers_cpp/include/embb/containers/object_pool.h index 756bdda..abd7c67 100644 --- a/containers_cpp/include/embb/containers/object_pool.h +++ b/containers_cpp/include/embb/containers/object_pool.h @@ -48,15 +48,15 @@ namespace containers { * * \ingroup CPP_CONTAINERS_POOLS * - * \tparam T Element type + * \tparam Type Element type * \tparam ValuePool Type of the underlying value pool, determines whether * the object pool is wait-free or lock-free * \tparam ObjectAllocator Type of allocator used to allocate objects */ -template, - class ObjectAllocator = embb::base::Allocator > + class ObjectAllocator = embb::base::Allocator > class ObjectPool { private: /** @@ -67,7 +67,7 @@ class ObjectPool { /** * Array holding the allocated object */ - T* objects; + Type* objects; /** * Capacity of the object pool @@ -105,15 +105,15 @@ class ObjectPool { bool ret_value; }; - bool IsContained(const T &obj) const; - int GetIndexOfObject(const T &obj) const; - T* AllocateRaw(); + bool IsContained(const Type &obj) const; + int GetIndexOfObject(const Type &obj) const; + Type* AllocateRaw(); public: /** * Constructs an object pool with capacity \c capacity. * - * \memory Allocates \c capacity elements of type \c T. + * \memory Allocates \c capacity elements of type \c Type. * * \notthreadsafe */ @@ -147,7 +147,7 @@ class ObjectPool { * \note The element must have been allocated with Allocate(). */ void Free( - T* obj + Type* obj /**< [IN] Pointer to the object to be freed */ ); @@ -162,22 +162,22 @@ class ObjectPool { * * \param ... Arguments of arbitrary type, passed to the object's constructor */ - T* Allocate(...); + Type* Allocate(...); #else - T* Allocate(); + Type* Allocate(); template - T* Allocate(Param1 const& param1); + Type* Allocate(Param1 const& param1); template - T* Allocate(Param1 const& param1, Param2 const& param2); + Type* Allocate(Param1 const& param1, Param2 const& param2); template - T* Allocate(Param1 const& param1, Param2 const& param2, + Type* Allocate(Param1 const& param1, Param2 const& param2, Param3 const& param3); template - T* Allocate(Param1 const& param1, Param2 const& param2, + Type* Allocate(Param1 const& param1, Param2 const& param2, Param3 const& param3, Param4 const& param4); #endif diff --git a/containers_cpp/include/embb/containers/wait_free_array_value_pool.h b/containers_cpp/include/embb/containers/wait_free_array_value_pool.h index 1cbd90d..8c99323 100644 --- a/containers_cpp/include/embb/containers/wait_free_array_value_pool.h +++ b/containers_cpp/include/embb/containers/wait_free_array_value_pool.h @@ -48,11 +48,11 @@ namespace containers { * * \par Requirements * - Let \c Pool be the pool class - * - Let \c T be the element type of the pool. Atomic operations must be - * possible on \c T. - * - Let \c b, d be objects of type \c T + * - Let \c Type be the element type of the pool. Atomic operations must be + * possible on \c Type. + * - Let \c b, d be objects of type \c Type * - Let \c i, j be forward iterators supporting \c std::distance. - * - Let \c c be an object of type \c T& + * - Let \c c be an object of type \c Type& * - Let \c e be a value of type \c int * * \par Valid Expressions @@ -64,13 +64,13 @@ namespace containers { * * * - * * *
Description
\code{.cpp} Stack(capacity) \endcode\code{.cpp} Stack(capacity) \endcodeNothing * Constructs a stack with capacity \c capacity that holds elements of - * type \c T. + * type \c Type. *
Description
\code{.cpp} Pool(i, j) \endcode + * \code{.cpp} Pool(i, j) \endcode * Nothing - * Constructs a value pool holding elements of type \c T, where \c b is the - * bottom element. The bottom element cannot be stored in the pool, it is - * exclusively used to mark empty cells. The pool initially contains + * Constructs a value pool holding elements of type \c Type, where \c b is + * the bottom element. The bottom element cannot be stored in the pool, it + * is exclusively used to mark empty cells. The pool initially contains * \c std::distance(i, j) elements which are copied during construction from * the range \c [i, j). A concrete class satisfying the value pool concept * might provide additional template parameters for specifying allocators. @@ -107,17 +107,17 @@ namespace containers { * * \see LockFreeTreeValuePool * - * \tparam T Element type (must support atomic operations such as \c int). + * \tparam Type Element type (must support atomic operations such as \c int). * \tparam Undefined Bottom element (cannot be stored in the pool) * \tparam Allocator Allocator used to allocate the pool array */ -template > > +template > > class WaitFreeArrayValuePool { private: int size; - embb::base::Atomic* pool; + embb::base::Atomic* pool; WaitFreeArrayValuePool(); Allocator allocator; @@ -131,7 +131,7 @@ class WaitFreeArrayValuePool { /** * Constructs a pool and fills it with the elements in the specified range. * - * \memory Dynamically allocates n*sizeof(embb::base::Atomic) + * \memory Dynamically allocates n*sizeof(embb::base::Atomic) * bytes, where n = std::distance(first, last) is the number * of pool elements. * @@ -166,7 +166,7 @@ class WaitFreeArrayValuePool { * \see CPP_CONCEPTS_VALUE_POOL */ int Allocate( - T & element + Type & element /**< [IN,OUT] Reference to the allocated element. Unchanged, if the operation was not successful. */ ); @@ -181,7 +181,7 @@ class WaitFreeArrayValuePool { * \see CPP_CONCEPTS_VALUE_POOL */ void Free( - T element, + Type element, /**< [IN] Element to be returned to the pool */ int index /**< [IN] Index of the element as obtained by Allocate() */ diff --git a/containers_cpp/include/embb/containers/wait_free_spsc_queue.h b/containers_cpp/include/embb/containers/wait_free_spsc_queue.h index ea9e64d..c459f33 100644 --- a/containers_cpp/include/embb/containers/wait_free_spsc_queue.h +++ b/containers_cpp/include/embb/containers/wait_free_spsc_queue.h @@ -53,9 +53,9 @@ * * \par Requirements * - Let \c Queue be the queue class - * - Let \c T be the element type of the queue + * - Let \c Type be the element type of the queue * - Let \c capacity be a value of type \c size_t - * - Let \c element be a reference to an element of type \c T + * - Let \c element be a reference to an element of type \c Type * * \par Valid Expressions * @@ -65,7 +65,7 @@ * * * - * + * * *
Description
\code{.cpp} Queue(capacity) \endcode\code{.cpp} Queue(capacity) \endcodeNothing * Constructs a queue with capacity \c capacity that holds elements of @@ -114,10 +114,10 @@ namespace containers { * * \see LockFreeMPMCQueue * - * \tparam T Type of the queue elements + * \tparam Type Type of the queue elements * \tparam Allocator Allocator type for allocating queue elements. */ -template > +template > class WaitFreeSPSCQueue { private: /** @@ -133,7 +133,7 @@ class WaitFreeSPSCQueue { /** * Array holding the queue elements */ - T* queue_array; + Type* queue_array; /** * Index of the head in the \c queue_array @@ -149,7 +149,7 @@ class WaitFreeSPSCQueue { /** * Creates a queue with the specified capacity. * - * \memory Allocates \c capacity elements of type \c T. + * \memory Allocates \c capacity elements of type \c Type. * * \notthreadsafe * @@ -190,7 +190,7 @@ class WaitFreeSPSCQueue { * \see CPP_CONCEPTS_QUEUE */ bool TryEnqueue( - T const & element + Type const & element /**< [IN] Const reference to the element that shall be enqueued */ ); @@ -208,9 +208,9 @@ class WaitFreeSPSCQueue { * \see CPP_CONCEPTS_QUEUE */ bool TryDequeue( - T & element - /**< [IN,OUT] Reference to the dequeued element. Unchanged, if the operation - was not successful. */ + Type & element + /**< [IN,OUT] Reference to the dequeued element. Unchanged, if the + operation was not successful. */ ); }; } // namespace containers -- libgit2 0.26.0