MCPcopy Create free account
hub / github.com/F-Stack/f-stack / GetMsgBuf

Method GetMsgBuf

adapter/micro_thread/mt_mbuf_pool.cpp:78–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78MtMsgBuf* 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
110void MsgBuffPool::FreeMsgBuf(MtMsgBuf* msg_buf)
111{

Callers 2

InputNotifyMethod · 0.45
InitConnEnvMethod · 0.45

Calls 4

HashFindMethod · 0.80
GetDataPtrMethod · 0.80
HashRemoveMethod · 0.80
HashInsertMethod · 0.80

Tested by

no test coverage detected