rename to servicepoint, new dir structure, WIP build.rs
This commit is contained in:
parent
e9dc4b59d2
commit
f2d98af532
61 changed files with 751 additions and 140 deletions
51
crates/servicepoint_binding_cs/src/SpNativeInstance.cs
Normal file
51
crates/servicepoint_binding_cs/src/SpNativeInstance.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
namespace ServicePoint;
|
||||
|
||||
public abstract class SpNativeInstance<T>
|
||||
: IDisposable
|
||||
where T : unmanaged
|
||||
{
|
||||
private unsafe T* _instance;
|
||||
|
||||
internal unsafe T* Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
throw new NullReferenceException("instance is null");
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private protected unsafe SpNativeInstance(T* instance)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
private protected abstract void Dealloc();
|
||||
|
||||
internal unsafe T* Into()
|
||||
{
|
||||
var instance = _instance;
|
||||
_instance = null;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private unsafe void ReleaseUnmanagedResources()
|
||||
{
|
||||
if (_instance != null)
|
||||
Dealloc();
|
||||
_instance = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ReleaseUnmanagedResources();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~SpNativeInstance()
|
||||
{
|
||||
ReleaseUnmanagedResources();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue