Refactoring cds/lock/array.h
authorkhizmax <libcds.dev@gmail.com>
Tue, 30 Sep 2014 19:47:20 +0000 (23:47 +0400)
committerkhizmax <libcds.dev@gmail.com>
Tue, 30 Sep 2014 19:47:20 +0000 (23:47 +0400)
cds/lock/array.h
cds/lock/scoped_lock.h
cds/lock/spinlock.h

index dabcaba34c14a9a8703c6e892877ab7597439ed3..ce94189a51d01559e50bee06acbda83cbbe23e74 100644 (file)
@@ -1,4 +1,4 @@
-//$$CDS-header$$
+//$$CDS-header$$-2
 
 #ifndef __CDS_LOCK_ARRAY_H
 #define __CDS_LOCK_ARRAY_H
@@ -212,8 +212,7 @@ namespace cds { namespace lock {
         {
             size_t nCell = m_SelectCellPolicy( hint, size() );
             assert( nCell < size() );
-            lock_type& l = m_arrLocks[ nCell ];
-            l.lock();
+            m_arrLocks[nCell].lock();
             return nCell;
         }
 
@@ -229,8 +228,7 @@ namespace cds { namespace lock {
         {
             size_t nCell = m_SelectCellPolicy( hint, size() );
             assert( nCell < size() );
-            lock_type& l = m_arrLocks[ nCell ];
-            if ( l.try_lock() )
+            if ( m_arrLocks[nCell].try_lock() )
                 return nCell;
             return c_nUnspecifiedCell;
         }
@@ -246,7 +244,7 @@ namespace cds { namespace lock {
         void lock_all()
         {
             lock_type * pLock = m_arrLocks;
-            for ( size_t i = 0; i < size(); ++i, ++pLock )
+            for ( lock_type * pEnd = m_arrLocks + size(); pLock != pEnd; ++pLock )
                 pLock->lock();
         }
 
@@ -254,7 +252,7 @@ namespace cds { namespace lock {
         void unlock_all()
         {
             lock_type * pLock = m_arrLocks;
-            for ( size_t i = 0; i < size(); ++i, ++pLock )
+            for ( lock_type * pEnd = m_arrLocks + size(); pLock != pEnd; ++pLock )
                 pLock->unlock();
         }
 
index 8542367827f0663be52bd770c321cf8f89bceea3..13b78f2531a944fee7e8127e3976c9e4312a735e 100644 (file)
@@ -1,4 +1,4 @@
-//$$CDS-header$$
+//$$CDS-header$$-2
 
 #ifndef __CDS_LOCK_SCOPED_LOCK_H
 #define __CDS_LOCK_SCOPED_LOCK_H
index e4248a5fbe2222fa86c7ec9069ee2a1cf03377b2..119cd8f834b031896fc96e565b600e0b9299209f 100644 (file)
@@ -1,4 +1,4 @@
-//$$CDS-header$$
+//$$CDS-header$$-2
 
 #ifndef __CDS_LOCK_SPINLOCK_H
 #define __CDS_LOCK_SPINLOCK_H