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 thread_local to declare modpending #28456

Closed

Conversation

gabrielschulhof
Copy link
Contributor

The pointer used to hold an incoming dynamically loaded module's
node::node_module structure needs to be thread-local. So far this was
done with uv_key_set() and uv_key_get(). The language now supports
the thread_local keyword which makes implementing this a lot cleaner.

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

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jun 27, 2019
@@ -243,8 +243,7 @@ using v8::Value;
// Globals per process
static node_module* modlist_internal;
static node_module* modlist_linked;
static uv_once_t init_modpending_once = UV_ONCE_INIT;
static uv_key_t thread_local_modpending;
static thread_local struct node_module* thread_local_modpending = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

Just node_module*, no struct (see lines above), and the = nullptr isn't strictly necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 on the node_module*, but I'd like to keep the initialization because we do a

CHECK_NULL(thread_local_modpending);

later on, and I'm not 100% sure that these variables get initialized on every platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, looks like the variable oughta get zeroed out: https://en.cppreference.com/w/cpp/language/initialization#Static_initialization

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

The pointer used to hold an incoming dynamically loaded module's
`node::node_module` structure needs to be thread-local. So far this was
done with `uv_key_set()` and `uv_key_get()`. The language now supports
the `thread_local` keyword which makes implementing this a lot cleaner.
@gabrielschulhof
Copy link
Contributor Author

Let's see if rebasing makes a difference for the CI.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jul 2, 2019

CI: https://ci.nodejs.org/job/node-test-pull-request/24227/
node-test-commit-windows-fanned and node-test-binary-windows-2 were yellow.

@gabrielschulhof
Copy link
Contributor Author

Landed in d3b10f6.

gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Jul 2, 2019
The pointer used to hold an incoming dynamically loaded module's
`node::node_module` structure needs to be thread-local. So far this was
done with `uv_key_set()` and `uv_key_get()`. The language now supports
the `thread_local` keyword which makes implementing this a lot cleaner.

PR-URL: nodejs#28456
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@gabrielschulhof gabrielschulhof deleted the thread-local-modpending branch July 2, 2019 23:16
targos pushed a commit that referenced this pull request Jul 20, 2019
The pointer used to hold an incoming dynamically loaded module's
`node::node_module` structure needs to be thread-local. So far this was
done with `uv_key_set()` and `uv_key_get()`. The language now supports
the `thread_local` keyword which makes implementing this a lot cleaner.

PR-URL: #28456
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This was referenced Jul 23, 2019
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++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants