34 #include "../api_core.h"
40 #include "../System/cl_platform.h"
44 #if defined(WIN32) || __GNUC__ > 4 || (__GNUC__ == 4 & __GNUC_MINOR__ >= 1)
49 class CL_InterlockedVariable
53 CL_InterlockedVariable()
54 : val((LONG*)
CL_System::aligned_alloc(sizeof(LONG), 4))
59 CL_InterlockedVariable(
const CL_InterlockedVariable &src)
60 : val((LONG*)
CL_System::aligned_alloc(sizeof(LONG), 4))
65 ~CL_InterlockedVariable()
70 CL_InterlockedVariable &operator =(
const CL_InterlockedVariable &src)
78 return InterlockedCompareExchange(val, 0, 0);
81 void set(LONG new_value)
83 InterlockedExchange(val, new_value);
88 return InterlockedIncrement(val);
93 return InterlockedDecrement(val);
96 bool compare_and_swap(LONG expected_value, LONG new_value)
98 return InterlockedCompareExchange(val, new_value, expected_value) == expected_value;
105 CL_InterlockedVariable()
111 CL_InterlockedVariable(
const CL_InterlockedVariable &src)
117 ~CL_InterlockedVariable()
122 CL_InterlockedVariable &operator =(
const CL_InterlockedVariable &src)
130 return __sync_val_compare_and_swap(val, 0, 0);
133 void set(
int new_value)
135 __sync_lock_test_and_set(val, new_value);
140 return __sync_add_and_fetch(val, 1);
145 return __sync_sub_and_fetch(val, 1);
148 bool compare_and_swap(
int expected_value,
int new_value)
150 return __sync_bool_compare_and_swap(val, expected_value, new_value);