★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/17083Nouvelle recherche | Portail wanayoo
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: use unique_ptr for scheduled delayed tasks #17083

Conversation

Copy link
Member

@fhinkel fhinkel commented Nov 16, 2017

Use std::unique_ptr for delayed tasks in the scheduled
delayed tasks vector. This makes it clear that the vector
has ownership of the delayed tasks and is responsible for
deleting them.

Use a custom deleter for the pointers because libuv
needs to close the handle and then delete the data. Provide
the handle when creating the pointer instead of invoking the
special delete action everytime an element is removed from the vector.

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

src

@nodejs-github-bot nodejs-github-bot added the c++ label Nov 16, 2017
scheduled_delayed_tasks_.emplace_back(delayed.release(),
[](DelayedTask* delayed) {
uv_close(reinterpret_cast<uv_handle_t*>(&delayed->timer),
[](uv_handle_t* handle) {
Copy link
Member

@addaleax addaleax Nov 16, 2017

Choose a reason for hiding this comment

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

Does the linter complain if you align arguments vertically?


// Use a custom deleter because libuv needs to close the handle first.
typedef std::unique_ptr<DelayedTask, std::function<void(DelayedTask*)>>
DelayedScheduledTask;
Copy link
Member

@addaleax addaleax Nov 16, 2017

Choose a reason for hiding this comment

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

Can you call this DelayedTaskPointer or something like that? Just to make clear it’s still a pointer and it’s not a conceptually different kind of thing

Use std::unique_ptr for delayed tasks in the scheduled
delayed tasks vector. This makes it clear that the vector
has ownership of the delayed tasks and is responsible for
deleting them.

Use a custom deleter for the pointers because libuv
needs to close the handle and then delete the data. Provide
the handle when creating the pointer instead of invoking the
special delete action everytime an element is removed from the vector.
@fhinkel fhinkel force-pushed the nov/refactor_delete_from_scheduled_tasks branch from a7cc724 to 8fe4791 Compare Nov 16, 2017
@fhinkel
Copy link
Member Author

@fhinkel fhinkel commented Nov 19, 2017

Landed in 24e824a.

@fhinkel fhinkel closed this Nov 19, 2017
fhinkel added a commit that referenced this issue Nov 19, 2017
Use std::unique_ptr for delayed tasks in the scheduled
delayed tasks vector. This makes it clear that the vector
has ownership of the delayed tasks and is responsible for
deleting them.

Use a custom deleter for the pointers because libuv
needs to close the handle and then delete the data. Provide
the handle when creating the pointer instead of invoking the
special delete action everytime an element is removed from the vector.

PR-URL: #17083
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@addaleax
Copy link
Member

@addaleax addaleax commented Nov 19, 2017

@fhinkel Looks like this is the commit that is actually breaking CI :(

addaleax added a commit to addaleax/node that referenced this issue Nov 19, 2017
addaleax added a commit that referenced this issue Nov 19, 2017
PR-URL: #17133
Refs: #17083
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
MylesBorins pushed a commit that referenced this issue Dec 12, 2017
Use std::unique_ptr for delayed tasks in the scheduled
delayed tasks vector. This makes it clear that the vector
has ownership of the delayed tasks and is responsible for
deleting them.

Use a custom deleter for the pointers because libuv
needs to close the handle and then delete the data. Provide
the handle when creating the pointer instead of invoking the
special delete action everytime an element is removed from the vector.

PR-URL: #17083
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this issue Dec 12, 2017
PR-URL: #17133
Refs: #17083
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
@MylesBorins MylesBorins mentioned this pull request Dec 12, 2017
@gibfahn
Copy link
Member

@gibfahn gibfahn commented Dec 19, 2017

@fhinkel would you mind raising a backport for this and #17133 on v8.x?

@MylesBorins
Copy link
Member

@MylesBorins MylesBorins commented Dec 19, 2017

The files changed in this PR do not exist on v6.x

Please feel free to change label if it can be manually backported

@MylesBorins
Copy link
Member

@MylesBorins MylesBorins commented May 22, 2018

ping @fhinkel re: backport

addaleax pushed a commit to addaleax/node that referenced this issue May 22, 2018
Use std::unique_ptr for delayed tasks in the scheduled
delayed tasks vector. This makes it clear that the vector
has ownership of the delayed tasks and is responsible for
deleting them.

Use a custom deleter for the pointers because libuv
needs to close the handle and then delete the data. Provide
the handle when creating the pointer instead of invoking the
special delete action everytime an element is removed from the vector.

PR-URL: nodejs#17083
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@addaleax
Copy link
Member

@addaleax addaleax commented May 22, 2018

Included a backport in #20901

MylesBorins pushed a commit that referenced this issue Jun 14, 2018
Use std::unique_ptr for delayed tasks in the scheduled
delayed tasks vector. This makes it clear that the vector
has ownership of the delayed tasks and is responsible for
deleting them.

Use a custom deleter for the pointers because libuv
needs to close the handle and then delete the data. Provide
the handle when creating the pointer instead of invoking the
special delete action everytime an element is removed from the vector.

Backport-PR-URL: #20901
PR-URL: #17083
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorins MylesBorins mentioned this pull request Jul 9, 2018
rvagg pushed a commit that referenced this issue Aug 16, 2018
Use std::unique_ptr for delayed tasks in the scheduled
delayed tasks vector. This makes it clear that the vector
has ownership of the delayed tasks and is responsible for
deleting them.

Use a custom deleter for the pointers because libuv
needs to close the handle and then delete the data. Provide
the handle when creating the pointer instead of invoking the
special delete action everytime an element is removed from the vector.

Backport-PR-URL: #20901
PR-URL: #17083
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@addaleax addaleax added the v8 platform label Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ v8 platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants