|
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 "handle_wrap.h" |
35 | 36 | #include "node.h" |
@@ -922,38 +923,6 @@ class ShouldNotAbortOnUncaughtScope { |
922 | 923 | Environment* env_; |
923 | 924 | }; |
924 | 925 |
|
925 | | -class CleanupHookCallback { |
926 | | - public: |
927 | | - typedef void (*Callback)(void*); |
928 | | - |
929 | | - CleanupHookCallback(Callback fn, |
930 | | - void* arg, |
931 | | - uint64_t insertion_order_counter) |
932 | | - : fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {} |
933 | | - |
934 | | - // Only hashes `arg_`, since that is usually enough to identify the hook. |
935 | | - struct Hash { |
936 | | - inline size_t operator()(const CleanupHookCallback& cb) const; |
937 | | - }; |
938 | | - |
939 | | - // Compares by `fn_` and `arg_` being equal. |
940 | | - struct Equal { |
941 | | - inline bool operator()(const CleanupHookCallback& a, |
942 | | - const CleanupHookCallback& b) const; |
943 | | - }; |
944 | | - |
945 | | - inline BaseObject* GetBaseObject() const; |
946 | | - |
947 | | - private: |
948 | | - friend class Environment; |
949 | | - Callback fn_; |
950 | | - void* arg_; |
951 | | - |
952 | | - // We keep track of the insertion order for these objects, so that we can |
953 | | - // call the callbacks in reverse order when we are cleaning up. |
954 | | - uint64_t insertion_order_counter_; |
955 | | -}; |
956 | | - |
957 | 926 | typedef void (*DeserializeRequestCallback)(v8::Local<v8::Context> context, |
958 | 927 | v8::Local<v8::Object> holder, |
959 | 928 | int index, |
@@ -1413,9 +1382,8 @@ class Environment : public MemoryRetainer { |
1413 | 1382 | void ScheduleTimer(int64_t duration); |
1414 | 1383 | void ToggleTimerRef(bool ref); |
1415 | 1384 |
|
1416 | | - using CleanupCallback = CleanupHookCallback::Callback; |
1417 | | - inline void AddCleanupHook(CleanupCallback cb, void* arg); |
1418 | | - inline void RemoveCleanupHook(CleanupCallback cb, void* arg); |
| 1385 | + inline void AddCleanupHook(CleanupQueue::Callback cb, void* arg); |
| 1386 | + inline void RemoveCleanupHook(CleanupQueue::Callback cb, void* arg); |
1419 | 1387 | void RunCleanup(); |
1420 | 1388 |
|
1421 | 1389 | static size_t NearHeapLimitCallback(void* data, |
@@ -1626,11 +1594,7 @@ class Environment : public MemoryRetainer { |
1626 | 1594 |
|
1627 | 1595 | BindingDataStore bindings_; |
1628 | 1596 |
|
1629 | | - // Use an unordered_set, so that we have efficient insertion and removal. |
1630 | | - std::unordered_set<CleanupHookCallback, |
1631 | | - CleanupHookCallback::Hash, |
1632 | | - CleanupHookCallback::Equal> cleanup_hooks_; |
1633 | | - uint64_t cleanup_hook_counter_ = 0; |
| 1597 | + CleanupQueue cleanup_queue_; |
1634 | 1598 | bool started_cleanup_ = false; |
1635 | 1599 |
|
1636 | 1600 | int64_t base_object_count_ = 0; |
|
0 commit comments