Compare commits

...

3 Commits

Author SHA1 Message Date
Dustin L. Howett
84ae7adec6 OS PR 14890400: fix defects caught with strict compiler switches (#20100)
Related work items: MSFT-53015560

Co-authored-by: Sudhakar Prabhu <sprabhu@microsoft.com>
2026-04-10 11:41:03 -07:00
Dustin L. Howett
a6ebdd3d4a render: check the thread exit condition after every long operation (#20097)
We have received an internal report that teardown on OneCore is still
hanging. It looks like there's a chance that `TriggerTeardown` is called
during `PaintFrame`, which may result in `_threadShouldKeepRunning`
getting set to `false` (TriggerTeardown) and `_redraw` being set to
`false` as well (PaintFrame). The thread will wait forever on `_redraw`
to be signalled, which it never will, because `TriggerTeardown` is
waiting for the thread to exit.

That is:

```
Render Thread      | ConIoSrv Thread
------------------------------------
Check _enabled     |
Wait on _redraw    |
Check _keepRunning | TriggerTeardown
Paint              |   _keepRunning = false
                   |   _redraw = true
    _redraw = false|   Signal _enabled
Paint Completes    |   Wait on thread
Check _enabled     |
Wait on _redraw    |
**DEADLOCK**       | **DEADLOCK**
                   v
```

This may not be an ideal fix, but at least it checks
`_threadShouldKeepRunning` after every "long" operation (waiting and
painting) now.
2026-04-09 16:34:09 -05:00
Dustin L. Howett
031998bfc3 Track the cursor dirty flag in the correct buffer (#20095)
Failure to do so will result in every console API requiring a cursor
update stalling for 500ms because we sent the update to the wrong
buffer.

Closes #20092
2026-04-08 22:08:28 +00:00
7 changed files with 14 additions and 13 deletions

View File

@@ -350,7 +350,7 @@ void ROW::_init() noexcept
std::iota(_charOffsets.begin(), _charOffsets.end(), uint16_t{ 0 });
#endif
#pragma warning(push)
#pragma warning(pop)
}
void ROW::CopyFrom(const ROW& source)

View File

@@ -67,7 +67,7 @@ void FontTests::TestCurrentFontAPIsInvalid()
}
else
{
hConsoleOutput = (HANDLE)dwConsoleOutput;
hConsoleOutput = ULongToHandle(dwConsoleOutput);
}
if (strOperation == L"Get")
@@ -107,7 +107,7 @@ void FontTests::TestGetFontSizeInvalid()
// Need to make sure that last error is cleared so that we can verify that lasterror was set by GetConsoleFontSize
SetLastError(0);
auto coordFontSize = OneCoreDelay::GetConsoleFontSize((HANDLE)dwConsoleOutput, 0);
auto coordFontSize = OneCoreDelay::GetConsoleFontSize(ULongToHandle(dwConsoleOutput), 0);
VERIFY_ARE_EQUAL(coordFontSize, c_coordZero, L"Ensure (0,0) coord returned to indicate failure");
VERIFY_ARE_EQUAL(GetLastError(), (DWORD)ERROR_INVALID_HANDLE, L"Ensure last error was set appropriately");
}

View File

@@ -36,7 +36,7 @@ void ConhostInternalGetSet::UnknownSequence() noexcept
// us from using a more conservative solution (e.g. always fetching the cursor position).
if (gci.IsInVtIoMode())
{
gci.GetActiveOutputBuffer().SetConptyCursorPositionMayBeWrong();
gci.GetActiveOutputBuffer().GetActiveBuffer().SetConptyCursorPositionMayBeWrong();
}
}

View File

@@ -6,8 +6,3 @@
TARGETNAME = ConInteractivityOneCoreLib
TARGETTYPE = LIBRARY
# VSTS 14847240: Locally suppress individual -Wv:17 compiler warnings.
# For more information, visit https://osgwiki.com/wiki/Windows_C%2B%2B_Toolset_Status.
USER_C_FLAGS=$(USER_C_FLAGS) /wd4302 # 'conversion': truncation from 'type1' to 'type2'
USER_C_FLAGS=$(USER_C_FLAGS) /wd4311 # 'variable': pointer truncation from 'type 1' to 'type 2'

View File

@@ -119,12 +119,15 @@ DWORD WINAPI Renderer::s_renderThread(void* param) noexcept
DWORD Renderer::_renderThread() noexcept
{
while (true)
while (_threadKeepRunning.load(std::memory_order_relaxed))
{
_enable.wait();
_waitUntilCanRender();
_waitUntilTimerOrRedraw();
// We just completed what could have been a long wait;
// eagerly check again to prevent rendering if we don't
// need to.
if (!_threadKeepRunning.load(std::memory_order_relaxed))
{
break;

View File

@@ -595,9 +595,12 @@ constexpr T saturate(auto val)
RETURN_IF_FAILED(pObjectHandle->GetScreenBuffer(GENERIC_READ, &pObj));
// See ConptyCursorPositionMayBeWrong() for details.
if (pObj->ConptyCursorPositionMayBeWrong())
auto& activeBuffer = pObj->GetActiveBuffer();
// GetConsoleScreenBufferInfoExImpl uses GetActiveBuffer internally, but
// under the console lock.
if (activeBuffer.ConptyCursorPositionMayBeWrong())
{
pObj->WaitForConptyCursorPositionToBeSynchronized();
activeBuffer.WaitForConptyCursorPositionToBeSynchronized();
}
m->_pApiRoutines->GetConsoleScreenBufferInfoExImpl(*pObj, ex);

View File

@@ -166,7 +166,7 @@ void InteractDispatch::MoveCursor(const VTInt row, const VTInt col)
// Unblock any callers inside SCREEN_INFORMATION::WaitForConptyCursorPositionToBeSynchronized().
// The cursor position has now been updated to the terminal's.
info.ResetConptyCursorPositionMayBeWrong();
info.GetActiveBuffer().ResetConptyCursorPositionMayBeWrong();
}
// Routine Description: