|
30 | 30 | #include "inspector_profiler.h" |
31 | 31 | #endif |
32 | 32 | #include "callback_queue.h" |
| 33 | +#include "cleanup_queue-inl.h" |
33 | 34 | #include "debug_utils.h" |
34 | 35 | #include "env_properties.h" |
35 | 36 | #include "handle_wrap.h" |
@@ -492,38 +493,6 @@ class ShouldNotAbortOnUncaughtScope { |
492 | 493 | Environment* env_; |
493 | 494 | }; |
494 | 495 |
|
495 | | -class CleanupHookCallback { |
496 | | - public: |
497 | | - typedef void (*Callback)(void*); |
498 | | - |
499 | | - CleanupHookCallback(Callback fn, |
500 | | - void* arg, |
501 | | - uint64_t insertion_order_counter) |
502 | | - : fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {} |
503 | | - |
504 | | - // Only hashes `arg_`, since that is usually enough to identify the hook. |
505 | | - struct Hash { |
506 | | - inline size_t operator()(const CleanupHookCallback& cb) const; |
507 | | - }; |
508 | | - |
509 | | - // Compares by `fn_` and `arg_` being equal. |
510 | | - struct Equal { |
511 | | - inline bool operator()(const CleanupHookCallback& a, |
512 | | - const CleanupHookCallback& b) const; |
513 | | - }; |
514 | | - |
515 | | - inline BaseObject* GetBaseObject() const; |
516 | | - |
517 | | - private: |
518 | | - friend class Environment; |
519 | | - Callback fn_; |
520 | | - void* arg_; |
521 | | - |
522 | | - // We keep track of the insertion order for these objects, so that we can |
523 | | - // call the callbacks in reverse order when we are cleaning up. |
524 | | - uint64_t insertion_order_counter_; |
525 | | -}; |
526 | | - |
527 | 496 | typedef void (*DeserializeRequestCallback)(v8::Local<v8::Context> context, |
528 | 497 | v8::Local<v8::Object> holder, |
529 | 498 | int index, |
@@ -990,9 +959,8 @@ class Environment : public MemoryRetainer { |
990 | 959 | void ScheduleTimer(int64_t duration); |
991 | 960 | void ToggleTimerRef(bool ref); |
992 | 961 |
|
993 | | - using CleanupCallback = CleanupHookCallback::Callback; |
994 | | - inline void AddCleanupHook(CleanupCallback cb, void* arg); |
995 | | - inline void RemoveCleanupHook(CleanupCallback cb, void* arg); |
| 962 | + inline void AddCleanupHook(CleanupQueue::Callback cb, void* arg); |
| 963 | + inline void RemoveCleanupHook(CleanupQueue::Callback cb, void* arg); |
996 | 964 | void RunCleanup(); |
997 | 965 |
|
998 | 966 | static size_t NearHeapLimitCallback(void* data, |
@@ -1208,11 +1176,7 @@ class Environment : public MemoryRetainer { |
1208 | 1176 |
|
1209 | 1177 | BindingDataStore bindings_; |
1210 | 1178 |
|
1211 | | - // Use an unordered_set, so that we have efficient insertion and removal. |
1212 | | - std::unordered_set<CleanupHookCallback, |
1213 | | - CleanupHookCallback::Hash, |
1214 | | - CleanupHookCallback::Equal> cleanup_hooks_; |
1215 | | - uint64_t cleanup_hook_counter_ = 0; |
| 1179 | + CleanupQueue cleanup_queue_; |
1216 | 1180 | bool started_cleanup_ = false; |
1217 | 1181 |
|
1218 | 1182 | int64_t base_object_count_ = 0; |
|
0 commit comments