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

Fixes #2847. CursesDriver doesn't processing response from task threading. #2848

Merged
merged 6 commits into from
Sep 29, 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
1 change: 1 addition & 0 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public override void Refresh ()
Curses.raw ();
Curses.noecho ();
Curses.refresh ();
ProcessWinChange ();
}

private void ProcessWinChange ()
Expand Down
17 changes: 14 additions & 3 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class Watch {
bool poll_dirty = true;
int [] wakeupPipes = new int [2];
static IntPtr ignore = Marshal.AllocHGlobal (1);
static IntPtr readHandle = Marshal.AllocHGlobal (1);
MainLoop mainLoop;
bool winChanged;

Expand All @@ -97,8 +96,8 @@ void IMainLoopDriver.Setup (MainLoop mainLoop)
{
this.mainLoop = mainLoop;
pipe (wakeupPipes);
AddWatch (wakeupPipes [1], Condition.PollIn, ml => {
read (wakeupPipes [1], ignore, readHandle);
AddWatch (wakeupPipes [0], Condition.PollIn, ml => {
read (wakeupPipes [1], ignore, (IntPtr)1);
return true;
});
}
Expand Down Expand Up @@ -176,6 +175,18 @@ bool CheckTimers (bool wait, out int pollTimeout)
if (mainLoop.timeouts.Count > 0) {
pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
if (pollTimeout < 0) {
// This avoids 'poll' waiting infinitely if 'pollTimeout < 0' until some action is detected
// This can occur after IMainLoopDriver.Wakeup is executed where the pollTimeout is less than 0
// and no event occurred in elapsed time when the 'poll' is start running again.
/*
The 'poll' function in the C standard library uses a signed integer as the timeout argument, where:

- A positive value specifies a timeout in milliseconds.
- A value of 0 means the poll function will return immediately, checking for events and not waiting.
- A value of -1 means the poll function will wait indefinitely until an event occurs or an error occurs.
- A negative value other than -1 typically indicates an error.
*/
pollTimeout = 0;
return true;
}
} else
Expand Down
2 changes: 1 addition & 1 deletion UICatalog/Scenarios/Threading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private async void CallLoadItemsAsync ()
LogJob ($"Returned from task Thread:{Thread.CurrentThread.ManagedThreadId} {DateTime.Now}");
_itemsList.SetSource (items);
LogJob ($"Finished populate list view Thread:{Thread.CurrentThread.ManagedThreadId} {DateTime.Now}");
_btnActionCancel.Text = "Load Items";
_btnActionCancel.Text = "Cancelable Load Items";
} else {
LogJob ("Task was canceled!");
}
Expand Down