forked from vmware-archive/gpos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindAtomics.cmake
81 lines (68 loc) · 1.89 KB
/
FindAtomics.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright (c) 2015, Pivotal Software, Inc.
# CMake module to find compiler built-ins for atomic operations.
# Test for GCC-style builtins for fetch-add and compare-and-swap (clang and ICC
# also have these). C++11 and C11 do this in an elegant standardized way, but
# we can not be assured of a C++11 compiler.
include(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES("
#include <stdint.h>
int main() {
uint32_t value = 0;
uint32_t increment = 10;
uint32_t prev = __sync_fetch_and_add(&value, increment);
return static_cast<int>(prev);
}
" COMPILER_HAS_FETCH_ADD_32)
if (COMPILER_HAS_FETCH_ADD_32)
set_property(
DIRECTORY
APPEND PROPERTY COMPILE_DEFINITIONS
GPOS_GCC_FETCH_ADD_32)
endif()
CHECK_CXX_SOURCE_COMPILES("
#include <stdint.h>
int main() {
uint64_t value = 0;
uint64_t increment = 10;
uint64_t prev = __sync_fetch_and_add(&value, increment);
return static_cast<int>(prev);
}
" COMPILER_HAS_FETCH_ADD_64)
if (COMPILER_HAS_FETCH_ADD_64)
set_property(
DIRECTORY
APPEND PROPERTY COMPILE_DEFINITIONS
GPOS_GCC_FETCH_ADD_64)
endif()
CHECK_CXX_SOURCE_COMPILES("
#include <stdint.h>
int main() {
uint32_t value = 0;
uint32_t expected_value = 0;
uint32_t new_value = 10;
bool success = __sync_bool_compare_and_swap(&value, expected_value, new_value);
return success ? 0 : 1;
}
" COMPILER_HAS_CAS_32)
if (COMPILER_HAS_CAS_32)
set_property(
DIRECTORY
APPEND PROPERTY COMPILE_DEFINITIONS
GPOS_GCC_CAS_32)
endif()
CHECK_CXX_SOURCE_COMPILES("
#include <stdint.h>
int main() {
uint64_t value = 0;
uint64_t expected_value = 0;
uint64_t new_value = 10;
bool success = __sync_bool_compare_and_swap(&value, expected_value, new_value);
return success ? 0 : 1;
}
" COMPILER_HAS_CAS_64)
if (COMPILER_HAS_CAS_64)
set_property(
DIRECTORY
APPEND PROPERTY COMPILE_DEFINITIONS
GPOS_GCC_CAS_64)
endif()