os.h 3.7 KB
Newer Older
S
slguan 已提交
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14
 * 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
slguan 已提交
15 16 17 18

#ifndef TDENGINE_PLATFORM_LINUX_H
#define TDENGINE_PLATFORM_LINUX_H

S
slguan 已提交
19 20 21 22 23 24 25 26 27
#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>

#include <arpa/inet.h>
#include <assert.h>
28
#include <dirent.h>
S
slguan 已提交
29
#include <endian.h>
S
slguan 已提交
30
#include <float.h>
S
slguan 已提交
31
#include <ifaddrs.h>
S
slguan 已提交
32
#include <limits.h>
33
#include <locale.h>
S
slguan 已提交
34
#include <math.h>
S
slguan 已提交
35 36 37 38 39
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
S
slguan 已提交
40 41
#include <pthread.h>
#include <pwd.h>
42 43
#include <semaphore.h>
#include <stdarg.h>
S
slguan 已提交
44 45 46 47
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
S
slguan 已提交
48 49 50
#include <sys/epoll.h>
#include <sys/file.h>
#include <sys/ioctl.h>
51
#include <sys/mman.h>
S
slguan 已提交
52 53
#include <sys/sendfile.h>
#include <sys/socket.h>
S
slguan 已提交
54
#include <sys/stat.h>
S
slguan 已提交
55 56 57 58
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/un.h>
S
slguan 已提交
59 60 61 62 63
#include <syslog.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include <wordexp.h>
S
slguan 已提交
64

S
slguan 已提交
65 66 67 68 69 70 71 72 73 74 75 76
#define taosCloseSocket(x) \
  {                        \
    if (VALIDFD(x)) {      \
      close(x);            \
      x = -1;              \
    }                      \
  }
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
#define taosReadSocket(fd, buf, len) read(fd, buf, len)

#define __sync_val_compare_and_swap_64 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap
H
hjxilinx 已提交
77

S
slguan 已提交
78 79
#define __sync_add_and_fetch_64 __sync_add_and_fetch
#define __sync_add_and_fetch_32 __sync_add_and_fetch
H
hjxilinx 已提交
80 81 82 83

#define __sync_sub_and_fetch_64 __sync_sub_and_fetch
#define __sync_sub_and_fetch_32 __sync_sub_and_fetch

S
slguan 已提交
84
int32_t __sync_val_load_32(int32_t *ptr);
85
void    __sync_val_restore_32(int32_t *ptr, int32_t newval);
S
slguan 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

#define SWAP(a, b, c)      \
  do {                     \
    typeof(a) __tmp = (a); \
    (a) = (b);             \
    (b) = __tmp;           \
  } while (0)

#define MAX(a, b)            \
  ({                         \
    typeof(a) __a = (a);     \
    typeof(b) __b = (b);     \
    (__a > __b) ? __a : __b; \
  })

#define MIN(a, b)            \
  ({                         \
    typeof(a) __a = (a);     \
    typeof(b) __b = (b);     \
    (__a < __b) ? __a : __b; \
  })

S
slguan 已提交
108
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
S
slguan 已提交
109 110 111 112 113 114 115 116 117 118 119

#define tsem_t sem_t
#define tsem_init sem_init
#define tsem_wait sem_wait
#define tsem_post sem_post
#define tsem_destroy sem_destroy

ssize_t tsendfile(int dfd, int sfd, off_t *offset, size_t size);

ssize_t twrite(int fd, void *buf, size_t n);

S
slguan 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
bool taosCheckPthreadValid(pthread_t thread);

void taosResetPthread(pthread_t *thread);

int64_t taosGetPthreadId();

int taosSetNonblocking(int sock, int on);

int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);

void tsPrintOsInfo();

char *taosCharsetReplace(char *charsetstr);

void taosGetSystemInfo();

void taosKillSystem();

S
slguan 已提交
138
bool taosSkipSocketCheck();
S
slguan 已提交
139

140 141 142
int64_t str2int64(char *str);

#define BUILDIN_CLZL(val) __builtin_clzl(val)
143
#define BUILDIN_CLZ(val) __builtin_clz(val)
144
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
145
#define BUILDIN_CTZ(val) __builtin_ctz(val)
146

S
slguan 已提交
147 148 149 150 151
#ifdef __cplusplus
}
#endif

#endif