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 { } else {
size_t index = GetIndex(real_len); size_t index = GetIndex(real_len);
list_head* free_node = nullptr; BufHead* buf_head = nullptr;
{ {
lock_.lock(); lock_.lock();
free_node = &free_list_[index]; list_head* head = &free_list_[index];
if (list_empty(free_node)) { if (!list_empty(head)) {
free_node = nullptr; buf_head = list_first_entry(head, BufHead, entry);
} else { list_del(&buf_head->entry);
list_del(free_node);
} }
lock_.unlock(); lock_.unlock();
} }
if (free_node) { if (buf_head) {
return (char*)free_node + sizeof(BufHead); return (char*)buf_head + sizeof(BufHead);
} }
} }
} }

View File

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