线程池 c++
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-08-03 15:31 threadPool
文件 3083264 2015-08-03 17:25 threadPool.ncb
文件 896 2015-07-23 22:02 threadPool.sln
文件 31232 2015-08-03 17:24 threadPool.suo
目录 0 2015-08-03 15:31 threadPoolDebug
文件 6706 2015-08-03 15:31 threadPoolDebugBuildLog.htm
文件 20691 2015-07-24 00:57 threadPoolDebugmem_pool.obj
文件 65 2015-08-03 15:31 threadPoolDebugmt.dep
文件 11917 2015-07-23 22:12 threadPoolDebugstdafx.obj
文件 68561 2015-07-28 22:17 threadPoolDebug hread.obj
文件 663 2015-07-23 22:12 threadPoolDebug hreadPool.exe.embed.manifest
文件 728 2015-07-23 22:12 threadPoolDebug hreadPool.exe.embed.manifest.res
文件 621 2015-08-03 15:31 threadPoolDebug hreadPool.exe.intermediate.manifest
文件 60963 2015-08-03 15:31 threadPoolDebug hreadPool.obj
文件 3211264 2015-07-23 22:12 threadPoolDebug hreadPool.pch
文件 353307 2015-08-03 15:29 threadPoolDebugThreadPoolExecutor.obj
文件 666624 2015-08-03 15:31 threadPoolDebugvc90.idb
文件 389120 2015-08-03 15:31 threadPoolDebugvc90.pdb
文件 6986 2015-07-24 00:57 threadPoolmem_pool.cpp
文件 2413 2015-07-24 00:57 threadPoolmem_pool.h
文件 1201 2015-07-23 22:02 threadPoolReadMe.txt
文件 215 2015-07-23 22:02 threadPoolstdafx.cpp
文件 233 2015-07-23 22:02 threadPoolstdafx.h
文件 498 2015-07-23 22:02 threadPool argetver.h
文件 2441 2015-07-24 00:58 threadPool hread.cpp
文件 1624 2015-07-23 22:04 threadPool hread.h
文件 785 2015-08-03 15:31 threadPool hreadPool.cpp
文件 4901 2015-07-24 00:55 threadPool hreadPool.vcproj
文件 1413 2015-08-03 17:24 threadPool hreadPool.vcproj.zhang-PC.zhang.user
文件 5553 2015-08-03 15:28 threadPoolThreadPoolExecutor.cpp
文件 2211 2015-07-24 00:52 threadPoolThreadPoolExecutor.h
............此处省略0个文件信息
#include “stdafx.h“
#include “mem_pool.h“
//#include “../auto_lock.h“
//--------------------------------------------MemBlock----------------------------------------------------
#define LOG_TAG “mem pool“
FixedMemBlock::FixedMemBlock(UINT unitSize USHORT unitCount) :
m_blockTotalSize(unitSize * unitCount)
m_freeUnitCount(unitCount - 1)
m_firstFreeIndex(1)
m_pNextBlock(NULL)
m_unitSize(unitSize)
{
char *p = m_firstByte;
//the min index is 1 max index is (unitCount - 1)
//0th unit points to 1th unit 1th points to 2th...(unitCount-2)th points to (unitCount-1)
for (int i = 1; i <= unitCount - 1; ++i)
{
(*(USHORT *)p) = i;
p += unitSize;
}
}
FixedMemBlock::~FixedMemBlock()
{}
void *FixedMemBlock::getFirstFreeUnit()
{
void *pRet = NULL;
if(m_freeUnitCount > 0)
{
pRet = m_firstByte + ((UINT)m_firstFreeIndex) * m_unitSize;
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “alloc unit %i %i from %i“ m_firstFreeIndex pRet this);
#endif
m_firstFreeIndex = *(USHORT *)pRet;
m_freeUnitCount--;
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “next unit %i“ m_firstFreeIndex);
PRINT_I(LOG_TAG “current unit count %i“ m_freeUnitCount);
PRINT_I(LOG_TAG “--------------------------“);
#endif
}
return pRet;
}
bool FixedMemBlock::containsUnit(void *addr)
{
ULONG l = (ULONG)addr;
return (l >= (ULONG)(m_firstByte) && l < (ULONG)(m_firstByte + m_blockTotalSize));
}
void FixedMemBlock::releaseUnit(void *p)
{
//when invoke this method should guarantee that p definitely belongs to this block
//so it‘s private not allow user to invoke it
//write the pre-free index to the head of the unit
*(USHORT *)p = m_firstFreeIndex;
m_firstFreeIndex = (USHORT)(((ULONG)p - (ULONG)(m_firstByte)) / m_unitSize);
m_freeUnitCount++;
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “release unit %i from %i“ m_firstFreeIndex this);
PRINT_I(LOG_TAG “current unit count %i“ m_freeUnitCount);
#endif
}
void * FixedMemBlock::operator new(size_t UINT unitSize UINT unitCount)
{
void *ret = ::operator new(sizeof(FixedMemBlock) + unitSize * unitCount);
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “alloc new block %i“ ret);
#endif
return ret;
}
void FixedMemBlock::operator delete(void *p UINT unitSize UINT unitCount)
{
if (p)::operator delete(p);
}
void FixedMemBlock::operator delete(void *p size_t)
{
#ifdef FIXEDMEMPOOL_DEBUG
PRINT_I(LOG_TAG “release block %i“ p);
#endif
if (p)::operator delete(p);
}
//--------------------------------------------MemPool----------------------------------------------------
FixedMemPool::FixedMemPool():
m_pBlockHead(NULL)
m_blockCount(0)
m_autoReleaseFreeBlock(false)
m_maxReserveBlocksCount(0)
m_totalAllocSize(0)
m_isInited(false)
m_unitSize(0)
m_unitCountPerBlock(0)
{
}
FixedMemPool::FixedMemPool(UINT unitSize USHORT unitCountPerBlock) :
m_pBlockHead(NULL)
m_blockCount(0)
m_autoReleaseFreeBl
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-08-03 15:31 threadPool
文件 3083264 2015-08-03 17:25 threadPool.ncb
文件 896 2015-07-23 22:02 threadPool.sln
文件 31232 2015-08-03 17:24 threadPool.suo
目录 0 2015-08-03 15:31 threadPoolDebug
文件 6706 2015-08-03 15:31 threadPoolDebugBuildLog.htm
文件 20691 2015-07-24 00:57 threadPoolDebugmem_pool.obj
文件 65 2015-08-03 15:31 threadPoolDebugmt.dep
文件 11917 2015-07-23 22:12 threadPoolDebugstdafx.obj
文件 68561 2015-07-28 22:17 threadPoolDebug hread.obj
文件 663 2015-07-23 22:12 threadPoolDebug hreadPool.exe.em
文件 728 2015-07-23 22:12 threadPoolDebug hreadPool.exe.em
文件 621 2015-08-03 15:31 threadPoolDebug hreadPool.exe.intermediate.manifest
文件 60963 2015-08-03 15:31 threadPoolDebug hreadPool.obj
文件 3211264 2015-07-23 22:12 threadPoolDebug hreadPool.pch
文件 353307 2015-08-03 15:29 threadPoolDebugThreadPoolExecutor.obj
文件 666624 2015-08-03 15:31 threadPoolDebugvc90.idb
文件 389120 2015-08-03 15:31 threadPoolDebugvc90.pdb
文件 6986 2015-07-24 00:57 threadPoolmem_pool.cpp
文件 2413 2015-07-24 00:57 threadPoolmem_pool.h
文件 1201 2015-07-23 22:02 threadPoolReadMe.txt
文件 215 2015-07-23 22:02 threadPoolstdafx.cpp
文件 233 2015-07-23 22:02 threadPoolstdafx.h
文件 498 2015-07-23 22:02 threadPool argetver.h
文件 2441 2015-07-24 00:58 threadPool hread.cpp
文件 1624 2015-07-23 22:04 threadPool hread.h
文件 785 2015-08-03 15:31 threadPool hreadPool.cpp
文件 4901 2015-07-24 00:55 threadPool hreadPool.vcproj
文件 1413 2015-08-03 17:24 threadPool hreadPool.vcproj.zhang-PC.zhang.user
文件 5553 2015-08-03 15:28 threadPoolThreadPoolExecutor.cpp
文件 2211 2015-07-24 00:52 threadPoolThreadPoolExecutor.h
............此处省略0个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)