mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-01-20 15:30:28 +01:00
Make code lock-less on critical path
This commit is contained in:
parent
190b14e66f
commit
558d37e940
|
|
@ -35,3 +35,4 @@ It does help this project on being supported.
|
|||
- Fix crash on startup when Steam is missing
|
||||
- Fix crash on resume when X360 Controller is in use
|
||||
- Provide currated list of mapping keys in settings (might be extended in the future)
|
||||
- Improve performance on critical loop (code is lock-less)
|
||||
|
|
|
|||
|
|
@ -128,63 +128,62 @@ namespace SteamController
|
|||
}
|
||||
}
|
||||
|
||||
public Profiles.Profile? FindProfile(String name)
|
||||
private bool SelectProfile(Profiles.Profile profile)
|
||||
{
|
||||
return Profiles.Find((profile) => profile.Name == name);
|
||||
lock (this)
|
||||
{
|
||||
var list = OrderedProfiles.ToList();
|
||||
if (!list.Remove(profile))
|
||||
return false;
|
||||
list.Insert(0, profile);
|
||||
orderedProfiles = list;
|
||||
RequestDesktopMode = profile.IsDesktop;
|
||||
|
||||
if (profile.Selected(this))
|
||||
{
|
||||
ProfileChanged(profile);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SelectProfile(String name, bool enable = true)
|
||||
public bool SelectProfile(String name)
|
||||
{
|
||||
var profile = FindProfile(name);
|
||||
var profile = Profiles.Find((profile) => profile.Name == name);
|
||||
if (profile is null)
|
||||
return false;
|
||||
|
||||
var list = OrderedProfiles;
|
||||
list.Remove(profile);
|
||||
list.Insert(0, profile);
|
||||
RequestDesktopMode = profile.IsDesktop;
|
||||
|
||||
if (profile.Selected(this))
|
||||
ProfileChanged(profile);
|
||||
return true;
|
||||
return SelectProfile(profile);
|
||||
}
|
||||
|
||||
public bool SelectNext()
|
||||
{
|
||||
bool firstSelected = false;
|
||||
var profile = OrderedProfiles.
|
||||
Where((profile) => profile.Selected(this)).
|
||||
Skip(1).
|
||||
FirstOrDefault();
|
||||
|
||||
var list = OrderedProfiles;
|
||||
foreach (var profile in list)
|
||||
{
|
||||
if (!profile.Selected(this))
|
||||
continue;
|
||||
|
||||
if (!firstSelected)
|
||||
{
|
||||
firstSelected = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
list.Remove(profile);
|
||||
list.Insert(0, profile);
|
||||
ProfileChanged(profile);
|
||||
return true;
|
||||
}
|
||||
if (profile is not null)
|
||||
return SelectProfile(profile);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ToggleDesktopMode(bool? forceState = null)
|
||||
{
|
||||
var oldProfile = GetCurrentProfile();
|
||||
if (forceState is null)
|
||||
RequestDesktopMode = !RequestDesktopMode;
|
||||
else
|
||||
RequestDesktopMode = forceState.Value;
|
||||
lock (this)
|
||||
{
|
||||
var oldProfile = GetCurrentProfile();
|
||||
if (forceState is null)
|
||||
RequestDesktopMode = !RequestDesktopMode;
|
||||
else
|
||||
RequestDesktopMode = forceState.Value;
|
||||
|
||||
var newProfile = GetCurrentProfile();
|
||||
if (oldProfile != newProfile && newProfile is not null)
|
||||
ProfileChanged(newProfile);
|
||||
var newProfile = GetCurrentProfile();
|
||||
if (oldProfile != newProfile && newProfile is not null)
|
||||
ProfileChanged(newProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace SteamController
|
|||
continue;
|
||||
|
||||
var profileItem = new ToolStripMenuItem(profile.Name);
|
||||
profileItem.Click += delegate { lock (context) { context.SelectProfile(profile.Name); } };
|
||||
profileItem.Click += delegate { context.SelectProfile(profile.Name); };
|
||||
contextMenu.Opening += delegate { profileItem.Checked = context.GetCurrentProfile() == profile; };
|
||||
contextMenu.Items.Add(profileItem);
|
||||
}
|
||||
|
|
@ -149,12 +149,8 @@ namespace SteamController
|
|||
}
|
||||
|
||||
updatesReceived++;
|
||||
|
||||
lock (context)
|
||||
{
|
||||
context.Update();
|
||||
context.Debug();
|
||||
}
|
||||
context.Update();
|
||||
context.Debug();
|
||||
|
||||
if (!context.Enabled)
|
||||
{
|
||||
|
|
@ -179,11 +175,8 @@ namespace SteamController
|
|||
|
||||
private void ContextStateUpdate_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
lock (context)
|
||||
{
|
||||
context.Tick();
|
||||
SharedData_Update();
|
||||
}
|
||||
context.Tick();
|
||||
SharedData_Update();
|
||||
|
||||
if (!context.Mouse.Valid)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue