Add compare-exchange function to Atomic

This commit is contained in:
baldurk
2016-09-08 20:19:56 +02:00
parent d461e40711
commit 5cc7519e92
3 changed files with 11 additions and 0 deletions
+1
View File
@@ -204,6 +204,7 @@ int32_t Dec32(volatile int32_t *i);
int64_t Inc64(volatile int64_t *i);
int64_t Dec64(volatile int64_t *i);
int64_t ExchAdd64(volatile int64_t *i, int64_t a);
int32_t CmpExch32(volatile int32_t *dest, int32_t exch, int32_t comp);
};
namespace Callstack
+5
View File
@@ -59,6 +59,11 @@ int64_t ExchAdd64(volatile int64_t *i, int64_t a)
{
return __sync_add_and_fetch(i, int64_t(a));
}
int32_t CmpExch32(volatile int32_t *dest, int32_t exch, int32_t comp)
{
return __sync_val_compare_and_swap(dest, comp, exch);
}
};
namespace Threading
+5
View File
@@ -72,6 +72,11 @@ int64_t ExchAdd64(volatile int64_t *i, int64_t a)
{
return (int64_t)InterlockedExchangeAdd64((volatile LONG64 *)i, a);
}
int32_t CmpExch32(volatile int32_t *dest, int32_t exch, int32_t comp)
{
return (int32_t)InterlockedCompareExchange((volatile LONG *)dest, exch, comp);
}
};
namespace Threading