1 #ifndef SRC_FREELIST_H_ 2 #define SRC_FREELIST_H_ 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 10 struct DefaultFreelistTraits;
13 size_t kMaximumLength,
14 typename FreelistTraits = DefaultFreelistTraits>
17 typedef struct list_item {
19 list_item* next =
nullptr;
24 while (head_ !=
nullptr) {
25 list_item* item = head_;
27 FreelistTraits::Free(item->item);
33 if (
size_ > kMaximumLength) {
34 FreelistTraits::Free(item);
37 FreelistTraits::Reset(item);
38 list_item* li = Calloc<list_item>(1);
40 if (head_ ==
nullptr) {
51 if (head_ !=
nullptr) {
53 list_item* cur = head_;
59 return FreelistTraits::template Alloc<T>();
65 list_item* head_ =
nullptr;
66 list_item* tail_ =
nullptr;
69 struct DefaultFreelistTraits {
72 return ::new (Malloc<T>(1)) T();
76 static
void Free(T* item) {
82 static void Reset(T* item) {
90 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 92 #endif // SRC_FREELIST_H_