Merged branch 'master' of https://github.com/Nemo1369/libcds
[libcds.git] / cds / details / allocator.h
index cbc634c08deb0f8ee5b73e091fafacce6a35546f..ee7f0302a067adbfa92937b771cdb2709585b55b 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-2017
+
+    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_DETAILS_ALLOCATOR_H
 #define CDSLIB_DETAILS_ALLOCATOR_H
@@ -42,52 +70,20 @@ namespace cds {
             template <typename... S>
             value_type *  New( S const&... src )
             {
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
-                }
-                value_type * pv = Construct( allocator_type::allocate(1), src... );
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
-                }
-                return pv;
-#           else
                 return Construct( allocator_type::allocate(1), src... );
-#           endif
             }
 
             /// Analogue of <tt>operator new T( std::forward<Args>(args)... )</tt> (move semantics)
             template <typename... Args>
             value_type * MoveNew( Args&&... args )
             {
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
-                }
-                value_type * pv = MoveConstruct( allocator_type::allocate(1), std::forward<Args>(args)... );
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
-                }
-                return pv;
-#           else
                 return MoveConstruct( allocator_type::allocate(1), std::forward<Args>(args)... );
-#           endif
             }
 
             /// Analogue of operator new T[\p nCount ]
             value_type * NewArray( size_t nCount )
             {
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
-                }
-#           endif
                 value_type * p = allocator_type::allocate( nCount );
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
-                }
-#           endif
                 for ( size_t i = 0; i < nCount; ++i )
                     Construct( p + i );
                 return p;
@@ -100,17 +96,7 @@ namespace cds {
             template <typename S>
             value_type * NewArray( size_t nCount, S const& src )
             {
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
-                }
-#           endif
                 value_type * p = allocator_type::allocate( nCount );
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
-                }
-#           endif
                 for ( size_t i = 0; i < nCount; ++i )
                     Construct( p + i, src );
                 return p;
@@ -140,22 +126,16 @@ namespace cds {
             /// Analogue of operator delete
             void Delete( value_type * p )
             {
-                // TSan false positive possible
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
                 allocator_type::destroy( p );
                 allocator_type::deallocate( p, 1 );
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
             }
 
             /// Analogue of operator delete []
             void Delete( value_type * p, size_t nCount )
             {
-                // TSan false positive possible
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
                  for ( size_t i = 0; i < nCount; ++i )
                      allocator_type::destroy( p + i );
                 allocator_type::deallocate( p, nCount );
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
             }
 
 #       if CDS_COMPILER == CDS_COMPILER_INTEL
@@ -170,10 +150,7 @@ namespace cds {
             template <typename... S>
             value_type * Construct( void * p, S const&... src )
             {
-                // TSan false positive possible
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
                 value_type * pv = new( p ) value_type( src... );
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
                 return pv;
             }
 
@@ -181,10 +158,7 @@ namespace cds {
             template <typename... Args>
             value_type * MoveConstruct( void * p, Args&&... args )
             {
-                // TSan false positive possible
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
                 value_type * pv = new( p ) value_type( std::forward<Args>(args)... );
-                CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
                 return pv;
             }
 
@@ -202,18 +176,7 @@ namespace cds {
 
                 size_t const nPtrSize = ( nByteSize + sizeof(void *) - 1 ) / sizeof(void *);
                 typedef typename allocator_type::template rebind< void * >::other void_allocator;
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN;
-                }
-#           endif
-                void * p = void_allocator().allocate( nPtrSize );
-#           if CDS_THREAD_SANITIZER_ENABLED
-                if ( c_bStdAllocator ) {
-                    CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;
-                }
-#           endif
-                return p;
+                return void_allocator().allocate( nPtrSize );
             }
             //@endcond
         };