mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 00:50:25 +02:00
Moving corlib files out of "System" directory into root
This commit is contained in:
parent
4cd58262e4
commit
7dbfd15292
179 changed files with 3 additions and 0 deletions
57
BeefLibs/corlib/src/IRefCounted.bf
Normal file
57
BeefLibs/corlib/src/IRefCounted.bf
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace System
|
||||
{
|
||||
interface IRefCounted
|
||||
{
|
||||
void AddRef();
|
||||
void ReleaseRef();
|
||||
}
|
||||
|
||||
class RefCounted : IRefCounted
|
||||
{
|
||||
protected int32 mRefCount = 1;
|
||||
|
||||
public ~this()
|
||||
{
|
||||
Debug.Assert(mRefCount == 0);
|
||||
}
|
||||
|
||||
public int RefCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return mRefCount;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteUnchecked()
|
||||
{
|
||||
mRefCount = 0;
|
||||
delete this;
|
||||
}
|
||||
|
||||
public void AddRef()
|
||||
{
|
||||
Interlocked.Increment(ref mRefCount);
|
||||
}
|
||||
|
||||
public void ReleaseRef()
|
||||
{
|
||||
int refCount = Interlocked.Decrement(ref mRefCount);
|
||||
Debug.Assert(refCount >= 0);
|
||||
if (refCount == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
public int ReleaseRefNoDelete()
|
||||
{
|
||||
int refCount = Interlocked.Decrement(ref mRefCount);
|
||||
Debug.Assert(refCount >= 0);
|
||||
return refCount;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue