mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 05:58:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
37
Brutal.OpenAl/Manual/Context.Internal.cs
Normal file
37
Brutal.OpenAl/Manual/Context.Internal.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Brutal.OpenAlApi;
|
||||
|
||||
public sealed partial class Context
|
||||
{
|
||||
// Weak so an abandoned wrapper is never kept alive; leaked entries are pruned on registration.
|
||||
private static readonly ConcurrentDictionary<AlcContext.Handle, WeakReference<Context>> LiveContexts = new();
|
||||
|
||||
internal static List<Context> EvictDeviceEntries(Device device)
|
||||
{
|
||||
List<Context> orphans = [];
|
||||
|
||||
foreach (var entry in LiveContexts)
|
||||
{
|
||||
if (!entry.Value.TryGetTarget(out var context))
|
||||
{
|
||||
LiveContexts.TryRemove(entry);
|
||||
Al.EvictContextRoots(entry.Key.Value);
|
||||
}
|
||||
else if (ReferenceEquals(context.Device, device))
|
||||
{
|
||||
LiveContexts.TryRemove(entry);
|
||||
Al.EvictContextRoots(entry.Key.Value);
|
||||
orphans.Add(context);
|
||||
}
|
||||
}
|
||||
|
||||
return orphans;
|
||||
}
|
||||
|
||||
internal static void MarkOrphaned(List<Context> orphans)
|
||||
{
|
||||
foreach (var context in orphans)
|
||||
context.Handle = AlcContext.Null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue