Added more checking
authorkhizmax <libcds.dev@gmail.com>
Sat, 14 Mar 2015 17:48:54 +0000 (20:48 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 14 Mar 2015 17:48:54 +0000 (20:48 +0300)
cds/memory/vyukov_queue_pool.h
cds/sync/injecting_monitor.h
cds/sync/pool_monitor.h

index 938f158e69f4a82d6526fda399b12ee9469fdb9b..c7be7f43273605dadf121021d48f97b97451bb0c 100644 (file)
@@ -405,8 +405,9 @@ namespace cds { namespace memory {
         //@cond
         void preallocate_pool()
         {
-            m_pFirst = cxx_allocator().NewArray( m_Queue.capacity() );
-            m_pLast = m_pFirst + m_Queue.capacity();
+            size_t const nCount = m_Queue.capacity();
+            m_pFirst = cxx_allocator().NewArray( nCount );
+            m_pLast = m_pFirst + nCount;
 
             for ( value_type * p = m_pFirst; p < m_pLast; ++p )
                 CDS_VERIFY( m_Queue.push( *p )) ;   // must be true
@@ -474,7 +475,7 @@ namespace cds { namespace memory {
 
             if ( p ) {
                 assert( from_pool( p ));
-                m_Queue.push( *p );
+                CDS_VERIFY( m_Queue.push( *p ));
             }
         }
     };
index 1588b204efd53c630f37b1a70a733248ba51f3ef..323866e8cddb909a9b491ffd7fd3d11b58204632 100644 (file)
@@ -34,6 +34,13 @@ namespace cds { namespace sync {
         /// Node injection
         struct node_injection {
             mutable lock_type m_Lock;   ///< Node spin-lock
+
+            //@cond
+            CDS_CONSTEXPR bool check_free() const
+            {
+                return true;
+            }
+            //@endcond
         };
 
         /// Makes exclusive access to node \p p
index 1e73711a55f799cb70b3b74b29ba88d857663b42..2c544cb737185f107a10c81835e1e0a7b8fb06e0 100644 (file)
@@ -33,13 +33,13 @@ namespace cds { namespace sync {
             typedef Counter event_counter; ///< measure type
 
             event_counter m_nLockCount;         ///< Number of monitor \p lock() call
-            event_counter m_nUnlockCount;       ///< Number of monitor \p unlock call
+            event_counter m_nUnlockCount;       ///< Number of monitor \p unlock() call
             event_counter m_nMaxLocked;         ///< Max number of simuntaneously locked mutexes
             event_counter m_nLockContention;    ///< Number of \p lock() contenton
             event_counter m_nUnlockContention;  ///< Number of \p unlock() contention
             event_counter m_nLockAllocation;    ///< Number of the lock allocation from the pool
             event_counter m_nLockDeallocation;  ///< Number of the lock deallocation
-            event_counter m_nMaxAllocated;      ///< Max number of sumultanouusly allocated mutexes
+            event_counter m_nMaxAllocated;      ///< Max number of sumultaneously allocated mutexes
 
             //@cond
             void onLock()
@@ -127,6 +127,7 @@ namespace cds { namespace sync {
             mutable atomics::atomic<refspin_type>   m_RefSpin;  ///< Spin-lock for \p m_pLock (bit 0) + reference counter
             mutable lock_type *                     m_pLock;    ///< Node-level lock
 
+            //@cond
             node_injection()
                 : m_RefSpin( 0 )
                 , m_pLock( nullptr )
@@ -137,6 +138,12 @@ namespace cds { namespace sync {
                 assert( m_pLock == nullptr );
                 assert( m_RefSpin.load( atomics::memory_order_relaxed ) == 0 );
             }
+
+            bool check_free() const
+            {
+                return m_pLock == nullptr && m_RefSpin.load( atomics::memory_order_acquire ) == 0;
+            }
+            //@endcond
         };
 
         /// Initializes the pool of 256 preallocated mutexes