Boost logo

Boost-Commit :

From: xushiweizh_at_[hidden]
Date: 2008-05-13 15:22:44


Author: xushiwei
Date: 2008-05-13 15:22:43 EDT (Tue, 13 May 2008)
New Revision: 45337
URL: http://svn.boost.org/trac/boost/changeset/45337

Log:
ticket #1879: Workaround ABA problem - bugfix.

Binary files modified:
   sandbox/memory/libs/memory/bin/win32/boost-memory.dll
   sandbox/memory/libs/memory/lib/boost-memory.lib
Text files modified:
   sandbox/memory/boost/detail/winapi/atomic/windows.hpp | 10 +++---
   sandbox/memory/boost/lockfree/stack.hpp | 1
   sandbox/memory/boost/lockfree/tagged_ptr.hpp | 2
   sandbox/memory/boost/memory/system_pool.hpp | 19 ++++++++------
   sandbox/memory/libs/memory/test/test_basic/memory/system_alloc_perform.cpp | 51 ++++++++++++++++++---------------------
   sandbox/memory/libs/memory/test/test_basic/test.cpp | 4 +-
   6 files changed, 43 insertions(+), 44 deletions(-)

Modified: sandbox/memory/boost/detail/winapi/atomic/windows.hpp
==============================================================================
--- sandbox/memory/boost/detail/winapi/atomic/windows.hpp (original)
+++ sandbox/memory/boost/detail/winapi/atomic/windows.hpp 2008-05-13 15:22:43 EDT (Tue, 13 May 2008)
@@ -74,11 +74,11 @@
 {
         bool ok;
         __asm {
- mov eax,[long ptr Comperand]
- mov edx,[long ptr Comperand+1]
- mov ebx,[long ptr Exchange]
- mov ecx,[long ptr Exchange+1]
- mov edi,[Destination]
+ mov eax, long ptr Comperand
+ mov edx, long ptr Comperand + 4
+ mov ebx, long ptr Exchange
+ mov ecx, long ptr Exchange + 4
+ mov edi, long ptr Destination
                 lock cmpxchg8b [edi]
                 setz [ok]
         }

Modified: sandbox/memory/boost/lockfree/stack.hpp
==============================================================================
--- sandbox/memory/boost/lockfree/stack.hpp (original)
+++ sandbox/memory/boost/lockfree/stack.hpp 2008-05-13 15:22:43 EDT (Tue, 13 May 2008)
@@ -35,6 +35,7 @@
                 node* prev() const { return _m_prev; }
 #if defined(_DEBUG)
                 node() : _m_prev(NULL) {}
+ void prev(node* p) { _m_prev = p; }
 #endif
         };
 

Modified: sandbox/memory/boost/lockfree/tagged_ptr.hpp
==============================================================================
--- sandbox/memory/boost/lockfree/tagged_ptr.hpp (original)
+++ sandbox/memory/boost/lockfree/tagged_ptr.hpp 2008-05-13 15:22:43 EDT (Tue, 13 May 2008)
@@ -57,7 +57,7 @@
         tagged_ptr() : m_p(0) {}
         
         template <class FuncT>
- bool BOOST_LOCKFREE_CALL set(FuncT op)
+ bool BOOST_LOCKFREE_CALL set(FuncT& op)
         {
                 BOOST_DETAIL_ASSERT(sizeof(Type*) == sizeof(LONG32));
                 for (;;)

Modified: sandbox/memory/boost/memory/system_pool.hpp
==============================================================================
--- sandbox/memory/boost/memory/system_pool.hpp (original)
+++ sandbox/memory/boost/memory/system_pool.hpp 2008-05-13 15:22:43 EDT (Tue, 13 May 2008)
@@ -41,13 +41,13 @@
 public:
         class node
         {
- private:
- node* m_prev;
- friend class normal_stack;
-
         public:
- node() : m_prev(NULL) {}
- node* prev() const { return m_prev; }
+ node* _m_prev;
+ node* prev() const { return _m_prev; }
+#if defined(_DEBUG)
+ node() : _m_prev(NULL) {}
+ void prev(node* p) { _m_prev = p; }
+#endif
         };
 
 private:
@@ -60,7 +60,7 @@
         void BOOST_LOCKFREE_CALL push(node* val)
         {
                 cslock aLock(m_cs);
- val->m_prev = m_top;
+ val->_m_prev = m_top;
                 m_top = val;
         }
 
@@ -78,7 +78,7 @@
                 node* the_top = m_top;
                 if (the_top == NULL)
                         return NULL;
- m_top = m_top->m_prev;
+ m_top = m_top->_m_prev;
                 return the_top;
         }
 };
