osAtomic.h 6.2 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

S
Shengliang Guan 已提交
16 17
#ifndef _TD_OS_ATOMIC_H_
#define _TD_OS_ATOMIC_H_
S
Shengliang Guan 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

wafwerar's avatar
wafwerar 已提交
23 24 25
// If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC
L
Liu Jicong 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39
#define __atomic_load_n             __ATOMIC_LOAD_N_FUNC_TAOS_FORBID
#define __atomic_store_n            __ATOMIC_STORE_N_FUNC_TAOS_FORBID
#define __atomic_exchange_n         __ATOMIC_EXCHANGE_N_FUNC_TAOS_FORBID
#define __sync_val_compare_and_swap __SYNC_VAL_COMPARE_AND_SWAP_FUNC_TAOS_FORBID
#define __atomic_add_fetch          __ATOMIC_ADD_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_add          __ATOMIC_FETCH_ADD_FUNC_TAOS_FORBID
#define __atomic_sub_fetch          __ATOMIC_SUB_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_sub          __ATOMIC_FETCH_SUB_FUNC_TAOS_FORBID
#define __atomic_and_fetch          __ATOMIC_AND_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_and          __ATOMIC_FETCH_AND_FUNC_TAOS_FORBID
#define __atomic_or_fetch           __ATOMIC_OR_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_or           __ATOMIC_FETCH_OR_FUNC_TAOS_FORBID
#define __atomic_xor_fetch          __ATOMIC_XOR_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_xor          __ATOMIC_FETCH_XOR_FUNC_TAOS_FORBID
S
Shengliang Guan 已提交
40 41
#endif

L
Liu Jicong 已提交
42
int8_t  atomic_load_8(int8_t volatile *ptr);
wafwerar's avatar
wafwerar 已提交
43 44 45
int16_t atomic_load_16(int16_t volatile *ptr);
int32_t atomic_load_32(int32_t volatile *ptr);
int64_t atomic_load_64(int64_t volatile *ptr);
L
Liu Jicong 已提交
46 47 48 49 50 51 52
void   *atomic_load_ptr(void *ptr);
void    atomic_store_8(int8_t volatile *ptr, int8_t val);
void    atomic_store_16(int16_t volatile *ptr, int16_t val);
void    atomic_store_32(int32_t volatile *ptr, int32_t val);
void    atomic_store_64(int64_t volatile *ptr, int64_t val);
void    atomic_store_ptr(void *ptr, void *val);
int8_t  atomic_exchange_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
53 54 55
int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
56 57
void   *atomic_exchange_ptr(void *ptr, void *val);
int8_t  atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t newval);
wafwerar's avatar
wafwerar 已提交
58 59 60
int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, int16_t newval);
int32_t atomic_val_compare_exchange_32(int32_t volatile *ptr, int32_t oldval, int32_t newval);
int64_t atomic_val_compare_exchange_64(int64_t volatile *ptr, int64_t oldval, int64_t newval);
L
Liu Jicong 已提交
61 62
void   *atomic_val_compare_exchange_ptr(void *ptr, void *oldval, void *newval);
int8_t  atomic_add_fetch_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
63 64 65
int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val);
wafwerar's avatar
wafwerar 已提交
66
void   *atomic_add_fetch_ptr(void *ptr, int64_t val);
L
Liu Jicong 已提交
67
int8_t  atomic_fetch_add_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
68 69 70
int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
71 72
void   *atomic_fetch_add_ptr(void *ptr, void *val);
int8_t  atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
73 74 75
int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val);
wafwerar's avatar
wafwerar 已提交
76
void   *atomic_sub_fetch_ptr(void *ptr, int64_t val);
L
Liu Jicong 已提交
77
int8_t  atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
78 79 80
int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
81 82
void   *atomic_fetch_sub_ptr(void *ptr, void *val);
int8_t  atomic_and_fetch_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
83 84 85
int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
86 87
void   *atomic_and_fetch_ptr(void *ptr, void *val);
int8_t  atomic_fetch_and_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
88 89 90
int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
91 92
void   *atomic_fetch_and_ptr(void *ptr, void *val);
int8_t  atomic_or_fetch_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
93 94 95
int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
96 97
void   *atomic_or_fetch_ptr(void *ptr, void *val);
int8_t  atomic_fetch_or_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
98 99 100
int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
101 102
void   *atomic_fetch_or_ptr(void *ptr, void *val);
int8_t  atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
103 104 105
int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
106 107
void   *atomic_xor_fetch_ptr(void *ptr, void *val);
int8_t  atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val);
wafwerar's avatar
wafwerar 已提交
108 109 110
int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val);
L
Liu Jicong 已提交
111
void   *atomic_fetch_xor_ptr(void *ptr, void *val);
wafwerar's avatar
wafwerar 已提交
112

S
Shengliang Guan 已提交
113 114 115 116
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
117
#endif /*_TD_OS_ATOMIC_H_*/