Repository navigation
src: implement MemoryRetainer in Environment #27018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixup! src: implement MemoryRetainer in Environment
- Loading branch information
commit 81203f66b4ad962ba358e387b09a95419c7e73c1
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -739,6 +739,36 @@ class ShouldNotAbortOnUncaughtScope { | |
| Environment* env_; | ||
| }; | ||
|
|
||
| class CleanupHookCallback { | ||
| public: | ||
| CleanupHookCallback(void (*fn)(void*), | ||
| void* arg, | ||
| uint64_t insertion_order_counter) | ||
| : fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {} | ||
|
|
||
| // Only hashes `arg_`, since that is usually enough to identify the hook. | ||
| struct Hash { | ||
| inline size_t operator()(const CleanupHookCallback& cb) const; | ||
| }; | ||
|
|
||
| // Compares by `fn_` and `arg_` being equal. | ||
| struct Equal { | ||
| inline bool operator()(const CleanupHookCallback& a, | ||
| const CleanupHookCallback& b) const; | ||
| }; | ||
|
|
||
| inline BaseObject* GetBaseObject() const; | ||
|
|
||
| private: | ||
| friend class Environment; | ||
| void (*fn_)(void*); | ||
| void* arg_; | ||
|
|
||
| // We keep track of the insertion order for these objects, so that we can | ||
| // call the callbacks in reverse order when we are cleaning up. | ||
| uint64_t insertion_order_counter_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make these fields
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copied from the previous implementation so I'd prefer to leave this to another patch.. |
||
| }; | ||
|
|
||
| class Environment : public MemoryRetainer { | ||
| public: | ||
| Environment(const Environment&) = delete; | ||
|
|
@@ -1224,42 +1254,6 @@ class Environment : public MemoryRetainer { | |
| void RunAndClearNativeImmediates(); | ||
| static void CheckImmediate(uv_check_t* handle); | ||
|
|
||
| class CleanupHookCallback : public MemoryRetainer { | ||
| public: | ||
| CleanupHookCallback(void (*fn)(void*), | ||
| void* arg, | ||
| uint64_t insertion_order_counter) | ||
| : fn_(fn), | ||
| arg_(arg), | ||
| insertion_order_counter_(insertion_order_counter) {} | ||
|
|
||
| // Only hashes `arg_`, since that is usually enough to identify the hook. | ||
| struct Hash { | ||
| inline size_t operator()(const CleanupHookCallback& cb) const; | ||
| }; | ||
|
|
||
| // Compares by `fn_` and `arg_` being equal. | ||
| struct Equal { | ||
| inline bool operator()(const CleanupHookCallback& a, | ||
| const CleanupHookCallback& b) const; | ||
| }; | ||
|
|
||
| SET_MEMORY_INFO_NAME(CleanupHookCallback); | ||
| SET_SELF_SIZE(CleanupHookCallback); | ||
| void MemoryInfo(MemoryTracker* tracker) const override; | ||
|
|
||
| inline BaseObject* GetBaseObject() const; | ||
|
|
||
| private: | ||
| friend class Environment; | ||
| void (*fn_)(void*); | ||
| void* arg_; | ||
|
|
||
| // We keep track of the insertion order for these objects, so that we can | ||
| // call the callbacks in reverse order when we are cleaning up. | ||
| uint64_t insertion_order_counter_; | ||
| }; | ||
|
|
||
| // Use an unordered_set, so that we have efficient insertion and removal. | ||
| std::unordered_set<CleanupHookCallback, | ||
| CleanupHookCallback::Hash, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.