VM: Refactor atomic-* to Factor style
parent
9ef732743d
commit
ca1276841d
|
@ -1,49 +1,39 @@
|
||||||
#define FACTOR_FORCE_INLINE __forceinline
|
#define FACTOR_FORCE_INLINE __forceinline
|
||||||
|
|
||||||
namespace factor {
|
namespace factor {
|
||||||
namespace atomic {
|
namespace atomic {
|
||||||
__forceinline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
|
__forceinline static bool cas(volatile cell* ptr, cell old_val, cell new_val) {
|
||||||
{
|
return InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(ptr),
|
||||||
return InterlockedCompareExchange(
|
(LONG) old_val, (LONG) new_val) ==
|
||||||
reinterpret_cast<volatile LONG *>(ptr),
|
(LONG) old_val;
|
||||||
(LONG)old_val,
|
}
|
||||||
(LONG)new_val) == (LONG)old_val;
|
__forceinline static bool cas(volatile fixnum* ptr, fixnum old_val,
|
||||||
}
|
fixnum new_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) ==
|
||||||
return InterlockedCompareExchange(
|
(LONG) old_val;
|
||||||
reinterpret_cast<volatile LONG *>(ptr),
|
}
|
||||||
(LONG)old_val,
|
|
||||||
(LONG)new_val) == (LONG)old_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
__forceinline static cell fetch_add(volatile cell *ptr, cell val)
|
__forceinline static cell fetch_add(volatile cell* ptr, cell val) {
|
||||||
{
|
return (cell)
|
||||||
return (cell)InterlockedExchangeAdd(
|
InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr), (LONG) val);
|
||||||
reinterpret_cast<volatile LONG *>(ptr), (LONG)val);
|
}
|
||||||
}
|
__forceinline static fixnum fetch_add(volatile fixnum* ptr, fixnum val) {
|
||||||
__forceinline static fixnum fetch_add(volatile fixnum *ptr, fixnum val)
|
return (fixnum)
|
||||||
{
|
InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr), (LONG) val);
|
||||||
return (fixnum)InterlockedExchangeAdd(
|
}
|
||||||
reinterpret_cast<volatile LONG *>(ptr), (LONG)val);
|
|
||||||
}
|
|
||||||
|
|
||||||
__forceinline static cell fetch_subtract(volatile cell *ptr, cell val)
|
__forceinline static cell fetch_subtract(volatile cell* ptr, cell val) {
|
||||||
{
|
return (cell) InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr),
|
||||||
return (cell)InterlockedExchangeAdd(
|
-(LONG) val);
|
||||||
reinterpret_cast<volatile LONG *>(ptr), -(LONG)val);
|
}
|
||||||
}
|
__forceinline static fixnum fetch_subtract(volatile fixnum* ptr, fixnum val) {
|
||||||
__forceinline static fixnum fetch_subtract(volatile fixnum *ptr, fixnum val)
|
return (fixnum) InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr),
|
||||||
{
|
-(LONG) val);
|
||||||
return (fixnum)InterlockedExchangeAdd(
|
}
|
||||||
reinterpret_cast<volatile LONG *>(ptr), -(LONG)val);
|
|
||||||
}
|
|
||||||
|
|
||||||
__forceinline static void fence()
|
__forceinline static void fence() { MemoryBarrier(); }
|
||||||
{
|
}
|
||||||
MemoryBarrier();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "atomic.hpp"
|
#include "atomic.hpp"
|
||||||
|
|
|
@ -1,49 +1,39 @@
|
||||||
#define FACTOR_FORCE_INLINE __forceinline
|
#define FACTOR_FORCE_INLINE __forceinline
|
||||||
|
|
||||||
namespace factor {
|
namespace factor {
|
||||||
namespace atomic {
|
namespace atomic {
|
||||||
__forceinline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
|
__forceinline static bool cas(volatile cell* ptr, cell old_val, cell new_val) {
|
||||||
{
|
return InterlockedCompareExchange64(reinterpret_cast<volatile LONG64*>(ptr),
|
||||||
return InterlockedCompareExchange64(
|
(LONG64) old_val, (LONG64) new_val) ==
|
||||||
reinterpret_cast<volatile LONG64 *>(ptr),
|
(LONG64) old_val;
|
||||||
(LONG64)old_val,
|
}
|
||||||
(LONG64)new_val) == (LONG64)old_val;
|
__forceinline static bool cas(volatile fixnum* ptr, fixnum old_val,
|
||||||
}
|
fixnum new_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) ==
|
||||||
return InterlockedCompareExchange64(
|
(LONG64) old_val;
|
||||||
reinterpret_cast<volatile LONG64 *>(ptr),
|
}
|
||||||
(LONG64)old_val,
|
|
||||||
(LONG64)new_val) == (LONG64)old_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
__forceinline static cell fetch_add(volatile cell *ptr, cell val)
|
__forceinline static cell fetch_add(volatile cell* ptr, cell val) {
|
||||||
{
|
return (cell) InterlockedExchangeAdd64(
|
||||||
return (cell)InterlockedExchangeAdd64(
|
reinterpret_cast<volatile LONG64*>(ptr), (LONG64) val);
|
||||||
reinterpret_cast<volatile LONG64 *>(ptr), (LONG64)val);
|
}
|
||||||
}
|
__forceinline static fixnum fetch_add(volatile fixnum* ptr, fixnum val) {
|
||||||
__forceinline static fixnum fetch_add(volatile fixnum *ptr, fixnum val)
|
return (fixnum) InterlockedExchangeAdd64(
|
||||||
{
|
reinterpret_cast<volatile LONG64*>(ptr), (LONG64) val);
|
||||||
return (fixnum)InterlockedExchangeAdd64(
|
}
|
||||||
reinterpret_cast<volatile LONG64 *>(ptr), (LONG64)val);
|
|
||||||
}
|
|
||||||
|
|
||||||
__forceinline static cell fetch_subtract(volatile cell *ptr, cell val)
|
__forceinline static cell fetch_subtract(volatile cell* ptr, cell val) {
|
||||||
{
|
return (cell) InterlockedExchangeAdd64(
|
||||||
return (cell)InterlockedExchangeAdd64(
|
reinterpret_cast<volatile LONG64*>(ptr), -(LONG64) val);
|
||||||
reinterpret_cast<volatile LONG64 *>(ptr), -(LONG64)val);
|
}
|
||||||
}
|
__forceinline static fixnum fetch_subtract(volatile fixnum* ptr, fixnum val) {
|
||||||
__forceinline static fixnum fetch_subtract(volatile fixnum *ptr, fixnum val)
|
return (fixnum) InterlockedExchangeAdd64(
|
||||||
{
|
reinterpret_cast<volatile LONG64*>(ptr), -(LONG64) val);
|
||||||
return (fixnum)InterlockedExchangeAdd64(
|
}
|
||||||
reinterpret_cast<volatile LONG64 *>(ptr), -(LONG64)val);
|
|
||||||
}
|
|
||||||
|
|
||||||
__forceinline static void fence()
|
__forceinline static void fence() { MemoryBarrier(); }
|
||||||
{
|
}
|
||||||
MemoryBarrier();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "atomic.hpp"
|
#include "atomic.hpp"
|
||||||
|
|
|
@ -1,45 +1,39 @@
|
||||||
#define FACTOR_FORCE_INLINE __attribute__((always_inline)) inline
|
#define FACTOR_FORCE_INLINE __attribute__((always_inline)) inline
|
||||||
namespace factor {
|
namespace factor {
|
||||||
namespace atomic {
|
namespace atomic {
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline)) inline static bool cas(volatile cell* ptr,
|
||||||
inline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
|
cell old_val,
|
||||||
{
|
cell new_val) {
|
||||||
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
|
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
|
||||||
}
|
}
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline)) inline static bool cas(volatile fixnum* ptr,
|
||||||
inline static bool cas(volatile fixnum *ptr, fixnum old_val, fixnum new_val)
|
fixnum old_val,
|
||||||
{
|
fixnum new_val) {
|
||||||
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
|
return __sync_bool_compare_and_swap(ptr, old_val, new_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline)) inline static cell fetch_add(volatile cell* ptr,
|
||||||
inline static cell fetch_add(volatile cell *ptr, cell val)
|
cell val) {
|
||||||
{
|
|
||||||
return __sync_fetch_and_add(ptr, val);
|
return __sync_fetch_and_add(ptr, val);
|
||||||
}
|
}
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline)) inline static fixnum fetch_add(
|
||||||
inline static fixnum fetch_add(volatile fixnum *ptr, fixnum val)
|
volatile fixnum* ptr, fixnum val) {
|
||||||
{
|
|
||||||
return __sync_fetch_and_add(ptr, val);
|
return __sync_fetch_and_add(ptr, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline)) inline static cell fetch_subtract(
|
||||||
inline static cell fetch_subtract(volatile cell *ptr, cell val)
|
volatile cell* ptr, cell val) {
|
||||||
{
|
|
||||||
return __sync_fetch_and_sub(ptr, val);
|
return __sync_fetch_and_sub(ptr, val);
|
||||||
}
|
}
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline)) inline static fixnum fetch_subtract(
|
||||||
inline static fixnum fetch_subtract(volatile fixnum *ptr, fixnum val)
|
volatile fixnum* ptr, fixnum val) {
|
||||||
{
|
|
||||||
return __sync_fetch_and_sub(ptr, val);
|
return __sync_fetch_and_sub(ptr, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline)) inline static void fence() {
|
||||||
inline static void fence()
|
|
||||||
{
|
|
||||||
__sync_synchronize();
|
__sync_synchronize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "atomic.hpp"
|
#include "atomic.hpp"
|
||||||
|
|
Loading…
Reference in New Issue