1 | /* |
2 | * Copyright 2008-2018 Aerospike, Inc. |
3 | * |
4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
5 | * license agreements. |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
8 | * use this file except in compliance with the License. You may obtain a copy of |
9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
14 | * License for the specific language governing permissions and limitations under |
15 | * the License. |
16 | */ |
17 | #pragma once |
18 | |
19 | #if defined(_MSC_VER) |
20 | #include <aerospike/as_atomic_win.h> |
21 | #else |
22 | #include <aerospike/as_atomic_gcc.h> |
23 | #endif |
24 | |
25 | /****************************************************************************** |
26 | * LOAD |
27 | *****************************************************************************/ |
28 | |
29 | // double as_load_double(const double* target) |
30 | #define as_load_double(_target) ({ \ |
31 | uint64_t v = as_load_uint64((const uint64_t*)_target); \ |
32 | *(double*)&v; \ |
33 | }) |
34 | |
35 | // float as_load_float(const float* target) |
36 | #define as_load_float(_target) ({ \ |
37 | uint32_t v = as_load_uint32((const uint32_t*)_target); \ |
38 | *(float*)&v; \ |
39 | }) |
40 | |
41 | /****************************************************************************** |
42 | * STORE |
43 | *****************************************************************************/ |
44 | |
45 | // void as_store_double(double* target, double value) |
46 | #define as_store_double(_target, _value) ({ \ |
47 | double v = _value; \ |
48 | as_store_uint64((uint64_t*)_target, *(uint64_t*)&v); \ |
49 | }) |
50 | |
51 | // void as_store_float(float* target, float value) |
52 | #define as_store_float(_target, _value) ({ \ |
53 | float v = _value; \ |
54 | as_store_uint32((uint32_t*)_target, *(uint32_t*)&v); \ |
55 | }) |
56 | |
57 | /****************************************************************************** |
58 | * FETCH AND SWAP |
59 | *****************************************************************************/ |
60 | |
61 | // double as_fas_double(double* target, double value) |
62 | #define as_fas_double(_target, _value) ({ \ |
63 | double nv = _value; \ |
64 | uint64_t ov = as_fas_uint64((uint64_t*)_target, *(uint64_t*)&nv); \ |
65 | *(double*)&ov; \ |
66 | }) |
67 | |
68 | // float as_fas_float(float* target, float value) |
69 | #define as_fas_float(_target, _value) ({ \ |
70 | float nv = _value; \ |
71 | uint32_t ov = as_fas_uint32((uint32_t*)_target, *(uint32_t*)&nv); \ |
72 | *(float*)&ov; \ |
73 | }) |
74 | |
75 | /****************************************************************************** |
76 | * COMPARE AND SWAP |
77 | *****************************************************************************/ |
78 | |
79 | // bool as_cas_double(double* target, double old_value, double new_value) |
80 | #define as_cas_double(_target, _old_value, _new_value) ({ \ |
81 | double ov = _old_value; \ |
82 | double nv = _new_value; \ |
83 | as_cas_uint64((uint64_t*)_target, *(uint64_t*)&ov, *(uint64_t*)&nv); \ |
84 | }) |
85 | |
86 | // bool as_cas_float(float* target, float old_value, float new_value) |
87 | #define as_cas_float(_target, _old_value, _new_value) ({ \ |
88 | float ov = _old_value; \ |
89 | float nv = _new_value; \ |
90 | as_cas_uint32((uint32_t*)_target, *(uint32_t*)&ov, *(uint32_t*)&nv); \ |
91 | }) |
92 | |