分类:
2008-10-13 16:12:06
//TODO,处理NEW失败的情况
class MsgBlockManager : public SingleTon
{
public:
MsgBlockManager(){_header=NULL;}
~MsgBlockManager(){}
public:
void init(UINT32 nums,UINT32 default_size);
void fini();
ACE_Message_Block *get_msg_block();
void release_msg_block(ACE_Message_Block *msg_block);
private:
ACE_Message_Block *_header;
ACE_Recursive_Thread_Mutex _lock;
};
//TODO!
//!!不动态生成!!!无内存泄漏!!!,有必要吗??
ACE_Message_Block *MsgBlockManager::get_msg_block()
{
ACE_Guard
if(_header==NULL)
{
ACE_DEBUG((LM_DEBUG,"NO MSG BLOCK!!!\n"));
return NULL;
}
ACE_Message_Block *ret=_header;
_header=_header->next();
ret->reset();
return ret;
}
void MsgBlockManager::release_msg_block(ACE_Message_Block *msg_block)
{
ACE_Guard
msg_block->next(_header);
_header=msg_block;
}
void MsgBlockManager::init(UINT32 nums,UINT32 default_size)
{
for(size_t i=0;i
ACE_Message_Block *msg_block=new ACE_Message_Block();
if(msg_block!=NULL)
{
msg_block->size(default_size);
msg_block->reset();
msg_block->next(_header);
_header=msg_block;
}
}
}
void MsgBlockManager::fini()
{
while(_header)
{
ACE_Message_Block *msg_block=_header->next();
delete _header;
_header=msg_block;
}
}