mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-19 00:51:30 -07:00
Improve mutex stuff?
idk i cant really find anything else wrong with it
This commit is contained in:
parent
7a963c53f7
commit
5741d82f3d
@ -119,6 +119,8 @@ namespace Bloxstrap
|
||||
|
||||
App.Logger.WriteLine(LOG_IDENT, "Performing connectivity check...");
|
||||
|
||||
SetStatus("Connecting to Roblox...");
|
||||
|
||||
try
|
||||
{
|
||||
await RobloxDeployment.GetInfo(RobloxDeployment.DefaultChannel);
|
||||
@ -158,8 +160,9 @@ namespace Bloxstrap
|
||||
|
||||
try
|
||||
{
|
||||
Mutex.OpenExisting("Bloxstrap_BootstrapperMutex").Close();
|
||||
App.Logger.WriteLine(LOG_IDENT, "Bloxstrap_BootstrapperMutex mutex exists, waiting...");
|
||||
Mutex.OpenExisting("Bloxstrap_SingletonMutex").Close();
|
||||
App.Logger.WriteLine(LOG_IDENT, "Bloxstrap_SingletonMutex mutex exists, waiting...");
|
||||
SetStatus("Waiting for other instances...");
|
||||
mutexExists = true;
|
||||
}
|
||||
catch (Exception)
|
||||
@ -168,7 +171,7 @@ namespace Bloxstrap
|
||||
}
|
||||
|
||||
// wait for mutex to be released if it's not yet
|
||||
await using AsyncMutex mutex = new("Bloxstrap_BootstrapperMutex");
|
||||
await using var mutex = new AsyncMutex(true, "Bloxstrap_SingletonMutex");
|
||||
await mutex.AcquireAsync(_cancelTokenSource.Token);
|
||||
|
||||
// reload our configs since they've likely changed by now
|
||||
@ -219,8 +222,6 @@ namespace Bloxstrap
|
||||
{
|
||||
const string LOG_IDENT = "Bootstrapper::CheckLatestVersion";
|
||||
|
||||
SetStatus("Connecting to Roblox...");
|
||||
|
||||
ClientVersion clientVersion;
|
||||
|
||||
try
|
||||
|
@ -4,13 +4,15 @@
|
||||
|
||||
public sealed class AsyncMutex : IAsyncDisposable
|
||||
{
|
||||
private readonly bool _initiallyOwned;
|
||||
private readonly string _name;
|
||||
private Task? _mutexTask;
|
||||
private ManualResetEventSlim? _releaseEvent;
|
||||
private CancellationTokenSource? _cancellationTokenSource;
|
||||
|
||||
public AsyncMutex(string name)
|
||||
public AsyncMutex(bool initiallyOwned, string name)
|
||||
{
|
||||
_initiallyOwned = initiallyOwned;
|
||||
_name = name;
|
||||
}
|
||||
|
||||
@ -31,7 +33,7 @@
|
||||
try
|
||||
{
|
||||
CancellationToken cancellationToken = _cancellationTokenSource.Token;
|
||||
using var mutex = new Mutex(false, _name);
|
||||
using var mutex = new Mutex(_initiallyOwned, _name);
|
||||
try
|
||||
{
|
||||
// Wait for either the mutex to be acquired, or cancellation
|
||||
|
Loading…
Reference in New Issue
Block a user