Removed old map tests
[libcds.git] / tests / unit / alloc / random.cpp
index dca2b1002c456b6eb06db954e2f12d5f9aaefbf8..9edc05a9fc73c204ead8ee4952d5b71b23e1fcb5 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.     
+*/
 
 // Random allocator test
 
@@ -22,12 +50,12 @@ namespace memory {
     static size_t s_nPassPerThread;
 
     struct Item {
-        cds::SpinLock   m_access;
+        cds::sync::spin m_access;
         char *          m_pszBlock;
 
         Item()
             : m_access( false )
-            , m_pszBlock( NULL )
+            , m_pszBlock( nullptr )
         {}
 
         Item& operator =(Item const& i)
@@ -82,14 +110,14 @@ namespace memory {
                 for ( size_t nPass = 0; nPass < s_nPassPerThread; ) {
                     size_t nIdx = m_rndGen( size_t(0), s_nDataSize - 1 );
                     Item & item = arr.at(nIdx);
-                    if ( item.m_access.tryLock() ) {
+                    if ( item.m_access.try_lock() ) {
                         if ( item.m_pszBlock ) {
                             m_Alloc.deallocate( item.m_pszBlock, 1 );
-                            item.m_pszBlock = NULL;
+                            item.m_pszBlock = nullptr;
                         }
                         else {
                             size_t nSize;
-                            item.m_pszBlock = m_Alloc.allocate( nSize = m_rndGen(s_nMinBlockSize, s_nMaxBlockSize ), NULL );
+                            item.m_pszBlock = m_Alloc.allocate( nSize = m_rndGen( s_nMinBlockSize, s_nMaxBlockSize ), nullptr );
 
                             if ( nSize < 32 )
                                 memset( item.m_pszBlock, 0, nSize );
@@ -124,7 +152,7 @@ namespace memory {
             for ( size_t i = 0; i < m_Data.size(); ++i ) {
                 if ( m_Data[i].m_pszBlock ) {
                     alloc.deallocate( m_Data[i].m_pszBlock, 1 );
-                    m_Data[i].m_pszBlock = NULL;
+                    m_Data[i].m_pszBlock = nullptr;
                 }
             }
         }
@@ -149,12 +177,10 @@ namespace memory {
                     ALLOC::stat( stEnd );
 
                     std::cout << "\nStatistics:\n"
-                        << stEnd
-;
+                        << stEnd;
                     stEnd -= stBegin;
                     std::cout << "\nDelta statistics:\n"
-                        << stEnd
-;
+                        << stEnd;
                 }
             }