32 #include "../api_core.h"
38 #include "../System/cl_platform.h"
47 #if defined(WIN32) || __GNUC__ > 4 || (__GNUC__ == 4 & __GNUC_MINOR__ >= 1)
50 class InterlockedVariable
55 : val((LONG*)System::aligned_alloc(sizeof(LONG), 4))
60 InterlockedVariable(
const InterlockedVariable &src)
61 : val((LONG*)System::aligned_alloc(sizeof(LONG), 4))
66 ~InterlockedVariable()
71 InterlockedVariable &operator =(
const InterlockedVariable &src)
79 return InterlockedCompareExchange(val, 0, 0);
82 void set(LONG new_value)
84 InterlockedExchange(val, new_value);
89 return InterlockedIncrement(val);
94 return InterlockedDecrement(val);
97 bool compare_and_swap(LONG expected_value, LONG new_value)
99 return InterlockedCompareExchange(val, new_value, expected_value) == expected_value;
106 InterlockedVariable()
107 : val((
byte32*)System::aligned_alloc(sizeof(
byte32), 4))
112 InterlockedVariable(
const InterlockedVariable &src)
113 : val((
byte32*)System::aligned_alloc(sizeof(
byte32), 4))
118 ~InterlockedVariable()
123 InterlockedVariable &operator =(
const InterlockedVariable &src)
131 return __sync_val_compare_and_swap(val, 0, 0);
134 void set(
int new_value)
136 __sync_lock_test_and_set(val, new_value);
141 return __sync_add_and_fetch(val, 1);
146 return __sync_sub_and_fetch(val, 1);
149 bool compare_and_swap(
int expected_value,
int new_value)
151 return __sync_bool_compare_and_swap(val, expected_value, new_value);
static void aligned_free(void *ptr)
Frees aligned memory.
int byte32
Definition: cl_platform.h:63