-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #693 from b-editor/develop
v1.0.0 Preview.2
- Loading branch information
Showing
184 changed files
with
8,144 additions
and
2,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 以下のような再入場を調べるための、デバッグ用のコードです。 | ||
|
||
// using (await lock.LockAsync()) | ||
// { | ||
// await Second(); | ||
// } | ||
|
||
// async Task Second() | ||
// { | ||
// using (await lock.LockAsync()) | ||
// { | ||
// } | ||
// } | ||
|
||
#if !DEBUG | ||
global using MyAsyncLock = Nito.AsyncEx.AsyncLock; | ||
#endif | ||
|
||
namespace Beutl.Api; | ||
|
||
#if DEBUG | ||
public sealed class MyAsyncLock | ||
{ | ||
private readonly SemaphoreSlim _semaphore = new(1, 1); | ||
private readonly Task<IDisposable> _releaser; | ||
|
||
public MyAsyncLock() | ||
{ | ||
_releaser = Task.FromResult<IDisposable>(new Releaser(this)); | ||
} | ||
|
||
public Task<IDisposable> LockAsync(CancellationToken cancellationToken = default) | ||
{ | ||
Task wait = _semaphore.WaitAsync(cancellationToken); | ||
if (wait.IsCompleted) | ||
{ | ||
return _releaser; | ||
} | ||
else | ||
{ | ||
return wait.ContinueWith( | ||
continuationFunction: (_, state) => (IDisposable)state!, | ||
state: _releaser.Result, | ||
cancellationToken: cancellationToken, | ||
continuationOptions: TaskContinuationOptions.ExecuteSynchronously, | ||
scheduler: TaskScheduler.Default); | ||
} | ||
} | ||
|
||
private sealed class Releaser : IDisposable | ||
{ | ||
private readonly MyAsyncLock _mutex; | ||
|
||
public Releaser(MyAsyncLock toRelease) | ||
{ | ||
_mutex = toRelease; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_mutex._semaphore.Release(); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.