VM: Refactor atomic-* to Factor style

db4
Erik Charlebois 2013-05-11 21:43:04 -04:00
parent 9ef732743d
commit ca1276841d
3 changed files with 91 additions and 117 deletions

View File

@ -1,49 +1,39 @@
#define FACTOR_FORCE_INLINE __forceinline
namespace factor {
namespace atomic {
__forceinline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
{
return InterlockedCompareExchange(
reinterpret_cast<volatile LONG *>(ptr),
(LONG)old_val,
(LONG)new_val) == (LONG)old_val;
}
__forceinline static bool cas(volatile fixnum *ptr, fixnum old_val, fixnum new_val)
{
return InterlockedCompareExchange(
reinterpret_cast<volatile LONG *>(ptr),
(LONG)old_val,
(LONG)new_val) == (LONG)old_val;
}
namespace atomic {
__forceinline static bool cas(volatile cell* ptr, cell old_val, cell new_val) {
return InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(ptr),
(LONG) old_val, (LONG) new_val) ==
(LONG) old_val;
}
__forceinline static bool cas(volatile fixnum* ptr, fixnum old_val,
fixnum new_val) {
return InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(ptr),
(LONG) old_val, (LONG) new_val) ==
(LONG) old_val;
}
__forceinline static cell fetch_add(volatile cell *ptr, cell val)
{
return (cell)InterlockedExchangeAdd(
reinterpret_cast<volatile LONG *>(ptr), (LONG)val);
}
__forceinline static fixnum fetch_add(volatile fixnum *ptr, fixnum val)
{
return (fixnum)InterlockedExchangeAdd(
reinterpret_cast<volatile LONG *>(ptr), (LONG)val);
}
__forceinline static cell fetch_add(volatile cell* ptr, cell val) {
return (cell)
InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr), (LONG) val);
}
__forceinline static fixnum fetch_add(volatile fixnum* ptr, fixnum val) {
return (fixnum)
InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr), (LONG) val);
}
__forceinline static cell fetch_subtract(volatile cell *ptr, cell val)
{
return (cell)InterlockedExchangeAdd(
reinterpret_cast<volatile LONG *>(ptr), -(LONG)val);
}
__forceinline static fixnum fetch_subtract(volatile fixnum *ptr, fixnum val)
{
return (fixnum)InterlockedExchangeAdd(
reinterpret_cast<volatile LONG *>(ptr), -(LONG)val);
}
__forceinline static cell fetch_subtract(volatile cell* ptr, cell val) {
return (cell) InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr),
-(LONG) val);
}
__forceinline static fixnum fetch_subtract(volatile fixnum* ptr, fixnum val) {
return (fixnum) InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr),
-(LONG) val);
}
__forceinline static void fence()
{
MemoryBarrier();
}
}
__forceinline static void fence() { MemoryBarrier(); }
}
}
#include "atomic.hpp"

View File

