Skip to content
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

src: allow generic C++ callables in SetImmediate() #28704

Closed

Conversation

addaleax
Copy link
Member

Modify the native SetImmediate() functions to take generic C++
callables as arguments. This makes passing arguments to the callback
easier, and in particular, it allows passing std::unique_ptrs
directly, which in turn makes sure that the data they point to is
deleted if the Environment is torn down before the callback can run.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Jul 15, 2019
@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added the wip Issues and PRs that are still a work in progress. label Jul 15, 2019
@addaleax addaleax force-pushed the native-immediate-type-erasure branch from ff700c2 to 0386696 Compare July 15, 2019 22:35
@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax force-pushed the native-immediate-type-erasure branch from 0386696 to 3cf4e25 Compare July 20, 2019 15:25
static_cast<PerformanceGCKind>(type),
state->performance_last_gc_start_mark,
PERFORMANCE_NOW());
env->SetUnrefImmediate([entry = std::move(entry)](Environment* env) mutable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need mutable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because here entry is moved again out of the function, and so it needs to be modifiable – Do you think a comment would help/be necessary here?

@addaleax
Copy link
Member Author

Fwiw, I requested access to CI machines for debugging in nodejs/build#1875 because I really can’t figure out why this would crash, although it’s (probably?) a problem with the relatively overseeable N-API bits here.

@nodejs-github-bot
Copy link
Collaborator

Modify the native `SetImmediate()` functions to take generic C++
callables as arguments. This makes passing arguments to the callback
easier, and in particular, it allows passing `std::unique_ptr`s
directly, which in turn makes sure that the data they point to is
deleted if the `Environment` is torn down before the callback can run.
@addaleax addaleax force-pushed the native-immediate-type-erasure branch from 6c0712f to 9d04047 Compare July 26, 2019 20:12
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added review wanted PRs that need reviews. and removed wip Issues and PRs that are still a work in progress. labels Jul 28, 2019
@nodejs-github-bot
Copy link
Collaborator

@addaleax
Copy link
Member Author

CI is yellow, so I think this could use a review :)

@addaleax
Copy link
Member Author

Landed in 5207dec

@addaleax addaleax closed this Jul 31, 2019
@addaleax addaleax deleted the native-immediate-type-erasure branch July 31, 2019 23:41
addaleax added a commit that referenced this pull request Jul 31, 2019
Modify the native `SetImmediate()` functions to take generic C++
callables as arguments. This makes passing arguments to the callback
easier, and in particular, it allows passing `std::unique_ptr`s
directly, which in turn makes sure that the data they point to is
deleted if the `Environment` is torn down before the callback can run.

PR-URL: #28704
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Aug 2, 2019
Modify the native `SetImmediate()` functions to take generic C++
callables as arguments. This makes passing arguments to the callback
easier, and in particular, it allows passing `std::unique_ptr`s
directly, which in turn makes sure that the data they point to is
deleted if the `Environment` is torn down before the callback can run.

PR-URL: #28704
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. review wanted PRs that need reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants