| 76 | } |
| 77 | |
| 78 | MtMsgBuf* MsgBuffPool::GetMsgBuf(int max_size) |
| 79 | { |
| 80 | if (!_hash_map) { |
| 81 | MTLOG_ERROR("MsgBuffPoll not init! hash %p,", _hash_map); |
| 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | MsgBufMap* msg_map = NULL; |
| 86 | MsgBufMap msg_key(max_size); |
| 87 | HashKey* hash_item = _hash_map->HashFind(&msg_key); |
| 88 | if (hash_item) { |
| 89 | msg_map = (MsgBufMap*)hash_item->GetDataPtr(); |
| 90 | if (msg_map) { |
| 91 | return msg_map->GetMsgBuf(); |
| 92 | } else { |
| 93 | MTLOG_ERROR("Hash item: %p, msg_map: %p impossible, clean it", hash_item, msg_map); |
| 94 | _hash_map->HashRemove(hash_item); |
| 95 | delete hash_item; |
| 96 | return NULL; |
| 97 | } |
| 98 | } else { |
| 99 | msg_map = new MsgBufMap(max_size, _max_free); |
| 100 | if (!msg_map) { |
| 101 | MTLOG_ERROR("maybe no more memory, failed. size: %d", max_size); |
| 102 | return NULL; |
| 103 | } |
| 104 | _hash_map->HashInsert(msg_map); |
| 105 | |
| 106 | return msg_map->GetMsgBuf(); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void MsgBuffPool::FreeMsgBuf(MtMsgBuf* msg_buf) |
| 111 | { |
no test coverage detected