Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61309 - sandbox/memory/boost/memory
From: xushiweizh_at_[hidden]
Date: 2010-04-15 23:34:15


Author: xushiwei
Date: 2010-04-15 23:34:14 EDT (Thu, 15 Apr 2010)
New Revision: 61309
URL: http://svn.boost.org/trac/boost/changeset/61309

Log:
BOOST_MEMORY_CHECK_THREAD;
Text files modified:
   sandbox/memory/boost/memory/basic.hpp | 55 ++++++++++++++++++++++++++++++++++++++++
   sandbox/memory/boost/memory/pool_alloc.hpp | 8 +++++
   sandbox/memory/boost/memory/region_alloc.hpp | 6 ++++
   3 files changed, 68 insertions(+), 1 deletions(-)

Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2010-04-15 23:34:14 EDT (Thu, 15 Apr 2010)
@@ -114,6 +114,61 @@
 #endif
 
 // =========================================================================
+// BOOST_MEMORY_THREAD_CHECKER
+
+#if defined(_WIN32) || defined(_WIN64)
+
+#ifndef _WINDOWS_
+#include <windows.h>
+#endif
+
+#else
+
+#ifndef _PTHREAD_H
+#include <pthread.h>
+#endif
+
+#endif
+
+NS_BOOST_MEMORY_BEGIN
+
+inline unsigned long BOOST_MEMORY_CALL getCurrentThreadId()
+{
+#if defined(_WIN32) || defined(_WIN64)
+ return GetCurrentThreadId();
+#else
+ return pthread_self();
+#endif
+}
+
+class thread_checker
+{
+private:
+ unsigned long m_threadId;
+
+public:
+ thread_checker()
+ {
+ m_threadId = getCurrentThreadId();
+ }
+
+ bool BOOST_MEMORY_CALL check() const
+ {
+ return m_threadId == getCurrentThreadId();
+ }
+};
+
+#if defined(_DEBUG)
+#define BOOST_MEMORY_THREAD_CHECKER NS_BOOST_MEMORY::thread_checker boostmm_thread_checker
+#define BOOST_MEMORY_CHECK_THREAD() BOOST_MEMORY_ASSERT(boostmm_thread_checker.check())
+#else
+#define BOOST_MEMORY_THREAD_CHECKER
+#define BOOST_MEMORY_CHECK_THREAD() (void)0
+#endif
+
+NS_BOOST_MEMORY_END
+
+// =========================================================================
 // NEW, NEW_ARRAY, ALLOC, ALLOC_ARRAY
 
 #if !defined(_NEW_) && !defined(_NEW)

Modified: sandbox/memory/boost/memory/pool_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/pool_alloc.hpp (original)
+++ sandbox/memory/boost/memory/pool_alloc.hpp 2010-04-15 23:34:14 EDT (Thu, 15 Apr 2010)
@@ -70,6 +70,7 @@
         size_type m_cbChunk;
         size_type m_nChunkPerBlock;
         alloc_type m_alloc;
+ BOOST_MEMORY_THREAD_CHECKER;
 
 private:
         void BOOST_MEMORY_CALL init_(size_type cbElem)
@@ -111,6 +112,8 @@
 
         void BOOST_MEMORY_CALL clear()
         {
+ BOOST_MEMORY_CHECK_THREAD();
+
                 MemBlock* nextBlk;
                 for (MemBlock* blk = m_blks; blk; blk = nextBlk)
                 {
@@ -145,6 +148,7 @@
 public:
         __forceinline void* BOOST_MEMORY_CALL allocate()
         {
+ BOOST_MEMORY_CHECK_THREAD();
                 if (m_freelist)
                 {
                         FreeChunk* p = m_freelist;
@@ -165,6 +169,7 @@
         __forceinline void BOOST_MEMORY_CALL deallocate(void* const p)
         {
                 BOOST_MEMORY_DBG_FILL(p, alloc_size());
+ BOOST_MEMORY_CHECK_THREAD();
 
                 ((FreeChunk*)p)->pPrev = m_freelist;
                 m_freelist = (FreeChunk*)p;
@@ -172,8 +177,9 @@
 
         __forceinline void BOOST_MEMORY_CALL deallocate(void* const p, size_t cb)
         {
- BOOST_MEMORY_ASSERT(cb == alloc_size());
+ BOOST_MEMORY_ASSERT(cb <= alloc_size());
                 BOOST_MEMORY_DBG_FILL(p, alloc_size());
+ BOOST_MEMORY_CHECK_THREAD();
 
                 ((FreeChunk*)p)->pPrev = m_freelist;
                 m_freelist = (FreeChunk*)p;

Modified: sandbox/memory/boost/memory/region_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/region_alloc.hpp (original)
+++ sandbox/memory/boost/memory/region_alloc.hpp 2010-04-15 23:34:14 EDT (Thu, 15 Apr 2010)
@@ -64,6 +64,7 @@
         char* m_end;
         AllocT m_alloc;
         DestroyNode* m_destroyChain;
+ BOOST_MEMORY_THREAD_CHECKER;
 
 private:
         __forceinline MemBlock* BOOST_MEMORY_CALL chainHeader_() const
@@ -113,6 +114,7 @@
 
         void BOOST_MEMORY_CALL clear()
         {
+ BOOST_MEMORY_CHECK_THREAD();
                 while (m_destroyChain)
                 {
                         DestroyNode* curr = m_destroyChain;
@@ -161,6 +163,7 @@
 public:
         __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb)
         {
+ BOOST_MEMORY_CHECK_THREAD();
                 if ((size_t)(m_end - m_begin) >= cb)
                 {
                         return m_end -= cb;
@@ -195,6 +198,7 @@
         {
                 DestroyNode* pNode = (DestroyNode*)p - 1;
                 BOOST_MEMORY_ASSERT(pNode->fnDestroy == fn);
+ BOOST_MEMORY_CHECK_THREAD();
 
                 pNode->pPrev = m_destroyChain;
                 m_destroyChain = pNode;
@@ -212,6 +216,8 @@
 
         void* BOOST_MEMORY_CALL reallocate(void* p, size_t oldSize, size_t newSize)
         {
+ BOOST_MEMORY_CHECK_THREAD();
+
                 if (oldSize >= newSize)
                         return p;
                 void* p2 = allocate(newSize);


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