|
1 | 1 | #include <ruby.h> |
2 | | -#if defined(__sun) |
3 | | -#include <atomic.h> |
4 | | -#endif |
| 2 | +/*#if defined(__sun)*/ |
| 3 | +/*#include <atomic.h>*/ |
| 4 | +/*#endif*/ |
5 | 5 |
|
6 | | -#ifdef HAVE_LIBKERN_OSATOMIC_H |
7 | | -#include <libkern/OSAtomic.h> |
8 | | -#endif |
| 6 | +/*#ifdef HAVE_LIBKERN_OSATOMIC_H*/ |
| 7 | +/*#include <libkern/OSAtomic.h>*/ |
| 8 | +/*#endif*/ |
9 | 9 |
|
10 | 10 | #include "atomic_reference.h" |
11 | 11 |
|
12 | 12 | void ir_mark(void *value) { |
13 | | - rb_gc_mark_maybe((VALUE) value); |
| 13 | + rb_gc_mark_maybe((VALUE) value); |
14 | 14 | } |
15 | 15 |
|
16 | 16 | VALUE ir_alloc(VALUE klass) { |
17 | | - return rb_data_object_alloc(klass, (void *) Qnil, ir_mark, NULL); |
| 17 | + return rb_data_object_alloc(klass, (void *) Qnil, ir_mark, NULL); |
18 | 18 | } |
19 | 19 |
|
20 | 20 | VALUE ir_initialize(int argc, VALUE* argv, VALUE self) { |
21 | | - VALUE value = Qnil; |
22 | | - if (rb_scan_args(argc, argv, "01", &value) == 1) { |
23 | | - value = argv[0]; |
24 | | - } |
25 | | - DATA_PTR(self) = (void *) value; |
26 | | - return Qnil; |
| 21 | + VALUE value = Qnil; |
| 22 | + if (rb_scan_args(argc, argv, "01", &value) == 1) { |
| 23 | + value = argv[0]; |
| 24 | + } |
| 25 | + DATA_PTR(self) = (void *) value; |
| 26 | + return Qnil; |
27 | 27 | } |
28 | 28 |
|
29 | 29 | VALUE ir_get(VALUE self) { |
30 | | - return (VALUE) DATA_PTR(self); |
| 30 | + return (VALUE) DATA_PTR(self); |
31 | 31 | } |
32 | 32 |
|
33 | 33 | VALUE ir_set(VALUE self, VALUE new_value) { |
34 | | - DATA_PTR(self) = (void *) new_value; |
35 | | - return new_value; |
| 34 | + DATA_PTR(self) = (void *) new_value; |
| 35 | + return new_value; |
36 | 36 | } |
37 | 37 |
|
38 | 38 | VALUE ir_get_and_set(VALUE self, VALUE new_value) { |
39 | | - VALUE old_value; |
40 | | - old_value = (VALUE) DATA_PTR(self); |
41 | | - DATA_PTR(self) = (void *) new_value; |
42 | | - return old_value; |
| 39 | + VALUE old_value; |
| 40 | + old_value = (VALUE) DATA_PTR(self); |
| 41 | + DATA_PTR(self) = (void *) new_value; |
| 42 | + return old_value; |
43 | 43 | } |
44 | 44 |
|
45 | 45 | VALUE ir_compare_and_set(volatile VALUE self, VALUE expect_value, VALUE new_value) { |
46 | 46 | #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 |
47 | | - if (OSAtomicCompareAndSwap64(expect_value, new_value, &DATA_PTR(self))) { |
48 | | - return Qtrue; |
49 | | - } |
| 47 | + if (OSAtomicCompareAndSwap64(expect_value, new_value, &DATA_PTR(self))) { |
| 48 | + return Qtrue; |
| 49 | + } |
50 | 50 | #elif defined(__sun) |
51 | | -/* Assuming VALUE is uintptr_t */ |
52 | | -/* Based on the definition of uintptr_t from /usr/include/sys/int_types.h */ |
| 51 | + /* Assuming VALUE is uintptr_t */ |
| 52 | + /* Based on the definition of uintptr_t from /usr/include/sys/int_types.h */ |
53 | 53 | #if defined(_LP64) || defined(_I32LPx) |
54 | | - /* 64-bit: uintptr_t === unsigned long */ |
55 | | - if (atomic_cas_ulong((uintptr_t *) &DATA_PTR(self), expect_value, new_value)) { |
56 | | - return Qtrue; |
57 | | - } |
| 54 | + /* 64-bit: uintptr_t === unsigned long */ |
| 55 | + if (atomic_cas_ulong((uintptr_t *) &DATA_PTR(self), expect_value, new_value)) { |
| 56 | + return Qtrue; |
| 57 | + } |
58 | 58 | #else |
59 | | - /* 32-bit: uintptr_t === unsigned int */ |
60 | | - if (atomic_cas_uint((uintptr_t *) &DATA_PTR(self), expect_value, new_value)) { |
61 | | - return Qtrue; |
62 | | - } |
| 59 | + /* 32-bit: uintptr_t === unsigned int */ |
| 60 | + if (atomic_cas_uint((uintptr_t *) &DATA_PTR(self), expect_value, new_value)) { |
| 61 | + return Qtrue; |
| 62 | + } |
63 | 63 | #endif |
64 | 64 | #elif defined _MSC_VER && defined _M_AMD64 |
65 | | - if (InterlockedCompareExchange64((LONGLONG*)&DATA_PTR(self), new_value, expect_value)) { |
66 | | - return Qtrue; |
67 | | - } |
| 65 | + if (InterlockedCompareExchange64((LONGLONG*)&DATA_PTR(self), new_value, expect_value)) { |
| 66 | + return Qtrue; |
| 67 | + } |
68 | 68 | #elif defined _MSC_VER && defined _M_IX86 |
69 | | - if (InterlockedCompareExchange((LONG*)&DATA_PTR(self), new_value, expect_value)) { |
70 | | - return Qtrue; |
71 | | - } |
| 69 | + if (InterlockedCompareExchange((LONG*)&DATA_PTR(self), new_value, expect_value)) { |
| 70 | + return Qtrue; |
| 71 | + } |
72 | 72 | #else |
73 | | - if (__sync_bool_compare_and_swap(&DATA_PTR(self), expect_value, new_value)) { |
74 | | - return Qtrue; |
75 | | - } |
| 73 | + if (__sync_bool_compare_and_swap(&DATA_PTR(self), expect_value, new_value)) { |
| 74 | + return Qtrue; |
| 75 | + } |
76 | 76 | #endif |
77 | | - return Qfalse; |
| 77 | + return Qfalse; |
78 | 78 | } |
0 commit comments