仿真平台内核初版 -tlib库 包含<sparc arm riscv powerPC>

This commit is contained in:
liuwb
2026-02-07 20:43:43 +08:00
parent de61f9e2b0
commit b3117648be
9748 changed files with 4309137 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
//
// Copyright (c) Antmicro
//
// Full license details are defined in the 'LICENSE' file.
//
using System;
namespace TermSharp.Misc
{
internal sealed class SimpleCache<TFrom, TTo> where TFrom : IGenerationAware
{
public SimpleCache(Func<TFrom, TTo> factory)
{
generation = -1;
this.factory = factory;
}
public TTo GetValue(TFrom from)
{
if(generation != from.Generation)
{
var resultAsDisposable = lastResult as IDisposable;
if(resultAsDisposable != null)
{
resultAsDisposable.Dispose();
}
lastResult = factory(from);
generation = from.Generation;
}
return lastResult;
}
private TTo lastResult;
private Func<TFrom, TTo> factory;
private int generation;
}
}