[PR #5051] [MERGED] Rework TermControl's initialization #26089

Open
opened 2026-01-31 09:13:51 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/5051
Author: @DHowett-MSFT
Created: 3/20/2020
Status: Merged
Merged: 3/26/2020
Merged by: @DHowett-MSFT

Base: masterHead: dev/duhowett/term_control_init


📝 Commits (3)

  • 068f5fa Rework TermControl's initialization
  • f7206c2 Merge remote-tracking branch 'origin/master' into dev/duhowett/term_control_init
  • 7754666 Merge remote-tracking branch 'origin/master' into dev/duhowett/term_control_init

📊 Changes

2 files changed (+215 additions, -194 deletions)

View changed files

📝 src/cascadia/TerminalControl/TermControl.cpp (+211 -189)
📝 src/cascadia/TerminalControl/TermControl.h (+4 -5)

📄 Description

This commit rewrites a large swath of TermControl's initialization code.

  • TermControl now always has a _terminal; it will never be null
  • Event registration for _terminal and any other available-at-init
    fixtures has been moved into the constructor.
  • Event handlers how more uniformly check _closing if they interact
    with the _terminal.
  • Swap chain attachment has been cleaned up and no longer uses a
    coroutine when it's spawned from the UI thread.
    • We have to register the renderer's swapchain change notification
      handler after we set the swap chain, otherwise it'll call us back
      when it initializes itself.
  • InitializeTerminal now happens under the _terminal's write lock
    • Certain things that InitializeTerminal were calling themselves
      attempted to take the lock. They no longer do so.
  • TermControlAutomationPeer cannot take the read lock, because setting
    the scrollbar's Maximum during InitializeTerminal will trigger
    vivification of the automation peer tree; if it attempts to take the
    lock it will deadlock during initialization.
  • BlinkCursor was renamed to CursorTimerTick because it's the "Tick"
    handler for the "CursorTimer".
  • DragDropHandler was converted into a coroutine instead of just
    calling a coroutine.

Caveats:

Terminal may not have a _buffer until InitializeTerminal happens.
There's a nasty coupling between RenderTarget and TextBuffer that means
that we need to have a renderer before we have a buffer.

There's a second nasty coupling between RenderThread and Renderer: we
can't create a RenderThread during construction because it needs to be
given a renderer, and we can't create a Renderer during construction
because it needs a RenderThread. We don't want to kick off a thread
during construction.

Testing:

I wailed on this by opening and closing and resizing terminals and panes
and tabs, up to a hundred open tabs and one tab with 51 panes. I set one
tab to update the title as fast as it possibly could and tested
teardown, zoom, resize, mouse movement, etc. while this was all
happening.

Closes #4613.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/5051 **Author:** [@DHowett-MSFT](https://github.com/DHowett-MSFT) **Created:** 3/20/2020 **Status:** ✅ Merged **Merged:** 3/26/2020 **Merged by:** [@DHowett-MSFT](https://github.com/DHowett-MSFT) **Base:** `master` ← **Head:** `dev/duhowett/term_control_init` --- ### 📝 Commits (3) - [`068f5fa`](https://github.com/microsoft/terminal/commit/068f5fa88a5e9fd1b1ff350df7971a946a00e908) Rework TermControl's initialization - [`f7206c2`](https://github.com/microsoft/terminal/commit/f7206c236ab0506589a9c2cd15f1fef1f704dc88) Merge remote-tracking branch 'origin/master' into dev/duhowett/term_control_init - [`7754666`](https://github.com/microsoft/terminal/commit/77546663d4fdbbf97f2b2bacc8fcb07f01e1f8e0) Merge remote-tracking branch 'origin/master' into dev/duhowett/term_control_init ### 📊 Changes **2 files changed** (+215 additions, -194 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+211 -189) 📝 `src/cascadia/TerminalControl/TermControl.h` (+4 -5) </details> ### 📄 Description This commit rewrites a large swath of TermControl's initialization code. * `TermControl` now _always_ has a `_terminal`; it will never be null * Event registration for `_terminal` and any other available-at-init fixtures has been moved into the constructor. * Event handlers how more uniformly check `_closing` if they interact with the _terminal. * Swap chain attachment has been cleaned up and no longer uses a coroutine when it's spawned from the UI thread. * We have to register the renderer's swapchain change notification handler after we set the swap chain, otherwise it'll call us back when it initializes itself. * `InitializeTerminal` now happens under the `_terminal`'s write lock * Certain things that InitializeTerminal were calling themselves attempted to take the lock. They no longer do so. * TermControlAutomationPeer cannot take the read lock, because setting the scrollbar's `Maximum` during `InitializeTerminal` will trigger vivification of the automation peer tree; if it attempts to take the lock it will deadlock during initialization. * `BlinkCursor` was renamed to `CursorTimerTick` because it's the "Tick" handler for the "CursorTimer". * `DragDropHandler` was converted into a coroutine instead of just _calling_ a coroutine. Caveats: Terminal may not have a `_buffer` until InitializeTerminal happens. There's a nasty coupling between RenderTarget and TextBuffer that means that we need to have a renderer before we have a buffer. There's a second nasty coupling between RenderThread and Renderer: we can't create a RenderThread during construction because it needs to be given a renderer, and we can't create a Renderer during construction because it needs a RenderThread. We don't want to kick off a thread during construction. Testing: I wailed on this by opening and closing and resizing terminals and panes and tabs, up to a hundred open tabs and one tab with 51 panes. I set one tab to update the title as fast as it possibly could and tested teardown, zoom, resize, mouse movement, etc. while this was all happening. Closes #4613. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:13:51 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26089