/src/tdengine/include/os/os.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com> |
3 | | * |
4 | | * This program is free software: you can use, redistribute, and/or modify |
5 | | * it under the terms of the GNU Affero General Public License, version 3 |
6 | | * or later ("AGPL"), as published by the Free Software Foundation. |
7 | | * |
8 | | * This program is distributed in the hope that it will be useful, but WITHOUT |
9 | | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
10 | | * FITNESS FOR A PARTICULAR PURPOSE. |
11 | | * |
12 | | * You should have received a copy of the GNU Affero General Public License |
13 | | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 | | */ |
15 | | |
16 | | #ifndef _TD_OS_H_ |
17 | | #define _TD_OS_H_ |
18 | | |
19 | | #ifdef __cplusplus |
20 | | extern "C" { |
21 | | #endif |
22 | | |
23 | | #include <assert.h> |
24 | | #include <ctype.h> |
25 | | |
26 | | #include <regex.h> |
27 | | |
28 | | #if !defined(WINDOWS) |
29 | | #include <dirent.h> |
30 | | |
31 | | #if !defined(_ALPINE) && !defined(TD_ASTRA) |
32 | | #include <execinfo.h> |
33 | | #endif |
34 | | |
35 | | #if !defined(TD_ASTRA) |
36 | | #include <libgen.h> |
37 | | #include <wordexp.h> |
38 | | #include <sys/param.h> |
39 | | #include <sys/shm.h> |
40 | | #include <sys/statvfs.h> |
41 | | #include <termios.h> |
42 | | #else |
43 | | #include <astra.h> |
44 | | #endif |
45 | | |
46 | | #include <sched.h> |
47 | | #include <unistd.h> |
48 | | #include <sys/ioctl.h> |
49 | | #include <sys/mman.h> |
50 | | #include <sys/stat.h> |
51 | | #include <sys/time.h> |
52 | | #include <sys/types.h> |
53 | | #include <sys/utsname.h> |
54 | | #include <sys/wait.h> |
55 | | |
56 | | #if defined(DARWIN) |
57 | | #include <pwd.h> |
58 | | #else |
59 | | #if !defined(TD_ASTRA) |
60 | | #include <argp.h> |
61 | | #include <sys/prctl.h> |
62 | | #include <sys/sysinfo.h> |
63 | | #if defined(_TD_X86_) |
64 | | #include <cpuid.h> |
65 | | #endif |
66 | | #endif |
67 | | #endif |
68 | | #else |
69 | | |
70 | | #ifndef __func__ |
71 | | #define __func__ __FUNCTION__ |
72 | | #endif |
73 | | #include <malloc.h> |
74 | | #include <time.h> |
75 | | #ifndef TD_USE_WINSOCK |
76 | | #include <winsock2.h> |
77 | | #else |
78 | | #include <winsock.h> |
79 | | #endif |
80 | | #endif |
81 | | |
82 | | #include <errno.h> |
83 | | #include <fcntl.h> |
84 | | #include <float.h> |
85 | | #include <inttypes.h> |
86 | | #include <limits.h> |
87 | | #include <locale.h> |
88 | | #include <math.h> |
89 | | #include <setjmp.h> |
90 | | #include <signal.h> |
91 | | #include <stdarg.h> |
92 | | #include <stdbool.h> |
93 | | #include <stddef.h> |
94 | | #include <stdint.h> |
95 | | #include <stdio.h> |
96 | | #include <stdlib.h> |
97 | | #include <string.h> |
98 | | #include <wchar.h> |
99 | | #include <wctype.h> |
100 | | |
101 | | #if __AVX__ |
102 | | #include <immintrin.h> |
103 | | #elif __SSE4_2__ |
104 | | #include <nmmintrin.h> |
105 | | #endif |
106 | | |
107 | | |
108 | | #include "osThread.h" |
109 | | |
110 | | #include "osAtomic.h" |
111 | | #include "osDef.h" |
112 | | #include "osDir.h" |
113 | | #include "osEndian.h" |
114 | | #include "osEnv.h" |
115 | | #include "osFile.h" |
116 | | #include "osLocale.h" |
117 | | #include "osLz4.h" |
118 | | #include "osMath.h" |
119 | | #include "osMemory.h" |
120 | | #include "osMemPool.h" |
121 | | #include "osRand.h" |
122 | | #include "osSemaphore.h" |
123 | | #include "osSignal.h" |
124 | | #include "osSleep.h" |
125 | | #include "osSocket.h" |
126 | | #include "osString.h" |
127 | | #include "osSysinfo.h" |
128 | | #include "osSystem.h" |
129 | | #include "osTime.h" |
130 | | #include "osTimer.h" |
131 | | #include "osTimezone.h" |
132 | | #include "taoserror.h" |
133 | | #include "tlog.h" |
134 | | |
135 | | extern int32_t tsRandErrChance; |
136 | | extern int64_t tsRandErrDivisor; |
137 | | extern int64_t tsRandErrScope; |
138 | | extern threadlocal bool tsEnableRandErr; |
139 | | |
140 | 0 | #define TAOS_UNUSED(expr) (void)(expr) |
141 | | #define TAOS_SKIP_ERROR(expr) \ |
142 | 0 | { \ |
143 | 0 | int32_t _code = terrno; \ |
144 | 0 | (void)(expr); \ |
145 | 0 | terrno = _code; \ |
146 | 0 | } |
147 | | |
148 | | #define OS_PARAM_CHECK(_o) \ |
149 | 0 | do { \ |
150 | 0 | if ((_o) == NULL) { \ |
151 | 0 | terrno = TSDB_CODE_INVALID_PARA; \ |
152 | 0 | return terrno; \ |
153 | 0 | } \ |
154 | 0 | } while (0) |
155 | | |
156 | | // NOTE: use TD_ALWAYS_ASSERT to enforce assertion even in release build |
157 | | // this is for test cases to use!!! |
158 | | #define TD_ALWAYS_ASSERT(pred) \ |
159 | | if (!(pred)) { \ |
160 | | fprintf(stderr, "Assertion `%s` failed.\n", #pred); \ |
161 | | abort(); \ |
162 | | } |
163 | | |
164 | | #ifdef __cplusplus |
165 | | } |
166 | | #endif |
167 | | |
168 | | #endif /*_TD_OS_H_*/ |