Added copyright and license
[libcds.git] / cds / container / basket_queue.h
index a379a546a10c5dc7db8d68a308dbe96412c17d69..53ef4bcff594a339be8bc877c953a71afae0a04a 100644 (file)
@@ -1,4 +1,32 @@
-//$$CDS-header$$
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+    
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+*/
 
 #ifndef CDSLIB_CONTAINER_BASKET_QUEUE_H
 #define CDSLIB_CONTAINER_BASKET_QUEUE_H
@@ -48,22 +76,22 @@ namespace cds { namespace container {
             */
             typedef opt::v::relaxed_ordering    memory_model;
 
-            /// Alignment of internal queue data. Default is \p opt::cache_line_alignment
-            enum { alignment = opt::cache_line_alignment };
+            /// Padding for internal critical atomic data. Default is \p opt::cache_line_padding
+            enum { padding = opt::cache_line_padding };
         };
 
         /// Metafunction converting option list to \p basket_queue::traits
         /**
             Supported \p Options are:
-            - opt::allocator - allocator (like \p std::allocator) used for allocating queue nodes. Default is \ref CDS_DEFAULT_ALLOCATOR
-            - opt::back_off - back-off strategy used, default is \p cds::backoff::empty.
-            - opt::item_counter - the type of item counting feature. Default is \p cds::atomicity::empty_item_counter (item counting disabled)
+            - \p opt::allocator - allocator (like \p std::allocator) used for allocating queue nodes. Default is \ref CDS_DEFAULT_ALLOCATOR
+            - \p opt::back_off - back-off strategy used, default is \p cds::backoff::empty.
+            - \p opt::item_counter - the type of item counting feature. Default is \p cds::atomicity::empty_item_counter (item counting disabled)
                 To enable item counting use \p cds::atomicity::item_counter
-            - opt::stat - the type to gather internal statistics.
+            - opt::stat - the type to gather internal statistics.
                 Possible statistics types are: \p basket_queue::stat, \p basket_queue::empty_stat, user-provided class that supports \p %basket_queue::stat interface.
                 Default is \p %basket_queue::empty_stat.
-            - opt::alignment - the alignment for internal queue data. Default is \p opt::cache_line_alignment
-            - opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default)
+            - \p opt::padding - padding for internal critical atomic data. Default is \p opt::cache_line_padding
+            - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default)
                 or \p opt::v::sequential_consistent (sequentially consisnent memory model).
 
             Example: declare \p %BasketQueue with item counting and internal statistics
@@ -143,14 +171,14 @@ namespace cds { namespace container {
 
         <b>Key idea</b>
 
-        In the \93basket\94 approach, instead of
+        In the 'basket' approach, instead of
         the traditional ordered list of nodes, the queue consists of an ordered list of groups
         of nodes (logical baskets). The order of nodes in each basket need not be specified, and in
         fact, it is easiest to maintain them in LIFO order. The baskets fulfill the following basic
         rules:
-        - Each basket has a time interval in which all its nodes\92 enqueue operations overlap.
+        - Each basket has a time interval in which all its nodes' enqueue operations overlap.
         - The baskets are ordered by the order of their respective time intervals.
-        - For each basket, its nodes\92 dequeue operations occur after its time interval.
+        - For each basket, its nodes' dequeue operations occur after its time interval.
         - The dequeue operations are performed according to the order of baskets.
 
         Two properties define the FIFO order of nodes:
@@ -159,7 +187,7 @@ namespace cds { namespace container {
 
         In algorithms such as the MS-queue or optimistic
         queue, threads enqueue items by applying a Compare-and-swap (CAS) operation to the
-        queue\92s tail pointer, and all the threads that fail on a particular CAS operation (and also
+        queue's tail pointer, and all the threads that fail on a particular CAS operation (and also
         the winner of that CAS) overlap in time. In particular, they share the time interval of
         the CAS operation itself. Hence, all the threads that fail to CAS on the tail-node of
         the queue may be inserted into the same basket. By integrating the basket-mechanism
@@ -167,7 +195,7 @@ namespace cds { namespace container {
         onto the new tail, can now be utilized to insert the failed operations into the basket,
         allowing enqueues to complete sooner. In the meantime, the next successful CAS operations
         by enqueues allow new baskets to be formed down the list, and these can be
-        filled concurrently. Moreover, the failed operations don\92t retry their link attempt on the
+        filled concurrently. Moreover, the failed operations don't retry their link attempt on the
         new tail, lowering the overall contention on it. This leads to a queue
         algorithm that unlike all former concurrent queue algorithms requires virtually no tuning
         of the backoff mechanisms to reduce contention, making the algorithm an attractive