mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-28 20:46:00 +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
58
BeefLibs/corlib/src/Threading/Volatile.bf
Normal file
58
BeefLibs/corlib/src/Threading/Volatile.bf
Normal file
|
@ -0,0 +1,58 @@
|
|||
namespace System.Threading
|
||||
{
|
||||
static class Volatile
|
||||
{
|
||||
//static volatile int32 gAtomicIdx;
|
||||
|
||||
public static T Read<T>(ref T location)
|
||||
{
|
||||
T value = location;
|
||||
Interlocked.Fence();
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void Write<T>(ref T location, T value)
|
||||
{
|
||||
Interlocked.Fence();
|
||||
location = value;
|
||||
}
|
||||
|
||||
/*public static void MoveAtomic(void* dest, void* src, int size)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int startAtomicIdx = gAtomicIdx;
|
||||
Thread.MemoryBarrier();
|
||||
Internal.MemCpy(dest, src, size);
|
||||
Thread.MemoryBarrier();
|
||||
int endAtomicIdx = Interlocked.Increment(ref gAtomicIdx);
|
||||
if (endAtomicIdx == startAtomicIdx)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static T ReadAtomic<T>(ref T location)
|
||||
{
|
||||
if (sizeof(T) > sizeof(int))
|
||||
{
|
||||
if (sizeof(T) == sizeof(int64))
|
||||
{
|
||||
// Handle 64-bit values on 32-bit machines
|
||||
var location;
|
||||
int64 result = Interlocked.CompareExchange(ref *(int64*)&location, 0, 0);
|
||||
return *(T*)&result;
|
||||
}
|
||||
|
||||
var location;
|
||||
T value = ?;
|
||||
MoveAtomic(&value, &location, sizeof(T));
|
||||
Thread.MemoryBarrier();
|
||||
return value;
|
||||
}
|
||||
|
||||
T value = location;
|
||||
Thread.MemoryBarrier();
|
||||
return value;
|
||||
}*/
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue