Skip to content

Commit

Permalink
Get rid of useless constructions
Browse files Browse the repository at this point in the history
  • Loading branch information
evgTSV authored and ForNeVeR committed Nov 14, 2024
1 parent 124387e commit dcda58a
Showing 1 changed file with 15 additions and 39 deletions.
54 changes: 15 additions & 39 deletions Cesium.Runtime/StdIoFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal record StreamHandle
public int ErrNo { get; set; }
}

private static object _locker = new();
internal static readonly List<StreamHandle> Handles = [];

private const int StdIn = 0;
Expand Down Expand Up @@ -677,56 +676,33 @@ public static int Remove(byte* pathname)
return Handles[(int)handleValue];
}

try
{
lock (_locker)
{
var gchAddr = Marshal.ReadIntPtr(handle);
var gch = GCHandle.FromIntPtr(gchAddr);
var gchAddr = Marshal.ReadIntPtr(handle);
var gch = GCHandle.FromIntPtr(gchAddr);

return gch.Target as StreamHandle;
}
}
catch (InvalidOperationException)
{
return null;
}
return gch.Target as StreamHandle;
}

internal static void* AddStream(StreamHandle stream)
{
lock (_locker)
{
var gch = GCHandle.Alloc(stream);
var handle = GCHandle.ToIntPtr(gch);
var gch = GCHandle.Alloc(stream);
var handle = GCHandle.ToIntPtr(gch);

var ptr = Marshal.AllocHGlobal(sizeof(IntPtr));
Marshal.WriteIntPtr(ptr, handle);
return (void*)ptr;
}
var ptr = Marshal.AllocHGlobal(sizeof(IntPtr));
Marshal.WriteIntPtr(ptr, handle);
return (void*)ptr;
}

internal static bool FreeStream(void* filePtr)
{
try
{
lock (_locker)
{
var handle = (IntPtr)filePtr;
var handle = (IntPtr)filePtr;

var gchAddr = Marshal.ReadIntPtr(handle);
var gch = GCHandle.FromIntPtr(gchAddr);
var gchAddr = Marshal.ReadIntPtr(handle);
var gch = GCHandle.FromIntPtr(gchAddr);

if (gch.Target is not StreamHandle) return false;
if (gch.Target is not StreamHandle) return false;

gch.Free();
Marshal.FreeHGlobal(handle);
return true;
}
}
catch (InvalidOperationException)
{
return false;
}
gch.Free();
Marshal.FreeHGlobal(handle);
return true;
}
}

0 comments on commit dcda58a

Please sign in to comment.