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 uint32_t for process initialization flags enum #46427

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,13 @@ void ResetSignalHandlers() {
#endif // __POSIX__
}

// We use uint32_t since that can be accessed as a lock-free atomic
// variable on all platforms that we support, which we require in
// order for its value to be usable inside signal handlers.
static std::atomic<uint32_t> init_process_flags = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a comment here describing why we use a uint32_t?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, makes sense – done in c259b3b!

static_assert(
std::is_same_v<std::underlying_type_t<ProcessInitializationFlags::Flags>,
uint32_t>);

static void PlatformInit(ProcessInitializationFlags::Flags flags) {
// init_process_flags is accessed in ResetStdio(),
Expand Down Expand Up @@ -1057,7 +1063,7 @@ std::unique_ptr<InitializationResult> InitializeOncePerProcess(
}

void TearDownOncePerProcess() {
const uint64_t flags = init_process_flags.load();
const uint32_t flags = init_process_flags.load();
ResetStdio();
if (!(flags & ProcessInitializationFlags::kNoDefaultSignalHandling)) {
ResetSignalHandlers();
Expand Down
11 changes: 4 additions & 7 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,8 @@ class Environment;
class MultiIsolatePlatform;
class InitializationResultImpl;

namespace ProcessFlags {
// TODO(addaleax): Switch to uint32_t to match std::atomic<uint32_t>
// init_process_flags in node.cc
enum Flags : uint64_t {
namespace ProcessInitializationFlags {
enum Flags : uint32_t {
kNoFlags = 0,
// Enable stdio inheritance, which is disabled by default.
// This flag is also implied by kNoStdioInitialization.
Expand Down Expand Up @@ -270,9 +268,8 @@ enum Flags : uint64_t {
kNoParseGlobalDebugVariables | kNoAdjustResourceLimits |
kNoUseLargePages | kNoPrintHelpOrVersionOutput,
};
} // namespace ProcessFlags
// TODO(addaleax): Make this the canonical name, as it is more descriptive.
namespace ProcessInitializationFlags = ProcessFlags;
} // namespace ProcessInitializationFlags
namespace ProcessFlags = ProcessInitializationFlags; // Legacy alias.

class NODE_EXTERN InitializationResult {
public:
Expand Down