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

F
freemine 已提交
30
// #define WCHAR wchar_t
S
Shengliang Guan 已提交
31 32 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

#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 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97
#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 已提交
98 99 100 101 102 103 104 105 106
#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 已提交
107
  #define threadlocal __thread
S
Shengliang Guan 已提交
108 109 110
#elif defined(__GNUC__) && !defined(threadlocal)
  #define threadlocal __thread
#else
S
TD-1207  
Shengliang Guan 已提交
111
  #define threadlocal __declspec( thread )
S
Shengliang Guan 已提交
112 113
#endif

S
TD-4088  
Shengliang Guan 已提交
114
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
S
TD-4088  
Shengliang Guan 已提交
115 116 117
  #define PRIzu "ld"  
#endif

S
Shengliang Guan 已提交
118 119 120 121 122
#ifdef __cplusplus
}
#endif

#endif