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