Skip to content

Commit

Permalink
src: use uint32_t for process initialization flags enum
Browse files Browse the repository at this point in the history
Refs: #45221
PR-URL: #46427
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
addaleax authored Feb 2, 2023
1 parent 1579ff4 commit f84de0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
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;
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

0 comments on commit f84de0a

Please sign in to comment.