Skip to content

Conversation

joyeecheung
Copy link
Member

This patch split part of the bootstrappers into three files:

  • lib/internal/process/main_thread_only.js: contains bootstrappers
    that can only be run in the main thread, including
    • setupStdio for the main thread that sets up process.stdin,
      process.stdout, process.error that may interact with external
      resources, e.g. TTY/File/Pipe/TCP sockets
    • setupProcessMethods that setup methods changing process-global
      states, e.g. process.chdir, process.umask, process.setuid
    • setupSignalHandlers
    • setupChildProcessIpcChannel that setup process.send for
      child processes.
  • lib/internal/process/worker_thread_only.js: contains bootstrappers
    that can only be run in the worker threads, including
    • setupStdio for the worker thread that are streams to be
      manipulated or piped to the parent thread
  • lib/internal/process/per_thread.js: contains bootstrappers
    that can be run in all threads, including:
    • setupAssert for process.assert
    • setupCpuUsage for process.cpuUsage
    • setupHrtime for process.hrtime and process.hrtime.bigint
    • setupMemoryUsage for process.memoryUsage
    • setupConfig for process.config
    • setupKillAndExit for process.kill and process.exit
    • setupRawDebug for process._rawDebug
    • setupUncaughtExceptionCapture for
      process.setUncaughtExceptionCaptureCallback and
      process.hasUncaughtExceptionCaptureCallback

Hopefully in the future we can sort more bootstrappers in
boostrap/node.js into these three files and further group
them into functions that can be run before creating the
snapshot / after loading the snapshot.

This patch also moves most of the isMainThread conditionals
into the main bootstrapper instead of letting them scattered around
special-casing different implementations.

PR-URL: #21378
Reviewed-By: Gus Caplan me@gus.host
Reviewed-By: Anna Henningsen anna@addaleax.net
Reviewed-By: Jeremiah Senkpiel fishrock123@rocketmail.com

This patch split part of the bootstrappers into three files:

- `lib/internal/process/main_thread_only.js`: contains bootstrappers
  that can only be run in the main thread, including
  - `setupStdio` for the main thread that sets up `process.stdin`,
    `process.stdout`, `process.error` that may interact with external
    resources, e.g. TTY/File/Pipe/TCP sockets
  - `setupProcessMethods` that setup methods changing process-global
    states, e.g. `process.chdir`, `process.umask`, `process.setuid`
  - `setupSignalHandlers`
  - `setupChildProcessIpcChannel` that setup `process.send` for
    child processes.
- `lib/internal/process/worker_thread_only.js`: contains bootstrappers
  that can only be run in the worker threads, including
  - `setupStdio` for the worker thread that are streams to be
    manipulated or piped to the parent thread
- `lib/internal/process/per_thread.js`: contains bootstrappers
    that can be run in all threads, including:
  - `setupAssert` for `process.assert`
  - `setupCpuUsage` for `process.cpuUsage`
  - `setupHrtime` for `process.hrtime` and `process.hrtime.bigint`
  - `setupMemoryUsage` for `process.memoryUsage`
  - `setupConfig` for `process.config`
  - `setupKillAndExit` for `process.kill` and `process.exit`
  - `setupRawDebug` for `process._rawDebug`
  - `setupUncaughtExceptionCapture` for
    `process.setUncaughtExceptionCaptureCallback` and
    `process.hasUncaughtExceptionCaptureCallback`

Hopefully in the future we can sort more bootstrappers in
`boostrap/node.js` into these three files and further group
them into functions that can be run before creating the
snapshot / after loading the snapshot.

This patch also moves most of the `isMainThread` conditionals
into the main bootstrapper instead of letting them scattered around
special-casing different implementations.

PR-URL: nodejs#21378
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. v10.x labels Jul 18, 2018
@joyeecheung
Copy link
Member Author

cc @targos

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

Thanks!

@targos
Copy link
Member

targos commented Jul 18, 2018

targos pushed a commit that referenced this pull request Jul 18, 2018
This patch split part of the bootstrappers into three files:

- `lib/internal/process/main_thread_only.js`: contains bootstrappers
  that can only be run in the main thread, including
  - `setupStdio` for the main thread that sets up `process.stdin`,
    `process.stdout`, `process.error` that may interact with external
    resources, e.g. TTY/File/Pipe/TCP sockets
  - `setupProcessMethods` that setup methods changing process-global
    states, e.g. `process.chdir`, `process.umask`, `process.setuid`
  - `setupSignalHandlers`
  - `setupChildProcessIpcChannel` that setup `process.send` for
    child processes.
- `lib/internal/process/worker_thread_only.js`: contains bootstrappers
  that can only be run in the worker threads, including
  - `setupStdio` for the worker thread that are streams to be
    manipulated or piped to the parent thread
- `lib/internal/process/per_thread.js`: contains bootstrappers
    that can be run in all threads, including:
  - `setupAssert` for `process.assert`
  - `setupCpuUsage` for `process.cpuUsage`
  - `setupHrtime` for `process.hrtime` and `process.hrtime.bigint`
  - `setupMemoryUsage` for `process.memoryUsage`
  - `setupConfig` for `process.config`
  - `setupKillAndExit` for `process.kill` and `process.exit`
  - `setupRawDebug` for `process._rawDebug`
  - `setupUncaughtExceptionCapture` for
    `process.setUncaughtExceptionCaptureCallback` and
    `process.hasUncaughtExceptionCaptureCallback`

Hopefully in the future we can sort more bootstrappers in
`boostrap/node.js` into these three files and further group
them into functions that can be run before creating the
snapshot / after loading the snapshot.

This patch also moves most of the `isMainThread` conditionals
into the main bootstrapper instead of letting them scattered around
special-casing different implementations.

PR-URL: #21378
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>

Backport-PR-URL: #21866
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@targos
Copy link
Member

targos commented Jul 18, 2018

Landed in 581390c

@targos targos closed this Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / src Issues and PRs related to general changes in the lib or src directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants