This commit is contained in:
azw 2023-05-13 12:46:01 +00:00
parent 18a1238512
commit 787f6a5faf
2 changed files with 8 additions and 8 deletions

View File

@ -45,19 +45,18 @@ namespace a8
} else {
size_t index = GetIndex(real_len);
list_head* free_node = nullptr;
BufHead* buf_head = nullptr;
{
lock_.lock();
free_node = &free_list_[index];
if (list_empty(free_node)) {
free_node = nullptr;
} else {
list_del(free_node);
list_head* head = &free_list_[index];
if (!list_empty(head)) {
buf_head = list_first_entry(head, BufHead, entry);
list_del(&buf_head->entry);
}
lock_.unlock();
}
if (free_node) {
return (char*)free_node + sizeof(BufHead);
if (buf_head) {
return (char*)buf_head + sizeof(BufHead);
}
}
}

View File

@ -23,6 +23,7 @@ namespace a8
char* buf_ = nullptr;
int buf_len_ = 0;
std::atomic<int> offset_ = 0;
a8::SpinLock lock_;
std::array<list_head, 10> free_list_;