@@ -129,6 +129,9 @@
 
         void BOOST_MEMORY_CALL deallocate(void* p)
         {
+#if defined(_DEBUG)
+ ((Block*)p)->prev(NULL);
+#endif
                 m_freeList.push((Block*)p);
         }
 

Modified: sandbox/memory/libs/memory/bin/win32/boost-memory.dll
==============================================================================
Binary files. No diff available.

Modified: sandbox/memory/libs/memory/lib/boost-memory.lib
==============================================================================
Binary files. No diff available.

Modified: sandbox/memory/libs/memory/test/test_basic/memory/system_alloc_perform.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/memory/system_alloc_perform.cpp (original)
+++ sandbox/memory/libs/memory/test/test_basic/memory/system_alloc_perform.cpp 2008-05-13 15:22:43 EDT (Tue, 13 May 2008)
@@ -18,38 +18,33 @@
 
 typedef system_pool_s<NS_BOOST_MEMORY_POLICY::stdlib, normal_stack> system_pool_static;
 
+enum { NTimes = 100 };
+enum { Total = 400 };
+
+static void* p[Total];
+
 template <class LogT>
 class TestSystemAlloc
 {
-private:
- void** p;
- enum { Total = 5000 };
-
 public:
- TestSystemAlloc()
- {
- p = new void*[Total];
- }
- ~TestSystemAlloc()
- {
- delete[] p;
- }
-
         template <class LogT2, class AllocT>
- void doTestAlloc(LogT2& log, AllocT& alloc)
+ void doTestAlloc(LogT2& log, AllocT& alloc, int N, int M = 16)
         {
                 NS_BOOST_DETAIL::accumulator acc;
- for (int i, j = 0; j < 16; ++j)
+ for (int i, j = 0; j < M; ++j)
                 {
                         NS_BOOST_DETAIL::performance_counter counter;
                         {
- for (i = 0; i < Total; ++i)
- {
- p[i] = alloc.allocate(BOOST_MEMORY_BLOCK_SIZE);
- }
- for (i = 0; i < Total; ++i)
+ for (int k = 0; k < N; ++k)
                                 {
- alloc.deallocate(p[i]);
+ for (i = 0; i < Total; ++i)
+ {
+ p[i] = alloc.allocate(BOOST_MEMORY_BLOCK_SIZE);
+ }
+ for (i = 0; i < Total; ++i)
+ {
+ alloc.deallocate(p[i]);
+ }
                                 }
                         }
                         acc.accumulate(counter.trace(log));
@@ -64,17 +59,17 @@
                 stdlib_alloc stdLib;
 
                 NS_BOOST_DETAIL::null_log nullLog;
- doTestAlloc(nullLog, sysPool);
- doTestAlloc(nullLog, sysPool2);
-
- log.trace("\n===== SystemPoolAlloc (LockFree) =====\n");
- doTestAlloc(log, sysPool);
+ doTestAlloc(nullLog, sysPool, 1, 1);
+ doTestAlloc(nullLog, sysPool2, 1, 1);
 
                 log.trace("\n===== SystemPoolAlloc (Lock) =====\n");
- doTestAlloc(log, sysPool2);
+ doTestAlloc(log, sysPool2, NTimes);
+
+ log.trace("\n===== SystemPoolAlloc (LockFree) =====\n");
+ doTestAlloc(log, sysPool, NTimes);
 
                 log.trace("\n===== StdLibAlloc =====\n");
- doTestAlloc(log, stdLib);
+ doTestAlloc(log, stdLib, NTimes);
         }
 };
 

Modified: sandbox/memory/libs/memory/test/test_basic/test.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/test.cpp (original)
+++ sandbox/memory/libs/memory/test/test_basic/test.cpp 2008-05-13 15:22:43 EDT (Tue, 13 May 2008)
@@ -21,9 +21,9 @@
 
 int main()
 {
- testPerformance();
+// testPerformance();
 // testExceptionSemantics();
-// testSystemAlloc();
+ testSystemAlloc();
 // testPerformance();
 // simpleExamples();
 // testStlContainers();


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk