]> gitweb.factorcode.org Git - factor.git/blob - vm/atomic-cl-64.hpp
vm: add atomic::load and atomic::store functions
[factor.git] / vm / atomic-cl-64.hpp
1 #define FACTOR_FORCE_INLINE __forceinline
2
3 namespace factor {
4         namespace atomic {
5                 __forceinline static bool cas(volatile cell *ptr, cell old_val, cell new_val)
6                 {
7                         return InterlockedCompareExchange64(
8                                 reinterpret_cast<volatile LONG64 *>(ptr),
9                                 (LONG64)old_val,
10                                 (LONG64)new_val) == (LONG64)old_val;
11                 }
12                 __forceinline static bool cas(volatile fixnum *ptr, fixnum old_val, fixnum new_val)
13                 {
14                         return InterlockedCompareExchange64(
15                                 reinterpret_cast<volatile LONG64 *>(ptr),
16                                 (LONG64)old_val,
17                                 (LONG64)new_val) == (LONG64)old_val;
18                 }
19
20                 __forceinline static cell add(volatile cell *ptr, cell val)
21                 {
22                         return (cell)InterlockedAdd64(
23                                 reinterpret_cast<volatile LONG64 *>(ptr), (LONG64)val);
24                 }
25                 __forceinline static fixnum add(volatile fixnum *ptr, fixnum val)
26                 {
27                         return (fixnum)InterlockedAdd64(
28                                 reinterpret_cast<volatile LONG64 *>(ptr), (LONG64)val);
29                 }
30
31                 __forceinline static cell subtract(volatile cell *ptr, cell val)
32                 {
33                         return (cell)InterlockedAdd64(
34                                 reinterpret_cast<volatile LONG64 *>(ptr), -(LONG64)val);
35                 }
36                 __forceinline static fixnum subtract(volatile fixnum *ptr, fixnum val)
37                 {
38                         return (fixnum)InterlockedAdd64(
39                                 reinterpret_cast<volatile LONG64 *>(ptr), -(LONG64)val);
40                 }
41
42                 __forceinline static void fence()
43                 {
44                         MemoryBarrier();
45                 }
46         }
47 }
48
49 #include "atomic.hpp"