mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 18:15:44 +00:00
Use private readonly object for locking
This commit is contained in:
parent
6fc811bc39
commit
29f40b88af
1 changed files with 4 additions and 6 deletions
|
|
@ -7,10 +7,12 @@ namespace FFMpegCore.Arguments;
|
||||||
public abstract class PipeArgument
|
public abstract class PipeArgument
|
||||||
{
|
{
|
||||||
private readonly PipeDirection _direction;
|
private readonly PipeDirection _direction;
|
||||||
|
private readonly object _pipeLock;
|
||||||
|
|
||||||
protected PipeArgument(PipeDirection direction)
|
protected PipeArgument(PipeDirection direction)
|
||||||
{
|
{
|
||||||
PipeName = PipeHelpers.GetUnqiuePipeName();
|
PipeName = PipeHelpers.GetUnqiuePipeName();
|
||||||
|
_pipeLock = new object();
|
||||||
_direction = direction;
|
_direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,7 +35,7 @@ public abstract class PipeArgument
|
||||||
public void Post()
|
public void Post()
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
||||||
lock (Pipe)
|
lock (_pipeLock)
|
||||||
{
|
{
|
||||||
Pipe?.Dispose();
|
Pipe?.Dispose();
|
||||||
Pipe = null!;
|
Pipe = null!;
|
||||||
|
|
@ -53,11 +55,7 @@ public abstract class PipeArgument
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
||||||
|
lock (_pipeLock)
|
||||||
//if Pipe is null, then the lock doesnt matter,
|
|
||||||
//Because the next code will not execute anyways.
|
|
||||||
//so we can use a new object
|
|
||||||
lock (Pipe ?? new object())
|
|
||||||
{
|
{
|
||||||
if (Pipe is { IsConnected: true })
|
if (Pipe is { IsConnected: true })
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue