osDef.h 2.9 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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/>.
 */

#ifndef TDENGINE_OS_DEF_H
#define TDENGINE_OS_DEF_H

#ifdef __cplusplus
extern "C" {
#endif

S
TD-1207  
Shengliang Guan 已提交
23 24 25 26
#ifndef WINDOWS
  #ifndef O_BINARY
    #define O_BINARY 0
  #endif
S
TD-1207  
Shengliang Guan 已提交
27 28
#endif

S
Shengliang Guan 已提交
29 30 31
#define FD_VALID(x) ((x) > STDERR_FILENO)
#define FD_INITIALIZER  ((int32_t)-1)

F
freemine 已提交
32
// #define WCHAR wchar_t
S
Shengliang Guan 已提交
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 82 83 84 85

#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2)) 

#ifndef NDEBUG
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif

#ifdef UNUSED
#undefine UNUSED
#endif
#define UNUSED(x) ((void)(x))

#ifdef UNUSED_FUNC
#undefine UNUSED_FUNC
#endif

#ifdef UNUSED_PARAM
#undef UNUSED_PARAM
#endif

#if defined(__GNUC__)
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
#define UNUSED_FUNC __attribute__((unused))
#else
#define UNUSED_PARAM(x) x
#define UNUSED_FUNC
#endif

#ifdef tListLen
#undefine tListLen
#endif
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))

#if defined(__GNUC__)
#define FORCE_INLINE inline __attribute__((always_inline))
#else
#define FORCE_INLINE
#endif

#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"

#define DEFAULT_COMP(x, y)       \
  do {                           \
    if ((x) == (y)) {            \
      return 0;                  \
    } else {                     \
      return (x) < (y) ? -1 : 1; \
    }                            \
  } while (0)

D
fix bug  
dapan1121 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99
#define DEFAULT_DOUBLE_COMP(x, y)           \
  do {                                      \
    if (isnan(x) && isnan(y)) { return 0; } \
    if (isnan(x)) { return -1; }            \
    if (isnan(y)) { return 1; }             \
    if ((x) == (y)) {                       \
      return 0;                             \
    } else {                                \
      return (x) < (y) ? -1 : 1;            \
    }                                       \
  } while (0)

#define DEFAULT_FLOAT_COMP(x, y) DEFAULT_DOUBLE_COMP(x, y)

S
Shengliang Guan 已提交
100 101 102 103 104 105 106 107 108
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))

// align to 8bytes
#define ALIGN8(n) ALIGN_NUM(n, 8)

#undef threadlocal
#ifdef _ISOC11_SOURCE
  #define threadlocal _Thread_local
#elif defined(__APPLE__)
F
freemine 已提交
109
  #define threadlocal __thread
S
Shengliang Guan 已提交
110 111 112
#elif defined(__GNUC__) && !defined(threadlocal)
  #define threadlocal __thread
#else
S
TD-1207  
Shengliang Guan 已提交
113
  #define threadlocal __declspec( thread )
S
Shengliang Guan 已提交
114 115 116 117 118 119 120
#endif

#ifdef __cplusplus
}
#endif

#endif