1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef COMMON_COMPONENTS_HEAP_ALLOCATOR_SLOT_LIST_H 17 #define COMMON_COMPONENTS_HEAP_ALLOCATOR_SLOT_LIST_H 18 19 #include "common_components/common/base_object.h" 20 21 namespace common { 22 struct ObjectSlot { 23 ObjectSlot* next; 24 }; 25 26 class SlotList { 27 public: PushFront(BaseObject * slot)28 void PushFront(BaseObject* slot) 29 { 30 ObjectSlot* headSlot = reinterpret_cast<ObjectSlot*>(slot); 31 headSlot->next = head_; 32 head_ = headSlot; 33 } 34 PopFront(size_t size)35 uintptr_t PopFront(size_t size) 36 { 37 if (head_ == nullptr) { 38 return 0; 39 } 40 ObjectSlot* allocSlot = head_; 41 head_ = head_->next; 42 allocSlot->next = nullptr; 43 return reinterpret_cast<uintptr_t>(allocSlot); 44 } 45 Clear()46 void Clear() { head_ = nullptr; } 47 private: 48 ObjectSlot* head_ = nullptr; 49 }; 50 } // namespace common 51 52 #endif // COMMON_COMPONENTS_HEAP_ALLOCATOR_SLOT_LIST_H 53