mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
CmdPal: Adding a lock around perf monitor updates (#46061)
Based on reported bug in Teams. Added lock around OnLoadBasePage._loadCount and modified PerformanceWidgetPage to use Interlocked.Increment/Decrement on _loadCount. --------- Co-authored-by: leileizhang <leilzh@microsoft.com> Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: moooyo <42196638+moooyo@users.noreply.github.com> Co-authored-by: Yu Leng <yuleng@microsoft.com> Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com> Co-authored-by: Jiří Polášek <me@jiripolasek.com> Co-authored-by: Shawn Yuan <128874481+shuaiyuanxx@users.noreply.github.com> Co-authored-by: Gordon Lam <73506701+yeelam-gordon@users.noreply.github.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Mike Hall <mikehall@microsoft.com> Co-authored-by: vanzue <vanzue@outlook.com> Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Co-authored-by: Thanh Nguyen <74597207+ThanhNguyxn@users.noreply.github.com> Co-authored-by: Zach Teutsch <88554871+zateutsch@users.noreply.github.com>
This commit is contained in:
@@ -14,7 +14,6 @@ void MonitorTopology::Initialize(const std::vector<MonitorInfo>& monitors)
|
||||
Logger::info(L"======= TOPOLOGY INITIALIZATION START =======");
|
||||
Logger::info(L"Initializing edge-based topology for {} monitors", monitors.size());
|
||||
|
||||
|
||||
m_monitors = monitors;
|
||||
m_outerEdges.clear();
|
||||
m_edgeMap.clear();
|
||||
@@ -692,7 +691,6 @@ int MonitorTopology::GetAbsolutePosition(const MonitorEdge& edge, double relativ
|
||||
return static_cast<int>(result);
|
||||
}
|
||||
|
||||
|
||||
std::vector<MonitorTopology::GapInfo> MonitorTopology::DetectMonitorGaps() const
|
||||
{
|
||||
std::vector<GapInfo> gaps;
|
||||
|
||||
@@ -19,7 +19,6 @@ public sealed partial class AppListItem : ListItem, IPrecomputedListItem
|
||||
{
|
||||
private readonly AppCommand _appCommand;
|
||||
private readonly AppItem _app;
|
||||
|
||||
private readonly Lazy<Task<IconInfo?>> _iconLoadTask;
|
||||
private readonly Lazy<Task<Details>> _detailsLoadTask;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Foundation;
|
||||
@@ -70,6 +71,7 @@ internal abstract partial class OnLoadContentPage : OnLoadBasePage, IContentPage
|
||||
|
||||
internal abstract partial class OnLoadBasePage : Page
|
||||
{
|
||||
private readonly Lock _loadLock = new();
|
||||
private int _loadCount;
|
||||
|
||||
#pragma warning disable CS0067 // The event is never used
|
||||
@@ -82,22 +84,28 @@ internal abstract partial class OnLoadBasePage : Page
|
||||
add
|
||||
{
|
||||
InternalItemsChanged += value;
|
||||
if (_loadCount == 0)
|
||||
lock (_loadLock)
|
||||
{
|
||||
Loaded();
|
||||
}
|
||||
if (_loadCount == 0)
|
||||
{
|
||||
Loaded();
|
||||
}
|
||||
|
||||
_loadCount++;
|
||||
_loadCount++;
|
||||
}
|
||||
}
|
||||
|
||||
remove
|
||||
{
|
||||
InternalItemsChanged -= value;
|
||||
_loadCount--;
|
||||
_loadCount = Math.Max(0, _loadCount);
|
||||
if (_loadCount == 0)
|
||||
lock (_loadLock)
|
||||
{
|
||||
Unloaded();
|
||||
_loadCount--;
|
||||
_loadCount = Math.Max(0, _loadCount);
|
||||
if (_loadCount == 0)
|
||||
{
|
||||
Unloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Threading;
|
||||
using CoreWidgetProvider.Helpers;
|
||||
using CoreWidgetProvider.Widgets.Enums;
|
||||
using Microsoft.CmdPal.Common;
|
||||
@@ -262,17 +263,17 @@ internal abstract partial class WidgetPage : OnLoadContentPage
|
||||
/// </summary>
|
||||
internal virtual void PushActivate()
|
||||
{
|
||||
_loadCount++;
|
||||
Interlocked.Increment(ref _loadCount);
|
||||
}
|
||||
|
||||
internal virtual void PopActivate()
|
||||
{
|
||||
_loadCount--;
|
||||
Interlocked.Decrement(ref _loadCount);
|
||||
}
|
||||
|
||||
private int _loadCount;
|
||||
|
||||
protected bool IsActive => _loadCount > 0;
|
||||
protected bool IsActive => Volatile.Read(ref _loadCount) > 0;
|
||||
|
||||
protected override void Loaded()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user