@ -1,49 +1,39 @@
#define FACTOR_FORCE_INLINE __forceinline
namespace factor {
namespace atomic {
__forceinline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
{
return InterlockedCompareExchange64(
reinterpret_cast<volatile LONG64 *>(ptr),
(LONG64)old_val,
(LONG64)new_val) == (LONG64)old_val;
}
__forceinline static bool cas(volatile fixnum *ptr, fixnum old_val, fixnum new_val)
{
return InterlockedCompareExchange64(
reinterpret_cast<volatile LONG64 *>(ptr),
(LONG64)old_val,
(LONG64)new_val) == (LONG64)old_val;
}
namespace atomic {
__forceinline static bool cas(volatile cell* ptr, cell old_val, cell new_val) {
return InterlockedCompareExchange64(reinterpret_cast<volatile LONG64*>(ptr),
(LONG64) old_val, (LONG64) new_val) ==
(LONG64) old_val;
}
__forceinline static bool cas(volatile fixnum* ptr, fixnum old_val,
fixnum new_val) {
return InterlockedCompareExchange64(reinterpret_cast<volatile LONG64*>(ptr),
(LONG64) old_val, (LONG64) new_val) ==
(LONG64) old_val;
}
__forceinline static cell fetch_add(volatile cell *ptr, cell val)
{
return (cell)InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64 *>(ptr), (LONG64)val);
}
__forceinline static fixnum fetch_add(volatile fixnum *ptr, fixnum val)
{
return (fixnum)InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64 *>(ptr), (LONG64)val);
}
__forceinline static cell fetch_add(volatile cell* ptr, cell val) {
return (cell) InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64*>(ptr), (LONG64) val);
}
__forceinline static fixnum fetch_add(volatile fixnum* ptr, fixnum val) {
return (fixnum) InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64*>(ptr), (LONG64) val);
}
__forceinline static cell fetch_subtract(volatile cell *ptr, cell val)
{
return (cell)InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64 *>(ptr), -(LONG64)val);
}
__forceinline static fixnum fetch_subtract(volatile fixnum *ptr, fixnum val)
{
return (fixnum)InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64 *>(ptr), -(LONG64)val);
}
__forceinline static cell fetch_subtract(volatile cell* ptr, cell val) {
return (cell) InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64*>(ptr), -(LONG64) val);
}
__forceinline static fixnum fetch_subtract(volatile fixnum* ptr, fixnum val) {
return (fixnum) InterlockedExchangeAdd64(
reinterpret_cast<volatile LONG64*>(ptr), -(LONG64) val);
}
__forceinline static void fence()
{
MemoryBarrier();
}
}
__forceinline static void fence() { MemoryBarrier(); }
}
}
#include "atomic.hpp"

View File

@ -1,45 +1,39 @@
#define FACTOR_FORCE_INLINE __attribute__((always_inline)) inline
namespace factor {
namespace atomic {
__attribute__((always_inline))
inline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
{
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
}
__attribute__((always_inline))
inline static bool cas(volatile fixnum *ptr, fixnum old_val, fixnum new_val)
{
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
}
namespace atomic {
__attribute__((always_inline)) inline static bool cas(volatile cell* ptr,
cell old_val,
cell new_val) {
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
}
__attribute__((always_inline)) inline static bool cas(volatile fixnum* ptr,
fixnum old_val,
fixnum new_val) {
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
}
__attribute__((always_inline))
inline static cell fetch_add(volatile cell *ptr, cell val)
{
return __sync_fetch_and_add(ptr, val);
}
__attribute__((always_inline))
inline static fixnum fetch_add(volatile fixnum *ptr, fixnum val)
{
return __sync_fetch_and_add(ptr, val);
}
__attribute__((always_inline)) inline static cell fetch_add(volatile cell* ptr,
cell val) {
return __sync_fetch_and_add(ptr, val);
}
__attribute__((always_inline)) inline static fixnum fetch_add(
volatile fixnum* ptr, fixnum val) {
return __sync_fetch_and_add(ptr, val);
}
__attribute__((always_inline))
inline static cell fetch_subtract(volatile cell *ptr, cell val)
{
return __sync_fetch_and_sub(ptr, val);
}
__attribute__((always_inline))
inline static fixnum fetch_subtract(volatile fixnum *ptr, fixnum val)
{
return __sync_fetch_and_sub(ptr, val);
}
__attribute__((always_inline)) inline static cell fetch_subtract(
volatile cell* ptr, cell val) {
return __sync_fetch_and_sub(ptr, val);
}
__attribute__((always_inline)) inline static fixnum fetch_subtract(
volatile fixnum* ptr, fixnum val) {
return __sync_fetch_and_sub(ptr, val);
}
__attribute__((always_inline))
inline static void fence()
{
__sync_synchronize();
}
}
__attribute__((always_inline)) inline static void fence() {
__sync_synchronize();
}
}
}
#include "atomic.hpp"