1 #ifndef SRC_CLEANUP_QUEUE_INL_H_ 2 #define SRC_CLEANUP_QUEUE_INL_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "base_object.h" 7 #include "cleanup_queue.h" 8 #include "memory_tracker-inl.h" 9 #include "util.h" 10 11 namespace node { 12 MemoryInfo(MemoryTracker * tracker)13inline void CleanupQueue::MemoryInfo(MemoryTracker* tracker) const { 14 ForEachBaseObject([&](BaseObject* obj) { 15 if (obj->IsDoneInitializing()) tracker->Track(obj); 16 }); 17 } 18 SelfSize()19inline size_t CleanupQueue::SelfSize() const { 20 return sizeof(CleanupQueue) + 21 cleanup_hooks_.size() * sizeof(CleanupHookCallback); 22 } 23 empty()24bool CleanupQueue::empty() const { 25 return cleanup_hooks_.empty(); 26 } 27 Add(Callback cb,void * arg)28void CleanupQueue::Add(Callback cb, void* arg) { 29 auto insertion_info = 30 cleanup_hooks_.emplace(cb, arg, cleanup_hook_counter_++); 31 // Make sure there was no existing element with these values. 32 CHECK_EQ(insertion_info.second, true); 33 } 34 Remove(Callback cb,void * arg)35void CleanupQueue::Remove(Callback cb, void* arg) { 36 CleanupHookCallback search{cb, arg, 0}; 37 cleanup_hooks_.erase(search); 38 } 39 40 template <typename T> ForEachBaseObject(T && iterator)41void CleanupQueue::ForEachBaseObject(T&& iterator) const { 42 std::vector<CleanupHookCallback> callbacks = GetOrdered(); 43 44 for (const auto& hook : callbacks) { 45 BaseObject* obj = GetBaseObject(hook); 46 if (obj != nullptr) iterator(obj); 47 } 48 } 49 GetBaseObject(const CleanupHookCallback & callback)50BaseObject* CleanupQueue::GetBaseObject( 51 const CleanupHookCallback& callback) const { 52 if (callback.fn_ == BaseObject::DeleteMe) 53 return static_cast<BaseObject*>(callback.arg_); 54 else 55 return nullptr; 56 } 57 58 } // namespace node 59 60 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 61 62 #endif // SRC_CLEANUP_QUEUE_INL_H_ 63