Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
73267640
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
73267640
编写于
5月 09, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
5月 09, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6045 from taosdata/feature/cp
Feature/cp
上级
255bf912
619a77cc
变更
63
隐藏空白更改
内联
并排
Showing
63 changed file
with
794 addition
and
990 deletion
+794
-990
cmake/define.inc
cmake/define.inc
+7
-7
cmake/env.inc
cmake/env.inc
+1
-0
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+1
-1
src/dnode/src/dnodeCfg.c
src/dnode/src/dnodeCfg.c
+1
-1
src/dnode/src/dnodeEps.c
src/dnode/src/dnodeEps.c
+1
-1
src/dnode/src/dnodeMInfos.c
src/dnode/src/dnodeMInfos.c
+1
-1
src/kit/shell/src/shellCheck.c
src/kit/shell/src/shellCheck.c
+1
-1
src/mnode/src/mnodeUser.c
src/mnode/src/mnodeUser.c
+1
-1
src/os/inc/os.h
src/os/inc/os.h
+1
-1
src/os/inc/osAtomic.h
src/os/inc/osAtomic.h
+246
-1
src/os/inc/osDarwin.h
src/os/inc/osDarwin.h
+1
-29
src/os/inc/osDef.h
src/os/inc/osDef.h
+6
-5
src/os/inc/osDir.h
src/os/inc/osDir.h
+4
-7
src/os/inc/osEok.h
src/os/inc/osEok.h
+0
-0
src/os/inc/osFile.h
src/os/inc/osFile.h
+26
-37
src/os/inc/osLinux32.h
src/os/inc/osLinux32.h
+0
-6
src/os/inc/osLz4.h
src/os/inc/osLz4.h
+16
-1
src/os/inc/osMath.h
src/os/inc/osMath.h
+28
-16
src/os/inc/osMemory.h
src/os/inc/osMemory.h
+1
-11
src/os/inc/osNingsi.h
src/os/inc/osNingsi.h
+0
-136
src/os/inc/osRand.h
src/os/inc/osRand.h
+1
-2
src/os/inc/osSemphone.h
src/os/inc/osSemphone.h
+8
-3
src/os/inc/osSignal.h
src/os/inc/osSignal.h
+1
-3
src/os/inc/osSleep.h
src/os/inc/osSleep.h
+4
-6
src/os/inc/osSocket.h
src/os/inc/osSocket.h
+32
-7
src/os/inc/osString.h
src/os/inc/osString.h
+17
-22
src/os/inc/osSysinfo.h
src/os/inc/osSysinfo.h
+12
-14
src/os/inc/osTime.h
src/os/inc/osTime.h
+9
-2
src/os/inc/osTimer.h
src/os/inc/osTimer.h
+0
-2
src/os/inc/osWindows.h
src/os/inc/osWindows.h
+0
-224
src/os/src/darwin/darwinFile.c
src/os/src/darwin/darwinFile.c
+0
-65
src/os/src/darwin/darwinString.c
src/os/src/darwin/darwinString.c
+0
-22
src/os/src/darwin/dwEnv.c
src/os/src/darwin/dwEnv.c
+0
-0
src/os/src/darwin/dwEok.c
src/os/src/darwin/dwEok.c
+2
-4
src/os/src/darwin/dwSemphone.c
src/os/src/darwin/dwSemphone.c
+0
-1
src/os/src/darwin/dwSocket.c
src/os/src/darwin/dwSocket.c
+0
-0
src/os/src/darwin/dwSysInfo.c
src/os/src/darwin/dwSysInfo.c
+0
-1
src/os/src/darwin/dwTimer.c
src/os/src/darwin/dwTimer.c
+0
-0
src/os/src/detail/osDir.c
src/os/src/detail/osDir.c
+2
-18
src/os/src/detail/osFile.c
src/os/src/detail/osFile.c
+251
-47
src/os/src/detail/osRand.c
src/os/src/detail/osRand.c
+0
-4
src/os/src/detail/osSemphone.c
src/os/src/detail/osSemphone.c
+4
-4
src/os/src/detail/osSignal.c
src/os/src/detail/osSignal.c
+3
-1
src/os/src/detail/osSleep.c
src/os/src/detail/osSleep.c
+57
-0
src/os/src/detail/osSocket.c
src/os/src/detail/osSocket.c
+4
-3
src/os/src/detail/osString.c
src/os/src/detail/osString.c
+5
-5
src/os/src/detail/osSysinfo.c
src/os/src/detail/osSysinfo.c
+1
-1
src/os/src/detail/osTimer.c
src/os/src/detail/osTimer.c
+1
-40
src/os/src/windows/wFile.c
src/os/src/windows/wFile.c
+0
-184
src/os/src/windows/wGetline.c
src/os/src/windows/wGetline.c
+11
-12
src/os/src/windows/wSocket.c
src/os/src/windows/wSocket.c
+10
-2
src/os/src/windows/wString.c
src/os/src/windows/wString.c
+7
-8
src/os/src/windows/wTimer.c
src/os/src/windows/wTimer.c
+0
-4
src/query/src/qTsbuf.c
src/query/src/qTsbuf.c
+2
-2
src/rpc/src/rpcTcp.c
src/rpc/src/rpcTcp.c
+0
-3
src/rpc/test/rserver.c
src/rpc/test/rserver.c
+1
-1
src/tsdb/inc/tsdbFile.h
src/tsdb/inc/tsdbFile.h
+1
-1
src/tsdb/src/tsdbFS.c
src/tsdb/src/tsdbFS.c
+1
-1
src/util/src/tcache.c
src/util/src/tcache.c
+0
-4
src/util/src/tfile.c
src/util/src/tfile.c
+1
-1
src/vnode/src/vnodeCfg.c
src/vnode/src/vnodeCfg.c
+1
-1
src/vnode/src/vnodeVersion.c
src/vnode/src/vnodeVersion.c
+1
-1
tests/examples/c/epoll.c
tests/examples/c/epoll.c
+1
-1
未找到文件。
cmake/define.inc
浏览文件 @
73267640
...
...
@@ -57,7 +57,7 @@ IF (TD_LINUX_64)
ADD_DEFINITIONS
(
-
D_M_X64
)
ADD_DEFINITIONS
(
-
D_TD_LINUX_64
)
MESSAGE
(
STATUS
"linux64 is defined"
)
SET
(
COMMON_FLAGS
"-
std=gnu99 -
Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
ENDIF
()
...
...
@@ -65,7 +65,7 @@ IF (TD_LINUX_32)
ADD_DEFINITIONS
(
-
D_TD_LINUX_32
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
MESSAGE
(
STATUS
"linux32 is defined"
)
SET
(
COMMON_FLAGS
"-
std=gnu99 -
Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ENDIF
()
IF
(
TD_ARM_64
)
...
...
@@ -73,7 +73,7 @@ IF (TD_ARM_64)
ADD_DEFINITIONS
(
-
D_TD_ARM_
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
MESSAGE
(
STATUS
"arm64 is defined"
)
SET
(
COMMON_FLAGS
"-
std=gnu99 -
Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ENDIF
()
IF
(
TD_ARM_32
)
...
...
@@ -81,7 +81,7 @@ IF (TD_ARM_32)
ADD_DEFINITIONS
(
-
D_TD_ARM_
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
MESSAGE
(
STATUS
"arm32 is defined"
)
SET
(
COMMON_FLAGS
"-
std=gnu99 -
Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types "
)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types "
)
ENDIF
()
IF
(
TD_MIPS_64
)
...
...
@@ -89,7 +89,7 @@ IF (TD_MIPS_64)
ADD_DEFINITIONS
(
-
D_TD_MIPS_64
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
MESSAGE
(
STATUS
"mips64 is defined"
)
SET
(
COMMON_FLAGS
"-
std=gnu99 -
Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ENDIF
()
IF
(
TD_MIPS_32
)
...
...
@@ -97,7 +97,7 @@ IF (TD_MIPS_32)
ADD_DEFINITIONS
(
-
D_TD_MIPS_32
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
MESSAGE
(
STATUS
"mips32 is defined"
)
SET
(
COMMON_FLAGS
"-
std=gnu99 -
Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
COMMON_FLAGS
"-Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
ENDIF
()
IF
(
TD_APLHINE
)
...
...
@@ -138,7 +138,7 @@ IF (TD_DARWIN_64)
ADD_DEFINITIONS
(
-
D_REENTRANT
-
D__USE_POSIX
-
D_LIBC_REENTRANT
)
ADD_DEFINITIONS
(
-
DUSE_LIBICONV
)
MESSAGE
(
STATUS
"darwin64 is defined"
)
SET
(
COMMON_FLAGS
"-
std=gnu99 -
Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
COMMON_FLAGS
"-Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE"
)
SET
(
DEBUG_FLAGS
"-O0 -g3 -DDEBUG"
)
SET
(
RELEASE_FLAGS
"-Og"
)
INCLUDE_DIRECTORIES
(
$
{
TD_COMMUNITY_DIR
}
/
deps
/
cJson
/
inc
)
...
...
cmake/env.inc
浏览文件 @
73267640
...
...
@@ -32,6 +32,7 @@ ENDIF ()
#
# Set compiler options
SET
(
COMMON_C_FLAGS
"${COMMON_FLAGS} -std=gnu99"
)
SET
(
CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} ${COMMON_FLAGS} ${DEBUG_FLAGS}"
)
SET
(
CMAKE_C_FLAGS_RELEASE
"${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FLAGS}"
)
...
...
src/client/src/tscParseInsert.c
浏览文件 @
73267640
...
...
@@ -68,7 +68,7 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1
}
else
if
(
strncmp
(
pToken
->
z
,
"0"
,
1
)
==
0
&&
pToken
->
n
==
1
)
{
// do nothing
}
else
if
(
pToken
->
type
==
TK_INTEGER
)
{
useconds
=
t
s
osStr2int64
(
pToken
->
z
);
useconds
=
t
a
osStr2int64
(
pToken
->
z
);
}
else
{
// strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
if
(
taosParseTime
(
pToken
->
z
,
time
,
pToken
->
n
,
timePrec
,
tsDaylight
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
src/dnode/src/dnodeCfg.c
浏览文件 @
73267640
...
...
@@ -158,7 +158,7 @@ static int32_t dnodeWriteCfg() {
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
fwrite
(
content
,
1
,
len
,
fp
);
f
sync
(
fileno
(
fp
));
taosF
sync
(
fileno
(
fp
));
fclose
(
fp
);
free
(
content
);
terrno
=
0
;
...
...
src/dnode/src/dnodeEps.c
浏览文件 @
73267640
...
...
@@ -277,7 +277,7 @@ static int32_t dnodeWriteEps() {
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
fwrite
(
content
,
1
,
len
,
fp
);
f
sync
(
fileno
(
fp
));
taosF
sync
(
fileno
(
fp
));
fclose
(
fp
);
free
(
content
);
terrno
=
0
;
...
...
src/dnode/src/dnodeMInfos.c
浏览文件 @
73267640
...
...
@@ -286,7 +286,7 @@ static int32_t dnodeWriteMInfos() {
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
fwrite
(
content
,
1
,
len
,
fp
);
f
sync
(
fileno
(
fp
));
taosF
sync
(
fileno
(
fp
));
fclose
(
fp
);
free
(
content
);
terrno
=
0
;
...
...
src/kit/shell/src/shellCheck.c
浏览文件 @
73267640
...
...
@@ -142,7 +142,7 @@ static void *shellCheckThreadFp(void *arg) {
taos_free_result
(
pSql
);
}
f
sync
(
fileno
(
fp
));
taosF
sync
(
fileno
(
fp
));
fclose
(
fp
);
return
NULL
;
...
...
src/mnode/src/mnodeUser.c
浏览文件 @
73267640
...
...
@@ -123,7 +123,7 @@ static void mnodePrintUserAuth() {
mnodeDecUserRef
(
pUser
);
}
f
sync
(
fileno
(
fp
));
taosF
sync
(
fileno
(
fp
));
fclose
(
fp
);
}
...
...
src/os/inc/os.h
浏览文件 @
73267640
...
...
@@ -58,7 +58,6 @@ extern "C" {
#include "osDef.h"
#include "osAtomic.h"
#include "osCommon.h"
#include "osDir.h"
#include "osFile.h"
#include "osLz4.h"
...
...
@@ -67,6 +66,7 @@ extern "C" {
#include "osRand.h"
#include "osSemphone.h"
#include "osSignal.h"
#include "osSleep.h"
#include "osSocket.h"
#include "osString.h"
#include "osSysinfo.h"
...
...
src/os/inc/osAtomic.h
浏览文件 @
73267640
...
...
@@ -20,7 +20,252 @@
extern
"C"
{
#endif
#ifndef TAOS_OS_FUNC_ATOMIC
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#else
#define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#endif
#ifdef _TD_GO_DLL_
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#else
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
#endif
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
char
interlocked_add_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_add_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_add_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_add_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
char
interlocked_and_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_and_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_and_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_and_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
__int64
interlocked_fetch_and_64
(
__int64
volatile
*
ptr
,
__int64
val
);
char
interlocked_or_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_or_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_or_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_or_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
char
interlocked_xor_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_xor_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_xor_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_xor_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
__int64
interlocked_fetch_xor_64
(
__int64
volatile
*
ptr
,
__int64
val
);
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _TD_GO_DLL_
#define atomic_fetch_add_8 __sync_fetch_and_ad
#define atomic_fetch_add_16 __sync_fetch_and_add
#else
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#endif
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_add_fetch_ptr atomic_add_fetch_64
#define atomic_fetch_add_ptr atomic_fetch_add_64
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
#define atomic_and_fetch_ptr atomic_and_fetch_64
#define atomic_fetch_and_ptr atomic_fetch_and_64
#define atomic_or_fetch_ptr atomic_or_fetch_64
#define atomic_fetch_or_ptr atomic_fetch_or_64
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
#else
#define atomic_add_fetch_ptr atomic_add_fetch_32
#define atomic_fetch_add_ptr atomic_fetch_add_32
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
#define atomic_and_fetch_ptr atomic_and_fetch_32
#define atomic_fetch_and_ptr atomic_fetch_and_32
#define atomic_or_fetch_ptr atomic_or_fetch_32
#define atomic_fetch_or_ptr atomic_fetch_or_32
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
#endif
#elif defined(_TD_NINGSI_60)
/*
* type __sync_fetch_and_add (type *ptr, type value);
* type __sync_fetch_and_sub (type *ptr, type value);
* type __sync_fetch_and_or (type *ptr, type value);
* type __sync_fetch_and_and (type *ptr, type value);
* type __sync_fetch_and_xor (type *ptr, type value);
* type __sync_fetch_and_nand (type *ptr, type value);
* type __sync_add_and_fetch (type *ptr, type value);
* type __sync_sub_and_fetch (type *ptr, type value);
* type __sync_or_and_fetch (type *ptr, type value);
* type __sync_and_and_fetch (type *ptr, type value);
* type __sync_xor_and_fetch (type *ptr, type value);
* type __sync_nand_and_fetch (type *ptr, type value);
*
* bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...)
* type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...)
* */
#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_store_8(ptr, val) (*(ptr)=(val))
#define atomic_store_16(ptr, val) (*(ptr)=(val))
#define atomic_store_32(ptr, val) (*(ptr)=(val))
#define atomic_store_64(ptr, val) (*(ptr)=(val))
#define atomic_store_ptr(ptr, val) (*(ptr)=(val))
int8_t
atomic_exchange_8_impl
(
int8_t
*
ptr
,
int8_t
val
);
int16_t
atomic_exchange_16_impl
(
int16_t
*
ptr
,
int16_t
val
);
int32_t
atomic_exchange_32_impl
(
int32_t
*
ptr
,
int32_t
val
);
int64_t
atomic_exchange_64_impl
(
int64_t
*
ptr
,
int64_t
val
);
void
*
atomic_exchange_ptr_impl
(
void
**
ptr
,
void
*
val
);
#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val)
#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val)
#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val)
#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val)
#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val)
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val))
#else
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
...
...
src/os/inc/osDarwin.h
浏览文件 @
73267640
...
...
@@ -71,24 +71,9 @@ extern "C" {
#include <fcntl.h>
#include <sys/utsname.h>
#include <math.h>
#define TAOS_OS_FUNC_FILE_SENDIFLE
#define TAOS_OS_FUNC_SEMPHONE
typedef
struct
tsem_s
*
tsem_t
;
int
tsem_init
(
tsem_t
*
sem
,
int
pshared
,
unsigned
int
value
);
int
tsem_wait
(
tsem_t
*
sem
);
int
tsem_post
(
tsem_t
*
sem
);
int
tsem_destroy
(
tsem_t
*
sem
);
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#define TAOS_OS_FUNC_STRING_STR2INT64
#define TAOS_OS_FUNC_SYSINFO
#define TAOS_OS_FUNC_TIMER
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
#include "osEok.h"
// specific
#define htobe64 htonll
typedef
int
(
*
__compar_fn_t
)(
const
void
*
,
const
void
*
);
// for send function in tsocket.c
...
...
@@ -106,19 +91,6 @@ typedef int(*__compar_fn_t)(const void *, const void *);
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif
#define TAOS_OS_FUNC_PTHREAD_RWLOCK
int64_t
tsosStr2int64
(
char
*
str
);
#include "eok.h"
void
taos_block_sigalrm
(
void
);
#define TAOS_OS_DEF_EPOLL
#define TAOS_EPOLL_WAIT_TIME 500
typedef
int32_t
SOCKET
;
typedef
SOCKET
EpollFd
;
#define EpollClose(pollFd) epoll_close(pollFd)
#ifdef __cplusplus
}
...
...
src/os/inc/osDef.h
浏览文件 @
73267640
...
...
@@ -26,11 +26,6 @@ extern "C" {
#endif
#endif
#define FD_VALID(x) ((x) > STDERR_FILENO)
#define FD_INITIALIZER ((int32_t)-1)
// #define WCHAR wchar_t
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
...
...
@@ -113,6 +108,12 @@ extern "C" {
#define threadlocal __declspec( thread )
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define PRIzu "ld"
#else
#define PRIzu "zu"
#endif
#ifdef __cplusplus
}
#endif
...
...
src/os/inc/osDir.h
浏览文件 @
73267640
...
...
@@ -20,13 +20,10 @@
extern
"C"
{
#endif
#include <sys/types.h>
// TAOS_OS_FUNC_DIR
void
taosRemoveDir
(
char
*
rootDir
);
int
taosMkDir
(
const
char
*
pathname
,
mode_t
mode
);
void
taosRemoveOldLogFiles
(
char
*
rootDir
,
int32_t
keepDays
);
int32_t
taosRename
(
char
*
oldName
,
char
*
newName
);
void
taosRemoveDir
(
char
*
rootDir
);
int32_t
taosMkDir
(
const
char
*
pathname
,
mode_t
mode
);
void
taosRemoveOldLogFiles
(
char
*
rootDir
,
int32_t
keepDays
);
int32_t
taosRename
(
char
*
oldName
,
char
*
newName
);
int32_t
taosCompressFile
(
char
*
srcFileName
,
char
*
destFileName
);
#ifdef __cplusplus
...
...
src/os/inc/
e
ok.h
→
src/os/inc/
osE
ok.h
浏览文件 @
73267640
文件已移动
src/os/inc/osFile.h
浏览文件 @
73267640
...
...
@@ -22,50 +22,39 @@ extern "C" {
#include "osSocket.h"
int64_t
taosReadImp
(
int32_t
fd
,
void
*
buf
,
int64_t
count
);
int64_t
taosWriteImp
(
int32_t
fd
,
void
*
buf
,
int64_t
count
);
int64_t
taosLSeekImp
(
int32_t
fd
,
int64_t
offset
,
int32_t
whence
);
int32_t
taosRenameFile
(
char
*
fullPath
,
char
*
suffix
,
char
delimiter
,
char
**
dstPath
);
int64_t
taosCopy
(
char
*
from
,
char
*
to
);
#define FD_VALID(x) ((x) > STDERR_FILENO)
#define FD_INITIALIZER ((int32_t)-1)
#define taosRead(fd, buf, count) taosReadImp(fd, buf, count)
#define taosWrite(fd, buf, count) taosWriteImp(fd, buf, count)
#define taosLSeek(fd, offset, whence) taosLSeekImp(fd, offset, whence)
#define taosClose(fd) \
{ \
if (FD_VALID(fd)) { \
close(fd); \
fd = FD_INITIALIZER; \
} \
}
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
// TAOS_OS_FUNC_FILE_SENDIFLE
int64_t
taosSendFile
(
SOCKET
dfd
,
int32_t
sfd
,
int64_t
*
offset
,
int64_t
size
);
int64_t
taosFSendFile
(
FILE
*
outfile
,
FILE
*
infile
,
int64_t
*
offset
,
int64_t
size
);
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
typedef
int32_t
FileFd
;
typedef
SOCKET
SocketFd
;
#else
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
#endif
int64_t
taosRead
(
FileFd
fd
,
void
*
buf
,
int64_t
count
);
int64_t
taosWrite
(
FileFd
fd
,
void
*
buf
,
int64_t
count
);
#ifdef TAOS_RANDOM_FILE_FAIL
void
taosSetRandomFileFailFactor
(
int32_t
factor
);
void
taosSetRandomFileFailOutput
(
const
char
*
path
);
#ifdef TAOS_RANDOM_FILE_FAIL_TEST
int64_t
taosReadFileRandomFail
(
int32_t
fd
,
void
*
buf
,
int32_t
count
,
const
char
*
file
,
uint32_t
line
);
int64_t
taosWriteFileRandomFail
(
int32_t
fd
,
void
*
buf
,
int32_t
count
,
const
char
*
file
,
uint32_t
line
);
int64_t
taosLSeekRandomFail
(
int32_t
fd
,
int64_t
offset
,
int32_t
whence
,
const
char
*
file
,
uint32_t
line
);
#undef taosRead
#undef taosWrite
#undef taosLSeek
#define taosRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
#define taosWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
#endif
#endif
int64_t
taosLSeek
(
FileFd
fd
,
int64_t
offset
,
int32_t
whence
);
int32_t
taosFtruncate
(
FileFd
fd
,
int64_t
length
);
int32_t
taosFsync
(
FileFd
fd
);
int32_t
taosRename
(
char
*
oldName
,
char
*
newName
);
int64_t
taosCopy
(
char
*
from
,
char
*
to
);
int64_t
taosSendFile
(
SocketFd
dfd
,
FileFd
sfd
,
int64_t
*
offset
,
int64_t
size
);
int64_t
taosFSendFile
(
FILE
*
outfile
,
FILE
*
infile
,
int64_t
*
offset
,
int64_t
size
);
// TAOS_OS_FUNC_FILE_GETTMPFILEPATH
void
taosGetTmpfilePath
(
const
char
*
fileNamePrefix
,
char
*
dstPath
);
void
taosClose
(
FileFd
fd
);
// TAOS_OS_FUNC_FILE_FTRUNCATE
int32_t
taosFtruncate
(
int32_t
fd
,
int64_t
length
);
#ifdef __cplusplus
}
#endif
#endif
#endif
\ No newline at end of file
src/os/inc/osLinux32.h
浏览文件 @
73267640
...
...
@@ -79,12 +79,6 @@ extern "C" {
#include <math.h>
#include <poll.h>
#define TAOS_OS_FUNC_LZ4
#define BUILDIN_CLZL(val) __builtin_clzll(val)
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZ(val) __builtin_ctz(val)
#ifdef __cplusplus
}
#endif
...
...
src/os/inc/osLz4.h
浏览文件 @
73267640
...
...
@@ -20,7 +20,22 @@
extern
"C"
{
#endif
#ifndef TAOS_OS_FUNC_LZ4
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
int32_t
BUILDIN_CLZL
(
uint64_t
val
);
int32_t
BUILDIN_CLZ
(
uint32_t
val
);
int32_t
BUILDIN_CTZL
(
uint64_t
val
);
int32_t
BUILDIN_CTZ
(
uint32_t
val
);
#elif defined (_TD_LINUX_32)
#define BUILDIN_CLZL(val) __builtin_clzll(val)
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZ(val) __builtin_ctz(val)
#elif defined (_TD_ARM_32)
#define BUILDIN_CLZL(val) __builtin_clzll(val)
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZ(val) __builtin_ctz(val)
#else
#define BUILDIN_CLZL(val) __builtin_clzl(val)
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
#define BUILDIN_CLZ(val) __builtin_clz(val)
...
...
src/os/inc/osMath.h
浏览文件 @
73267640
...
...
@@ -23,26 +23,38 @@ extern "C" {
#define POW2(x) ((x) * (x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#ifndef TAOS_OS_FUNC_MATH
#define SWAP(a, b, c) \
do { \
typeof(a) __tmp = (a); \
(a) = (b); \
(b) = __tmp; \
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define SWAP(a, b, c) \
do { \
c __tmp = (c)(a); \
(a) = (c)(b); \
(b) = __tmp; \
} while (0)
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#else
#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 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; \
#define MIN(a, b) \
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(__a < __b) ? __a : __b; \
})
#endif
...
...
src/os/inc/osMemory.h
浏览文件 @
73267640
...
...
@@ -43,9 +43,6 @@ void taosTMemset(void *ptr, int c);
#define tmalloc(size) malloc(size)
#define tcalloc(num, size) calloc(num, size)
#define trealloc(ptr, size) realloc(ptr, size)
#define tstrdup(str) taosStrdupImp(str)
#define tstrndup(str, size) taosStrndupImp(str, size)
#define tgetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream)
#define tfree(x) \
do { \
if (x) { \
...
...
@@ -71,15 +68,8 @@ void taosTMemset(void *ptr, int c);
#define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__)
#define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__)
#define tfree(ptr) taosFreeMem(ptr, __FILE__, __LINE__)
// #undef tstrdup
// #undef tstrndup
// #undef tgetline
// #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__)
// #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__)
// #define tgetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__)
#endif
#endif
#endif
#ifdef __cplusplus
}
...
...
src/os/inc/osNingsi.h
已删除
100644 → 0
浏览文件 @
255bf912
/*
* 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_NINGSI_H
#define TDENGINE_OS_NINGSI_H
#ifdef __cplusplus
extern
"C"
{
#endif
#define TAOS_OS_FUNC_ATOMIC
/*
* type __sync_fetch_and_add (type *ptr, type value);
* type __sync_fetch_and_sub (type *ptr, type value);
* type __sync_fetch_and_or (type *ptr, type value);
* type __sync_fetch_and_and (type *ptr, type value);
* type __sync_fetch_and_xor (type *ptr, type value);
* type __sync_fetch_and_nand (type *ptr, type value);
* type __sync_add_and_fetch (type *ptr, type value);
* type __sync_sub_and_fetch (type *ptr, type value);
* type __sync_or_and_fetch (type *ptr, type value);
* type __sync_and_and_fetch (type *ptr, type value);
* type __sync_xor_and_fetch (type *ptr, type value);
* type __sync_nand_and_fetch (type *ptr, type value);
*
* bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...)
* type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...)
* */
#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0)
#define atomic_store_8(ptr, val) (*(ptr)=(val))
#define atomic_store_16(ptr, val) (*(ptr)=(val))
#define atomic_store_32(ptr, val) (*(ptr)=(val))
#define atomic_store_64(ptr, val) (*(ptr)=(val))
#define atomic_store_ptr(ptr, val) (*(ptr)=(val))
int8_t
atomic_exchange_8_impl
(
int8_t
*
ptr
,
int8_t
val
);
int16_t
atomic_exchange_16_impl
(
int16_t
*
ptr
,
int16_t
val
);
int32_t
atomic_exchange_32_impl
(
int32_t
*
ptr
,
int32_t
val
);
int64_t
atomic_exchange_64_impl
(
int64_t
*
ptr
,
int64_t
val
);
void
*
atomic_exchange_ptr_impl
(
void
**
ptr
,
void
*
val
);
#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val)
#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val)
#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val)
#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val)
#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val)
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val))
#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val))
#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val))
#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val))
#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val))
#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val))
#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val))
#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val))
#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val))
#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val))
#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val))
#ifdef __cplusplus
}
#endif
#endif
src/os/inc/osRand.h
浏览文件 @
73267640
...
...
@@ -20,9 +20,8 @@
extern
"C"
{
#endif
// TAOS_OS_FUNC_RAND
uint32_t
taosRand
(
void
);
void
taosRandStr
(
char
*
str
,
int32_t
size
);
void
taosRandStr
(
char
*
str
,
int32_t
size
);
uint32_t
taosSafeRand
(
void
);
#ifdef __cplusplus
...
...
src/os/inc/osSemphone.h
浏览文件 @
73267640
...
...
@@ -20,7 +20,13 @@
extern
"C"
{
#endif
#ifndef TAOS_OS_FUNC_SEMPHONE
#if defined (_TD_DARWIN_64)
typedef
struct
tsem_s
*
tsem_t
;
int
tsem_init
(
tsem_t
*
sem
,
int
pshared
,
unsigned
int
value
);
int
tsem_wait
(
tsem_t
*
sem
);
int
tsem_post
(
tsem_t
*
sem
);
int
tsem_destroy
(
tsem_t
*
sem
);
#else
#define tsem_t sem_t
#define tsem_init sem_init
int
tsem_wait
(
tsem_t
*
sem
);
...
...
@@ -28,7 +34,7 @@ extern "C" {
#define tsem_destroy sem_destroy
#endif
#if
def TAOS_OS_FUNC_PTHREAD_RWLOCK
#if
defined (_TD_DARWIN_64)
#define pthread_rwlock_t pthread_mutex_t
#define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
#define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
...
...
@@ -43,7 +49,6 @@ extern "C" {
#define pthread_spin_unlock(lock) pthread_mutex_unlock(lock)
#endif
// TAOS_OS_FUNC_SEMPHONE_PTHREAD
bool
taosCheckPthreadValid
(
pthread_t
thread
);
int64_t
taosGetSelfPthreadId
();
int64_t
taosGetPthreadId
(
pthread_t
thread
);
...
...
src/os/inc/osSignal.h
浏览文件 @
73267640
...
...
@@ -20,8 +20,6 @@
extern
"C"
{
#endif
#include "os.h"
#include "taosdef.h"
#include <signal.h>
#ifndef SIGALRM
...
...
@@ -57,4 +55,4 @@ void taosDflSignal(int32_t signum);
}
#endif
#endif // TDENGINE_
TTIME
_H
#endif // TDENGINE_
OS_SIGNAL
_H
src/os/inc/os
Common
.h
→
src/os/inc/os
Sleep
.h
浏览文件 @
73267640
...
...
@@ -13,19 +13,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_OS_
COMMON
_H
#define TDENGINE_OS_
COMMON
_H
#ifndef TDENGINE_OS_
SLEEP
_H
#define TDENGINE_OS_
SLEEP
_H
#ifdef __cplusplus
extern
"C"
{
#endif
#ifndef TAOS_OS_DEF_ZU
#define PRIzu "zu"
#endif
void
taosMsleep
(
int32_t
ms
);
#ifdef __cplusplus
}
#endif
#endif
#endif
\ No newline at end of file
src/os/inc/osSocket.h
浏览文件 @
73267640
...
...
@@ -20,7 +20,14 @@
extern
"C"
{
#endif
#ifndef TAOS_OS_FUNC_SOCKET_OP
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags)
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen)
#define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0)
#define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0)
#define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd)
#define taosCloseSocket(fd) closesocket((SOCKET)fd)
#else
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
...
...
@@ -35,7 +42,21 @@ extern "C" {
}
#endif
#ifndef TAOS_OS_DEF_EPOLL
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define TAOS_EPOLL_WAIT_TIME 100
typedef
SOCKET
eventfd_t
;
#define eventfd(a, b) -1
typedef
SOCKET
EpollFd
;
#define EpollClose(pollFd) epoll_close(pollFd)
#ifndef EPOLLWAKEUP
#define EPOLLWAKEUP (1u << 29)
#endif
#elif defined(_TD_DARWIN_64)
#define TAOS_EPOLL_WAIT_TIME 500
typedef
int32_t
SOCKET
;
typedef
SOCKET
EpollFd
;
#define EpollClose(pollFd) epoll_close(pollFd)
#else
#define TAOS_EPOLL_WAIT_TIME 500
typedef
int32_t
SOCKET
;
typedef
SOCKET
EpollFd
;
...
...
@@ -59,21 +80,25 @@ extern "C" {
#endif
#endif
// TAOS_OS_FUNC_SOCKET
int32_t
taosSetNonblocking
(
SOCKET
sock
,
int32_t
on
);
void
taosIgnSIGPIPE
();
void
taosBlockSIGPIPE
();
void
taosSetMaskSIGPIPE
();
// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
int32_t
taosSetSockOpt
(
SOCKET
socketfd
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
optlen
);
int32_t
taosGetSockOpt
(
SOCKET
socketfd
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
*
optlen
);
// TAOS_OS_FUNC_SOCKET_INET
uint32_t
taosInetAddr
(
char
*
ipAddr
);
const
char
*
taosInetNtoa
(
struct
in_addr
ipInt
);
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#define htobe64 htonll
#if defined(_TD_GO_DLL_)
uint64_t
htonll
(
uint64_t
val
);
#endif
#elif defined(_TD_DARWIN_64)
#define htobe64 htonll
#endif
#ifdef __cplusplus
}
#endif
...
...
src/os/inc/osString.h
浏览文件 @
73267640
...
...
@@ -20,35 +20,30 @@
extern
"C"
{
#endif
#ifndef TAOS_OS_FUNC_STRING_STRDUP
#define taosStrdupImp(str) strdup(str)
#define taosStrndupImp(str, size) strndup(str, size)
#endif
#ifndef TAOS_OS_FUNC_STRING_GETLINE
#define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream)
#else
int
taosGetlineImp
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
#endif
#ifndef TAOS_OS_FUNC_STRING_WCHAR
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define tstrdup(str) _strdup(str)
#define tstrndup(str, size) _strndup(str, size)
int32_t
tgetline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
int32_t
twcslen
(
const
wchar_t
*
wcs
);
#else
#define tstrdup(str) strdup(str)
#define tstrndup(str, size) strndup(str, size)
#define tgetline(lineptr, n, stream) getline(lineptr, n, stream)
#define twcslen wcslen
#endif
#endif
#define tstrncpy(dst, src, size)
\
do { \
strncpy((dst), (src), (size)); \
(dst)[(size)-1] = 0; \
#define tstrncpy(dst, src, size) \
do {
\
strncpy((dst), (src), (size));
\
(dst)[(size)-1] = 0;
\
} while (0)
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
int64_t
tsosStr2int64
(
char
*
str
);
#endif
int64_t
taosStr2int64
(
char
*
str
);
// USE_LIBICONV
int32_t
taosUcs4ToMbs
(
void
*
ucs4
,
int32_t
ucs4_max_len
,
char
*
mbs
);
bool
taosMbsToUcs4
(
char
*
mbs
,
size_t
mbs_len
,
char
*
ucs4
,
int32_t
ucs4_max_len
,
int
*
len
);
int
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
in
t
bytes
);
bool
taosMbsToUcs4
(
char
*
mbs
,
size_t
mbs_len
,
char
*
ucs4
,
int32_t
ucs4_max_len
,
int
32_t
*
len
);
int
32_t
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int32_
t
bytes
);
bool
taosValidateEncodec
(
const
char
*
encodec
);
char
*
taosCharsetReplace
(
char
*
charsetstr
);
...
...
src/os/inc/osSysinfo.h
浏览文件 @
73267640
...
...
@@ -20,7 +20,6 @@
extern
"C"
{
#endif
// TAOS_OS_FUNC_SYSINFO
typedef
struct
{
int64_t
tsize
;
int64_t
used
;
...
...
@@ -28,20 +27,19 @@ typedef struct {
}
SysDiskSize
;
int32_t
taosGetDiskSize
(
char
*
dataDir
,
SysDiskSize
*
diskSize
);
void
taosGetSystemInfo
();
bool
taosGetProcIO
(
float
*
readKB
,
float
*
writeKB
);
bool
taosGetBandSpeed
(
float
*
bandSpeedKb
);
void
taosGetDisk
();
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
;
bool
taosGetProcMemory
(
float
*
memoryUsedMB
)
;
bool
taosGetSysMemory
(
float
*
memoryUsedMB
);
void
taosPrintOsInfo
();
int
taosSystem
(
const
char
*
cmd
)
;
void
taosKillSystem
();
bool
taosGetSystemUid
(
char
*
uid
);
char
*
taosGetCmdlineByPID
(
int
pid
);
void
taosGetSystemInfo
();
bool
taosGetProcIO
(
float
*
readKB
,
float
*
writeKB
);
bool
taosGetBandSpeed
(
float
*
bandSpeedKb
);
void
taosGetDisk
();
bool
taosGetCpuUsage
(
float
*
sysCpuUsage
,
float
*
procCpuUsage
)
;
bool
taosGetProcMemory
(
float
*
memoryUsedMB
)
;
bool
taosGetSysMemory
(
float
*
memoryUsedMB
);
void
taosPrintOsInfo
();
int
taosSystem
(
const
char
*
cmd
)
;
void
taosKillSystem
();
bool
taosGetSystemUid
(
char
*
uid
);
char
*
taosGetCmdlineByPID
(
int
pid
);
// TAOS_OS_FUNC_SYSINFO_CORE
void
taosSetCoreDump
();
#ifdef __cplusplus
...
...
src/os/inc/osTime.h
浏览文件 @
73267640
...
...
@@ -23,9 +23,16 @@ extern "C" {
#include "os.h"
#include "taosdef.h"
#ifndef TAOS_OS_FUNC_TIME_DEF
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL)
#else
#define MILLISECOND_PER_SECOND (1000i64)
#endif
#else
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
#endif
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
...
...
@@ -85,7 +92,7 @@ int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts);
int32_t
parseNatualDuration
(
const
char
*
token
,
int32_t
tokenLen
,
int64_t
*
duration
,
char
*
unit
);
int32_t
taosParseTime
(
char
*
timestr
,
int64_t
*
time
,
int32_t
len
,
int32_t
timePrec
,
int8_t
dayligth
);
void
deltaToUtcInitOnce
();
void
deltaToUtcInitOnce
();
#ifdef __cplusplus
}
...
...
src/os/inc/osTimer.h
浏览文件 @
73267640
...
...
@@ -20,8 +20,6 @@
extern
"C"
{
#endif
// TAOS_OS_FUNC_TIMER
void
taosMsleep
(
int
mseconds
);
int
taosInitTimer
(
void
(
*
callback
)(
int
),
int
ms
);
void
taosUninitTimer
();
...
...
src/os/inc/osWindows.h
浏览文件 @
73267640
...
...
@@ -55,87 +55,9 @@
extern
"C"
{
#endif
#define TAOS_OS_FUNC_LZ4
int32_t
BUILDIN_CLZL
(
uint64_t
val
);
int32_t
BUILDIN_CLZ
(
uint32_t
val
);
int32_t
BUILDIN_CTZL
(
uint64_t
val
);
int32_t
BUILDIN_CTZ
(
uint32_t
val
);
#define TAOS_OS_FUNC_FILE
#define TAOS_OS_FUNC_FILE_ISREG
#define TAOS_OS_FUNC_FILE_ISDIR
#define TAOS_OS_FUNC_FILE_ISLNK
#define TAOS_OS_FUNC_FILE_SENDIFLE
#define TAOS_OS_FUNC_FILE_GETTMPFILEPATH
#define TAOS_OS_FUNC_FILE_FTRUNCATE
#define TAOS_OS_FUNC_DIR
#define TAOS_OS_FUNC_MATH
#define SWAP(a, b, c) \
do { \
c __tmp = (c)(a); \
(a) = (c)(b); \
(b) = __tmp; \
} while (0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define TAOS_OS_FUNC_SEMPHONE_PTHREAD
#define TAOS_OS_FUNC_SOCKET
#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#define TAOS_OS_FUNC_SOCKET_OP
#define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags)
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen)
#define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0)
#define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0)
#define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd)
#define taosCloseSocket(fd) closesocket((SOCKET)fd)
typedef
SOCKET
eventfd_t
;
#define eventfd(a, b) -1
#define TAOS_OS_DEF_EPOLL
#define TAOS_EPOLL_WAIT_TIME 100
typedef
SOCKET
EpollFd
;
#define EpollClose(pollFd) epoll_close(pollFd)
#ifndef EPOLLWAKEUP
#define EPOLLWAKEUP (1u << 29)
#endif
#define TAOS_OS_DEF_ZU
#define PRIzu "ld"
#define TAOS_OS_FUNC_STRING_WCHAR
int
twcslen
(
const
wchar_t
*
wcs
);
#define TAOS_OS_FUNC_STRING_GETLINE
#define TAOS_OS_FUNC_STRING_STR2INT64
#ifdef _TD_GO_DLL_
int64_t
tsosStr2int64
(
char
*
str
);
uint64_t
htonll
(
uint64_t
val
);
#else
#define tsosStr2int64 _atoi64
#endif
#define TAOS_OS_FUNC_STRING_STRDUP
#define taosStrdupImp(str) _strdup(str)
#define taosStrndupImp(str, size) _strndup(str, size)
char
*
stpcpy
(
char
*
dest
,
const
char
*
src
);
char
*
stpncpy
(
char
*
dest
,
const
char
*
src
,
size_t
n
);
#define TAOS_OS_FUNC_SYSINFO
#define TAOS_OS_FUNC_TIME_DEF
#ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL)
#else
#define MILLISECOND_PER_SECOND (1000i64)
#endif
#define TAOS_OS_FUNC_TIMER_SLEEP
#define TAOS_OS_FUNC_TIMER
// specific
typedef
int
(
*
__compar_fn_t
)(
const
void
*
,
const
void
*
);
#define ssize_t int
...
...
@@ -147,14 +69,12 @@ typedef int (*__compar_fn_t)(const void *, const void *);
#define snprintf _snprintf
#define in_addr_t unsigned long
#define socklen_t int
#define htobe64 htonll
struct
tm
*
localtime_r
(
const
time_t
*
timep
,
struct
tm
*
result
);
char
*
strptime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
);
char
*
strsep
(
char
**
stringp
,
const
char
*
delim
);
char
*
getpass
(
const
char
*
prefix
);
int
flock
(
int
fd
,
int
option
);
int
fsync
(
int
filedes
);
char
*
strndup
(
const
char
*
s
,
size_t
n
);
int
gettimeofday
(
struct
timeval
*
ptv
,
void
*
pTimeZone
);
...
...
@@ -175,12 +95,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone);
#define TCP_KEEPINTVL 0x1234
#endif
#ifdef _MSC_VER
//#if _MSC_VER >= 1900
#define TAOS_OS_FUNC_SOCKET_INET
//#endif
#endif
#define SHUT_RDWR SD_BOTH
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
...
...
@@ -193,8 +107,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone);
#define PATH_MAX 256
#endif
#define TAOS_OS_FUNC_SIGNAL
typedef
struct
{
int
we_wordc
;
char
*
we_wordv
[
1
];
...
...
@@ -210,142 +122,6 @@ void wordfree(wordexp_t *pwordexp);
#define LOG_INFO 1
void
syslog
(
int
unused
,
const
char
*
format
,
...);
#define TAOS_OS_FUNC_ATOMIC
#define atomic_load_8(ptr) (*(char volatile*)(ptr))
#define atomic_load_16(ptr) (*(short volatile*)(ptr))
#define atomic_load_32(ptr) (*(long volatile*)(ptr))
#define atomic_load_64(ptr) (*(__int64 volatile*)(ptr))
#define atomic_load_ptr(ptr) (*(void* volatile*)(ptr))
#define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val))
#define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val))
#define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val))
#define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val))
#define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val))
#define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val))
#define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val))
#define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val))
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#else
#define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#endif
#ifdef _TD_GO_DLL_
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
#else
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
#endif
#define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
#define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
#define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
#define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
char
interlocked_add_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_add_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_add_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_add_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
char
interlocked_and_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_and_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_and_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_and_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
__int64
interlocked_fetch_and_64
(
__int64
volatile
*
ptr
,
__int64
val
);
char
interlocked_or_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_or_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_or_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_or_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
char
interlocked_xor_fetch_8
(
char
volatile
*
ptr
,
char
val
);
short
interlocked_xor_fetch_16
(
short
volatile
*
ptr
,
short
val
);
long
interlocked_xor_fetch_32
(
long
volatile
*
ptr
,
long
val
);
__int64
interlocked_xor_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
);
__int64
interlocked_fetch_xor_64
(
__int64
volatile
*
ptr
,
__int64
val
);
#define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _TD_GO_DLL_
#define atomic_fetch_add_8 __sync_fetch_and_ad
#define atomic_fetch_add_16 __sync_fetch_and_add
#else
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#endif
#define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
#define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_add_fetch_ptr atomic_add_fetch_64
#define atomic_fetch_add_ptr atomic_fetch_add_64
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
#define atomic_and_fetch_ptr atomic_and_fetch_64
#define atomic_fetch_and_ptr atomic_fetch_and_64
#define atomic_or_fetch_ptr atomic_or_fetch_64
#define atomic_fetch_or_ptr atomic_fetch_or_64
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
#else
#define atomic_add_fetch_ptr atomic_add_fetch_32
#define atomic_fetch_add_ptr atomic_fetch_add_32
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
#define atomic_and_fetch_ptr atomic_and_fetch_32
#define atomic_fetch_and_ptr atomic_fetch_and_32
#define atomic_or_fetch_ptr atomic_or_fetch_32
#define atomic_fetch_or_ptr atomic_fetch_or_32
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
#endif
#ifdef __cplusplus
}
#endif
...
...
src/os/src/darwin/darwinFile.c
已删除
100644 → 0
浏览文件 @
255bf912
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tulog.h"
int64_t
taosFSendFile
(
FILE
*
out_file
,
FILE
*
in_file
,
int64_t
*
offset
,
int64_t
count
)
{
int
r
=
0
;
if
(
offset
)
{
r
=
fseek
(
in_file
,
*
offset
,
SEEK_SET
);
if
(
r
==-
1
)
return
-
1
;
}
off_t
len
=
count
;
while
(
len
>
0
)
{
char
buf
[
1024
*
16
];
off_t
n
=
sizeof
(
buf
);
if
(
len
<
n
)
n
=
len
;
size_t
m
=
fread
(
buf
,
1
,
n
,
in_file
);
if
(
m
<
n
)
{
int
e
=
ferror
(
in_file
);
if
(
e
)
return
-
1
;
}
if
(
m
==
0
)
break
;
if
(
m
!=
fwrite
(
buf
,
1
,
m
,
out_file
))
{
return
-
1
;
}
len
-=
m
;
}
return
count
-
len
;
}
int64_t
taosSendFile
(
SOCKET
dfd
,
int32_t
sfd
,
int64_t
*
offset
,
int64_t
count
)
{
int
r
=
0
;
if
(
offset
)
{
r
=
lseek
(
sfd
,
*
offset
,
SEEK_SET
);
if
(
r
==-
1
)
return
-
1
;
}
off_t
len
=
count
;
while
(
len
>
0
)
{
char
buf
[
1024
*
16
];
off_t
n
=
sizeof
(
buf
);
if
(
len
<
n
)
n
=
len
;
size_t
m
=
read
(
sfd
,
buf
,
n
);
if
(
m
==-
1
)
return
-
1
;
if
(
m
==
0
)
break
;
size_t
l
=
write
(
dfd
,
buf
,
m
);
if
(
l
==-
1
)
return
-
1
;
len
-=
l
;
}
return
count
-
len
;
}
src/os/src/darwin/darwinString.c
已删除
100644 → 0
浏览文件 @
255bf912
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
int64_t
tsosStr2int64
(
char
*
str
)
{
char
*
endptr
=
NULL
;
return
strtoll
(
str
,
&
endptr
,
10
);
}
src/os/src/darwin/d
arwin
Env.c
→
src/os/src/darwin/d
w
Env.c
浏览文件 @
73267640
文件已移动
src/os/src/darwin/
e
ok.c
→
src/os/src/darwin/
dwE
ok.c
浏览文件 @
73267640
...
...
@@ -18,9 +18,9 @@
// https://stackoverflow.com/questions/4393197/erlangs-let-it-crash-philosophy-applicable-elsewhere
// experimentally, we follow log-and-crash here
#include "eok.h"
#define _DEFAULT_SOURCE
#include "os.h"
#include "osEok.h"
#include <sys/event.h>
...
...
@@ -415,8 +415,6 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) {
static
struct
timespec
do_timespec_diff
(
struct
timespec
*
from
,
struct
timespec
*
to
);
int
epoll_wait
(
int
epfd
,
struct
epoll_event
*
events
,
int
maxevents
,
int
timeout
)
{
taos_block_sigalrm
();
int
e
=
0
;
if
(
!
events
)
{
errno
=
EINVAL
;
...
...
src/os/src/darwin/d
arwin
Semphone.c
→
src/os/src/darwin/d
w
Semphone.c
浏览文件 @
73267640
...
...
@@ -20,7 +20,6 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include <libproc.h>
// #define SEM_USE_PTHREAD
...
...
src/os/src/darwin/d
arwin
Socket.c
→
src/os/src/darwin/d
w
Socket.c
浏览文件 @
73267640
文件已移动
src/os/src/darwin/d
arwin
SysInfo.c
→
src/os/src/darwin/d
w
SysInfo.c
浏览文件 @
73267640
...
...
@@ -22,7 +22,6 @@
#include <errno.h>
#include <libproc.h>
static
void
taosGetSystemTimezone
()
{
SGlobalCfg
*
cfg_timezone
=
taosGetConfigOption
(
"timezone"
);
if
(
cfg_timezone
==
NULL
)
return
;
...
...
src/os/src/darwin/d
arwin
Timer.c
→
src/os/src/darwin/d
w
Timer.c
浏览文件 @
73267640
文件已移动
src/os/src/detail/osDir.c
浏览文件 @
73267640
...
...
@@ -28,7 +28,7 @@ void taosRemoveDir(char *rootDir) {
struct
dirent
*
de
=
NULL
;
while
((
de
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
continue
;
char
filename
[
1024
];
snprintf
(
filename
,
1023
,
"%s/%s"
,
rootDir
,
de
->
d_name
);
if
(
de
->
d_type
&
DT_DIR
)
{
...
...
@@ -51,27 +51,11 @@ int taosMkDir(const char *path, mode_t mode) {
return
code
;
}
#ifndef TAOS_OS_FUNC_DIR
int32_t
taosRename
(
char
*
oldName
,
char
*
newName
)
{
int32_t
code
=
rename
(
oldName
,
newName
);
if
(
code
<
0
)
{
uError
(
"failed to rename file %s to %s, reason:%s"
,
oldName
,
newName
,
strerror
(
errno
));
}
else
{
uTrace
(
"successfully to rename file %s to %s"
,
oldName
,
newName
);
}
return
code
;
}
#endif
void
taosRemoveOldLogFiles
(
char
*
rootDir
,
int32_t
keepDays
)
{
DIR
*
dir
=
opendir
(
rootDir
);
if
(
dir
==
NULL
)
return
;
int64_t
sec
=
taosGetTimestampSec
();
int64_t
sec
=
taosGetTimestampSec
();
struct
dirent
*
de
=
NULL
;
while
((
de
=
readdir
(
dir
))
!=
NULL
)
{
...
...
src/os/src/detail/osFile.c
浏览文件 @
73267640
...
...
@@ -16,65 +16,68 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "tglobal.h"
#include "tulog.h"
#ifndef TAOS_OS_FUNC_FILE_GETTMPFILEPATH
void
taosClose
(
FileFd
fd
)
{
close
(
fd
);
fd
=
FD_INITIALIZER
;
}
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void
taosGetTmpfilePath
(
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
char
tmpPath
[
PATH_MAX
];
char
tmpPath
[
PATH_MAX
];
int32_t
len
=
strlen
(
tsTempDir
);
int32_t
len
=
(
int32_t
)
strlen
(
tsTempDir
);
memcpy
(
tmpPath
,
tsTempDir
,
len
);
static
uint64_t
seqId
=
0
;
if
(
tmpPath
[
len
-
1
]
!=
'/'
)
{
tmpPath
[
len
++
]
=
'/'
;
if
(
tmpPath
[
len
-
1
]
!=
'/'
&&
tmpPath
[
len
-
1
]
!=
'\\'
)
{
tmpPath
[
len
++
]
=
'\\'
;
}
strcpy
(
tmpPath
+
len
,
tdengineTmpFileNamePrefix
);
strcat
(
tmpPath
,
tdengineTmpFileNamePrefix
);
if
(
strlen
(
tmpPath
)
+
strlen
(
fileNamePrefix
)
+
strlen
(
"-%d-%s"
)
<
PATH_MAX
)
{
strcat
(
tmpPath
,
fileNamePrefix
);
strcat
(
tmpPath
,
"-%d-%s"
);
}
char
rand
[
32
]
=
{
0
};
sprintf
(
rand
,
"%"
PRIu64
,
atomic_add_fetch_64
(
&
seqId
,
1
));
char
rand
[
8
]
=
{
0
};
taosRandStr
(
rand
,
tListLen
(
rand
)
-
1
);
snprintf
(
dstPath
,
PATH_MAX
,
tmpPath
,
getpid
(),
rand
);
}
#endif
int32_t
taosRenameFile
(
char
*
fullPath
,
char
*
suffix
,
char
delimiter
,
char
**
dstPath
)
{
int32_t
ts
=
taosGetTimestampSec
();
#else
char
fname
[
PATH_MAX
]
=
{
0
};
// max file name length must be less than 255
void
taosGetTmpfilePath
(
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
char
*
delimiterPos
=
strrchr
(
fullPath
,
delimiter
);
if
(
delimiterPos
==
NULL
)
return
-
1
;
char
tmpPath
[
PATH_MAX
];
int32_t
len
=
strlen
(
tsTempDir
);
memcpy
(
tmpPath
,
tsTempDir
,
len
);
static
uint64_t
seqId
=
0
;
int32_t
fileNameLen
=
0
;
if
(
suffix
)
{
fileNameLen
=
snprintf
(
fname
,
PATH_MAX
,
"%s.%d.%s"
,
delimiterPos
+
1
,
ts
,
suffix
);
}
else
{
fileNameLen
=
snprintf
(
fname
,
PATH_MAX
,
"%s.%d"
,
delimiterPos
+
1
,
ts
);
if
(
tmpPath
[
len
-
1
]
!=
'/'
)
{
tmpPath
[
len
++
]
=
'/'
;
}
int32_t
len
=
(
int32_t
)((
delimiterPos
-
fullPath
)
+
fileNameLen
+
1
);
if
(
*
dstPath
==
NULL
)
{
*
dstPath
=
calloc
(
1
,
len
+
1
);
if
(
*
dstPath
==
NULL
)
return
-
1
;
strcpy
(
tmpPath
+
len
,
tdengineTmpFileNamePrefix
);
if
(
strlen
(
tmpPath
)
+
strlen
(
fileNamePrefix
)
+
strlen
(
"-%d-%s"
)
<
PATH_MAX
)
{
strcat
(
tmpPath
,
fileNamePrefix
);
strcat
(
tmpPath
,
"-%d-%s"
)
;
}
strncpy
(
*
dstPath
,
fullPath
,
(
size_t
)(
delimiterPos
-
fullPath
+
1
))
;
strncat
(
*
dstPath
,
fname
,
(
size_t
)
fileNameLen
);
(
*
dstPath
)[
len
]
=
0
;
char
rand
[
32
]
=
{
0
}
;
sprintf
(
rand
,
"%"
PRIu64
,
atomic_add_fetch_64
(
&
seqId
,
1
))
;
return
rename
(
fullPath
,
*
dstPath
);
snprintf
(
dstPath
,
PATH_MAX
,
tmpPath
,
getpid
(),
rand
);
}
int64_t
taosReadImp
(
int32_t
fd
,
void
*
buf
,
int64_t
count
)
{
#endif
int64_t
taosRead
(
FileFd
fd
,
void
*
buf
,
int64_t
count
)
{
int64_t
leftbytes
=
count
;
int64_t
readbytes
;
char
*
tbuf
=
(
char
*
)
buf
;
...
...
@@ -98,7 +101,7 @@ int64_t taosReadImp(int32_t fd, void *buf, int64_t count) {
return
count
;
}
int64_t
taosWrite
Imp
(
int32_t
fd
,
void
*
buf
,
int64_t
n
)
{
int64_t
taosWrite
(
FileFd
fd
,
void
*
buf
,
int64_t
n
)
{
int64_t
nleft
=
n
;
int64_t
nwritten
=
0
;
char
*
tbuf
=
(
char
*
)
buf
;
...
...
@@ -118,9 +121,7 @@ int64_t taosWriteImp(int32_t fd, void *buf, int64_t n) {
return
n
;
}
int64_t
taosLSeekImp
(
int32_t
fd
,
int64_t
offset
,
int32_t
whence
)
{
return
(
int64_t
)
lseek
(
fd
,
(
long
)
offset
,
whence
);
}
int64_t
taosLSeek
(
FileFd
fd
,
int64_t
offset
,
int32_t
whence
)
{
return
(
int64_t
)
lseek
(
fd
,
(
long
)
offset
,
whence
);
}
int64_t
taosCopy
(
char
*
from
,
char
*
to
)
{
char
buffer
[
4096
];
...
...
@@ -145,22 +146,139 @@ int64_t taosCopy(char *from, char *to) {
if
(
bytes
<
sizeof
(
buffer
))
break
;
}
f
sync
(
fidto
);
taosF
sync
(
fidto
);
c
lose
(
fidfrom
);
c
lose
(
fidto
);
taosC
lose
(
fidfrom
);
taosC
lose
(
fidto
);
return
size
;
_err:
if
(
fidfrom
>=
0
)
c
lose
(
fidfrom
);
if
(
fidto
>=
0
)
c
lose
(
fidto
);
if
(
fidfrom
>=
0
)
taosC
lose
(
fidfrom
);
if
(
fidto
>=
0
)
taosC
lose
(
fidto
);
remove
(
to
);
return
-
1
;
}
#ifndef TAOS_OS_FUNC_FILE_SENDIFLE
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define _SEND_FILE_STEP_ 1000
int64_t
taosFSendFile
(
FILE
*
out_file
,
FILE
*
in_file
,
int64_t
*
offset
,
int64_t
count
)
{
fseek
(
in_file
,
(
int32_t
)(
*
offset
),
0
);
int64_t
writeLen
=
0
;
uint8_t
buffer
[
_SEND_FILE_STEP_
]
=
{
0
};
for
(
int64_t
len
=
0
;
len
<
(
count
-
_SEND_FILE_STEP_
);
len
+=
_SEND_FILE_STEP_
)
{
size_t
rlen
=
fread
(
buffer
,
1
,
_SEND_FILE_STEP_
,
in_file
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
if
(
rlen
<
_SEND_FILE_STEP_
)
{
fwrite
(
buffer
,
1
,
rlen
,
out_file
);
return
(
int64_t
)(
writeLen
+
rlen
);
}
else
{
fwrite
(
buffer
,
1
,
_SEND_FILE_STEP_
,
in_file
);
writeLen
+=
_SEND_FILE_STEP_
;
}
}
int64_t
remain
=
count
-
writeLen
;
if
(
remain
>
0
)
{
size_t
rlen
=
fread
(
buffer
,
1
,
(
size_t
)
remain
,
in_file
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
{
fwrite
(
buffer
,
1
,
(
size_t
)
remain
,
out_file
);
writeLen
+=
remain
;
}
}
return
writeLen
;
}
int64_t
taosSendFile
(
SocketFd
dfd
,
FileFd
sfd
,
int64_t
*
offset
,
int64_t
count
)
{
if
(
offset
!=
NULL
)
lseek
(
sfd
,
(
int32_t
)(
*
offset
),
0
);
int64_t
writeLen
=
0
;
uint8_t
buffer
[
_SEND_FILE_STEP_
]
=
{
0
};
for
(
int64_t
len
=
0
;
len
<
(
count
-
_SEND_FILE_STEP_
);
len
+=
_SEND_FILE_STEP_
)
{
int32_t
rlen
=
(
int32_t
)
read
(
sfd
,
buffer
,
_SEND_FILE_STEP_
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
if
(
rlen
<
_SEND_FILE_STEP_
)
{
taosWriteSocket
(
dfd
,
buffer
,
rlen
);
return
(
int64_t
)(
writeLen
+
rlen
);
}
else
{
taosWriteSocket
(
dfd
,
buffer
,
_SEND_FILE_STEP_
);
writeLen
+=
_SEND_FILE_STEP_
;
}
}
int64_t
remain
=
count
-
writeLen
;
if
(
remain
>
0
)
{
int32_t
rlen
=
read
(
sfd
,
buffer
,
(
int32_t
)
remain
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
{
taosWriteSocket
(
sfd
,
buffer
,
(
int32_t
)
remain
);
writeLen
+=
remain
;
}
}
return
writeLen
;
}
#elif defined(_TD_DARWIN_64)
int64_t
taosSendFile
(
SOCKET
dfd
,
int32_t
sfd
,
int64_t
*
offset
,
int64_t
size
)
{
int64_t
taosFSendFile
(
FILE
*
out_file
,
FILE
*
in_file
,
int64_t
*
offset
,
int64_t
count
)
{
int
r
=
0
;
if
(
offset
)
{
r
=
fseek
(
in_file
,
*
offset
,
SEEK_SET
);
if
(
r
==
-
1
)
return
-
1
;
}
off_t
len
=
count
;
while
(
len
>
0
)
{
char
buf
[
1024
*
16
];
off_t
n
=
sizeof
(
buf
);
if
(
len
<
n
)
n
=
len
;
size_t
m
=
fread
(
buf
,
1
,
n
,
in_file
);
if
(
m
<
n
)
{
int
e
=
ferror
(
in_file
);
if
(
e
)
return
-
1
;
}
if
(
m
==
0
)
break
;
if
(
m
!=
fwrite
(
buf
,
1
,
m
,
out_file
))
{
return
-
1
;
}
len
-=
m
;
}
return
count
-
len
;
}
int64_t
taosSendFile
(
SocketFd
dfd
,
FileFd
sfd
,
int64_t
*
offset
,
int64_t
count
)
{
int
r
=
0
;
if
(
offset
)
{
r
=
lseek
(
sfd
,
*
offset
,
SEEK_SET
);
if
(
r
==
-
1
)
return
-
1
;
}
off_t
len
=
count
;
while
(
len
>
0
)
{
char
buf
[
1024
*
16
];
off_t
n
=
sizeof
(
buf
);
if
(
len
<
n
)
n
=
len
;
size_t
m
=
read
(
sfd
,
buf
,
n
);
if
(
m
==
-
1
)
return
-
1
;
if
(
m
==
0
)
break
;
size_t
l
=
write
(
dfd
,
buf
,
m
);
if
(
l
==
-
1
)
return
-
1
;
len
-=
l
;
}
return
count
-
len
;
}
#else
int64_t
taosSendFile
(
SocketFd
dfd
,
FileFd
sfd
,
int64_t
*
offset
,
int64_t
size
)
{
int64_t
leftbytes
=
size
;
int64_t
sentbytes
;
...
...
@@ -188,10 +306,96 @@ int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size
#endif
#ifndef TAOS_OS_FUNC_FILE_FTRUNCATE
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
int32_t
taosFtruncate
(
int32_t
fd
,
int64_t
l_size
)
{
if
(
fd
<
0
)
{
errno
=
EBADF
;
uError
(
"%s
\n
"
,
"fd arg was negative"
);
return
-
1
;
}
HANDLE
h
=
(
HANDLE
)
_get_osfhandle
(
fd
);
LARGE_INTEGER
li_0
;
li_0
.
QuadPart
=
(
int64_t
)
0
;
BOOL
cur
=
SetFilePointerEx
(
h
,
li_0
,
NULL
,
FILE_CURRENT
);
if
(
!
cur
)
{
uError
(
"SetFilePointerEx Error getting current position in file.
\n
"
);
return
-
1
;
}
int32_t
taosFtruncate
(
int32_t
fd
,
int64_t
length
)
{
return
ftruncate
(
fd
,
length
);
LARGE_INTEGER
li_size
;
li_size
.
QuadPart
=
l_size
;
BOOL
cur2
=
SetFilePointerEx
(
h
,
li_size
,
NULL
,
FILE_BEGIN
);
if
(
cur2
==
0
)
{
int
error
=
GetLastError
();
uError
(
"SetFilePointerEx GetLastError is: %d
\n
"
,
error
);
switch
(
error
)
{
case
ERROR_INVALID_HANDLE
:
errno
=
EBADF
;
break
;
default:
errno
=
EIO
;
break
;
}
return
-
1
;
}
if
(
!
SetEndOfFile
(
h
))
{
int
error
=
GetLastError
();
uError
(
"SetEndOfFile GetLastError is:%d"
,
error
);
switch
(
error
)
{
case
ERROR_INVALID_HANDLE
:
errno
=
EBADF
;
break
;
default:
errno
=
EIO
;
break
;
}
return
-
1
;
}
return
0
;
}
int32_t
taosFsync
(
FileFd
fd
)
{
if
(
fd
<
0
)
{
errno
=
EBADF
;
uError
(
"%s
\n
"
,
"fd arg was negative"
);
return
-
1
;
}
HANDLE
h
=
(
HANDLE
)
_get_osfhandle
(
fd
);
return
FlushFileBuffers
(
h
);
}
int32_t
taosRename
(
char
*
oldName
,
char
*
newName
)
{
int32_t
code
=
MoveFileEx
(
oldName
,
newName
,
MOVEFILE_REPLACE_EXISTING
|
MOVEFILE_COPY_ALLOWED
);
if
(
code
<
0
)
{
uError
(
"failed to rename file %s to %s, reason:%s"
,
oldName
,
newName
,
strerror
(
errno
));
}
else
{
uTrace
(
"successfully to rename file %s to %s"
,
oldName
,
newName
);
}
return
code
;
}
#else
int32_t
taosFtruncate
(
FileFd
fd
,
int64_t
length
)
{
return
ftruncate
(
fd
,
length
);
}
int32_t
taosFsync
(
FileFd
fd
)
{
return
fsync
(
fd
);
}
int32_t
taosRename
(
char
*
oldName
,
char
*
newName
)
{
int32_t
code
=
rename
(
oldName
,
newName
);
if
(
code
<
0
)
{
uError
(
"failed to rename file %s to %s, reason:%s"
,
oldName
,
newName
,
strerror
(
errno
));
}
else
{
uTrace
(
"successfully to rename file %s to %s"
,
oldName
,
newName
);
}
return
code
;
}
#endif
\ No newline at end of file
#endif
src/os/src/detail/osRand.c
浏览文件 @
73267640
...
...
@@ -16,8 +16,6 @@
#define _DEFAULT_SOURCE
#include "os.h"
#ifndef TAOS_OS_FUNC_RAND
uint32_t
taosRand
(
void
)
{
return
rand
();
}
uint32_t
taosSafeRand
(
void
)
{
...
...
@@ -38,8 +36,6 @@ uint32_t taosSafeRand(void) {
return
(
uint32_t
)
seed
;
}
#endif
void
taosRandStr
(
char
*
str
,
int32_t
size
)
{
const
char
*
set
=
"abcdefghijklmnopqrstuvwxyz0123456789-_."
;
int32_t
len
=
39
;
...
...
src/os/src/detail/osSemphone.c
浏览文件 @
73267640
...
...
@@ -16,9 +16,9 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if
ndef TAOS_OS_FUNC_SEMPHONE
#if
!defined (_TD_DARWIN_64)
int
tsem_wait
(
tsem_t
*
sem
)
{
int
32_t
tsem_wait
(
tsem_t
*
sem
)
{
int
ret
=
0
;
do
{
ret
=
sem_wait
(
sem
);
...
...
@@ -28,9 +28,9 @@ int tsem_wait(tsem_t* sem) {
#endif
#if
ndef TAOS_OS_FUNC_SEMPHONE_PTHREAD
#if
!(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64))
bool
taosCheckPthreadValid
(
pthread_t
thread
)
{
return
thread
!=
0
;
}
bool
taosCheckPthreadValid
(
pthread_t
thread
)
{
return
thread
!=
0
;
}
int64_t
taosGetSelfPthreadId
()
{
static
__thread
int
id
=
0
;
...
...
src/os/src/detail/osSignal.c
浏览文件 @
73267640
...
...
@@ -15,11 +15,13 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosdef.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tulog.h"
#ifndef TAOS_OS_FUNC_SIGNAL
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
typedef
void
(
*
FLinuxSignalHandler
)(
int32_t
signum
,
siginfo_t
*
sigInfo
,
void
*
context
);
void
taosSetSignal
(
int32_t
signum
,
FSignalHandler
sigfp
)
{
...
...
src/os/src/
windows/wGodll
.c
→
src/os/src/
detail/osSleep
.c
浏览文件 @
73267640
...
...
@@ -15,19 +15,43 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosdef.h"
#include "tglobal.h"
#include "ttimer.h"
#include "tulog.h"
#include "tutil.h"
#ifdef _TD_GO_DLL_
int64_t
tsosStr2int64
(
char
*
str
)
{
char
*
endptr
=
NULL
;
return
strtoll
(
str
,
&
endptr
,
10
);
}
uint64_t
htonll
(
uint64_t
val
)
{
return
(((
uint64_t
)
htonl
(
val
))
<<
32
)
+
htonl
(
val
>>
32
);
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void
taosMsleep
(
int32_t
ms
)
{
Sleep
(
ms
);
}
#else
/*
to make taosMsleep work,
signal SIGALRM shall be blocked in the calling thread,
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
*/
void
taosMsleep
(
int32_t
mseconds
)
{
#if 1
usleep
(
mseconds
*
1000
);
#else
struct
timeval
timeout
;
int32_t
seconds
,
useconds
;
seconds
=
mseconds
/
1000
;
useconds
=
(
mseconds
%
1000
)
*
1000
;
timeout
.
tv_sec
=
seconds
;
timeout
.
tv_usec
=
useconds
;
/* sigset_t set; */
/* sigemptyset(&set); */
/* sigaddset(&set, SIGALRM); */
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
select
(
0
,
NULL
,
NULL
,
NULL
,
&
timeout
);
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
#endif
}
#endif
src/os/src/detail/osSocket.c
浏览文件 @
73267640
...
...
@@ -17,7 +17,7 @@
#include "os.h"
#include "tulog.h"
#if
ndef TAOS_OS_FUNC_SOCKET
#if
!(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
int32_t
taosSetNonblocking
(
SOCKET
sock
,
int32_t
on
)
{
int32_t
flags
=
0
;
...
...
@@ -65,7 +65,7 @@ void taosSetMaskSIGPIPE() {
#endif
#if
ndef TAOS_OS_FUNC_SOCKET_SETSOCKETOPT
#if
!(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_32))
int32_t
taosSetSockOpt
(
SOCKET
socketfd
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
optlen
)
{
return
setsockopt
(
socketfd
,
level
,
optname
,
optval
,
(
socklen_t
)
optlen
);
...
...
@@ -74,9 +74,10 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
int32_t
taosGetSockOpt
(
SOCKET
socketfd
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
*
optlen
)
{
return
getsockopt
(
socketfd
,
level
,
optname
,
optval
,
(
socklen_t
*
)
optlen
);
}
#endif
#if
ndef TAOS_OS_FUNC_SOCKET_INET
#if
!( (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) && defined(_MSC_VER) )
uint32_t
taosInetAddr
(
char
*
ipAddr
)
{
return
inet_addr
(
ipAddr
);
...
...
src/os/src/detail/osString.c
浏览文件 @
73267640
...
...
@@ -17,17 +17,17 @@
#include "os.h"
#include "tglobal.h"
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
int64_t
tsosStr2int64
(
char
*
str
)
{
int64_t
taosStr2int64
(
char
*
str
)
{
char
*
endptr
=
NULL
;
return
strtoll
(
str
,
&
endptr
,
10
);
}
#endif
#ifndef TAOS_OS_FUNC_STRING_WCHAR
int
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int
bytes
)
{
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
int32_t
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int32_t
bytes
)
{
return
wcsncmp
((
wchar_t
*
)
f1_ucs4
,
(
wchar_t
*
)
f2_ucs4
,
bytes
/
TSDB_NCHAR_SIZE
);
}
#endif
#ifdef USE_LIBICONV
...
...
src/os/src/detail/osSysinfo.c
浏览文件 @
73267640
...
...
@@ -20,7 +20,7 @@
#include "tulog.h"
#include "taoserror.h"
#if
ndef TAOS_OS_FUNC_SYSINFO
#if
!(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64))
#define PROCESS_ITEM 12
...
...
src/os/src/detail/osTimer.c
浏览文件 @
73267640
...
...
@@ -18,7 +18,7 @@
#include "ttimer.h"
#include "tulog.h"
#if
ndef TAOS_OS_FUNC_TIMER
#if
!(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_64))
static
void
taosDeleteTimer
(
void
*
tharg
)
{
timer_t
*
pTimer
=
tharg
;
...
...
@@ -104,42 +104,3 @@ void taosUninitTimer() {
}
#endif
#ifndef TAOS_OS_FUNC_TIMER_SLEEP
/*
to make taosMsleep work,
signal SIGALRM shall be blocked in the calling thread,
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
*/
void
taosMsleep
(
int
mseconds
)
{
#ifdef __APPLE__
taos_block_sigalrm
();
#endif // __APPLE__
#if 1
usleep
(
mseconds
*
1000
);
#else
struct
timeval
timeout
;
int
seconds
,
useconds
;
seconds
=
mseconds
/
1000
;
useconds
=
(
mseconds
%
1000
)
*
1000
;
timeout
.
tv_sec
=
seconds
;
timeout
.
tv_usec
=
useconds
;
/* sigset_t set; */
/* sigemptyset(&set); */
/* sigaddset(&set, SIGALRM); */
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
select
(
0
,
NULL
,
NULL
,
NULL
,
&
timeout
);
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
#endif
}
#endif
src/os/src/windows/wFile.c
已删除
100644 → 0
浏览文件 @
255bf912
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "osSocket.h"
#include "tglobal.h"
#include "tulog.h"
void
taosGetTmpfilePath
(
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
char
tmpPath
[
PATH_MAX
];
int32_t
len
=
(
int32_t
)
strlen
(
tsTempDir
);
memcpy
(
tmpPath
,
tsTempDir
,
len
);
if
(
tmpPath
[
len
-
1
]
!=
'/'
&&
tmpPath
[
len
-
1
]
!=
'\\'
)
{
tmpPath
[
len
++
]
=
'\\'
;
}
strcpy
(
tmpPath
+
len
,
tdengineTmpFileNamePrefix
);
strcat
(
tmpPath
,
tdengineTmpFileNamePrefix
);
if
(
strlen
(
tmpPath
)
+
strlen
(
fileNamePrefix
)
+
strlen
(
"-%d-%s"
)
<
PATH_MAX
)
{
strcat
(
tmpPath
,
fileNamePrefix
);
strcat
(
tmpPath
,
"-%d-%s"
);
}
char
rand
[
8
]
=
{
0
};
taosRandStr
(
rand
,
tListLen
(
rand
)
-
1
);
snprintf
(
dstPath
,
PATH_MAX
,
tmpPath
,
getpid
(),
rand
);
}
#define _SEND_FILE_STEP_ 1000
int64_t
taosFSendFile
(
FILE
*
out_file
,
FILE
*
in_file
,
int64_t
*
offset
,
int64_t
count
)
{
fseek
(
in_file
,
(
int32_t
)(
*
offset
),
0
);
int64_t
writeLen
=
0
;
uint8_t
buffer
[
_SEND_FILE_STEP_
]
=
{
0
};
for
(
int64_t
len
=
0
;
len
<
(
count
-
_SEND_FILE_STEP_
);
len
+=
_SEND_FILE_STEP_
)
{
size_t
rlen
=
fread
(
buffer
,
1
,
_SEND_FILE_STEP_
,
in_file
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
if
(
rlen
<
_SEND_FILE_STEP_
)
{
fwrite
(
buffer
,
1
,
rlen
,
out_file
);
return
(
int64_t
)(
writeLen
+
rlen
);
}
else
{
fwrite
(
buffer
,
1
,
_SEND_FILE_STEP_
,
in_file
);
writeLen
+=
_SEND_FILE_STEP_
;
}
}
int64_t
remain
=
count
-
writeLen
;
if
(
remain
>
0
)
{
size_t
rlen
=
fread
(
buffer
,
1
,
(
size_t
)
remain
,
in_file
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
{
fwrite
(
buffer
,
1
,
(
size_t
)
remain
,
out_file
);
writeLen
+=
remain
;
}
}
return
writeLen
;
}
int64_t
taosSendFile
(
SOCKET
dfd
,
int32_t
sfd
,
int64_t
*
offset
,
int64_t
count
)
{
if
(
offset
!=
NULL
)
lseek
(
sfd
,
(
int32_t
)(
*
offset
),
0
);
int64_t
writeLen
=
0
;
uint8_t
buffer
[
_SEND_FILE_STEP_
]
=
{
0
};
for
(
int64_t
len
=
0
;
len
<
(
count
-
_SEND_FILE_STEP_
);
len
+=
_SEND_FILE_STEP_
)
{
int32_t
rlen
=
(
int32_t
)
read
(
sfd
,
buffer
,
_SEND_FILE_STEP_
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
if
(
rlen
<
_SEND_FILE_STEP_
)
{
taosWriteSocket
(
dfd
,
buffer
,
rlen
);
return
(
int64_t
)(
writeLen
+
rlen
);
}
else
{
taosWriteSocket
(
dfd
,
buffer
,
_SEND_FILE_STEP_
);
writeLen
+=
_SEND_FILE_STEP_
;
}
}
int64_t
remain
=
count
-
writeLen
;
if
(
remain
>
0
)
{
int32_t
rlen
=
read
(
sfd
,
buffer
,
(
int32_t
)
remain
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
{
taosWriteSocket
(
sfd
,
buffer
,
(
int32_t
)
remain
);
writeLen
+=
remain
;
}
}
return
writeLen
;
}
int32_t
taosFtruncate
(
int32_t
fd
,
int64_t
l_size
)
{
if
(
fd
<
0
)
{
errno
=
EBADF
;
uError
(
"%s
\n
"
,
"fd arg was negative"
);
return
-
1
;
}
HANDLE
h
=
(
HANDLE
)
_get_osfhandle
(
fd
);
LARGE_INTEGER
li_0
;
li_0
.
QuadPart
=
(
int64_t
)
0
;
BOOL
cur
=
SetFilePointerEx
(
h
,
li_0
,
NULL
,
FILE_CURRENT
);
if
(
!
cur
)
{
uError
(
"SetFilePointerEx Error getting current position in file.
\n
"
);
return
-
1
;
}
LARGE_INTEGER
li_size
;
li_size
.
QuadPart
=
l_size
;
BOOL
cur2
=
SetFilePointerEx
(
h
,
li_size
,
NULL
,
FILE_BEGIN
);
if
(
cur2
==
0
)
{
int
error
=
GetLastError
();
uError
(
"SetFilePointerEx GetLastError is: %d
\n
"
,
error
);
switch
(
error
)
{
case
ERROR_INVALID_HANDLE
:
errno
=
EBADF
;
break
;
default:
errno
=
EIO
;
break
;
}
return
-
1
;
}
if
(
!
SetEndOfFile
(
h
))
{
int
error
=
GetLastError
();
uError
(
"SetEndOfFile GetLastError is:%d"
,
error
);
switch
(
error
)
{
case
ERROR_INVALID_HANDLE
:
errno
=
EBADF
;
break
;
default:
errno
=
EIO
;
break
;
}
return
-
1
;
}
return
0
;
}
int
fsync
(
int
filedes
)
{
if
(
filedes
<
0
)
{
errno
=
EBADF
;
uError
(
"%s
\n
"
,
"fd arg was negative"
);
return
-
1
;
}
HANDLE
h
=
(
HANDLE
)
_get_osfhandle
(
filedes
);
return
FlushFileBuffers
(
h
);
}
int32_t
taosRename
(
char
*
oldName
,
char
*
newName
)
{
int32_t
code
=
MoveFileEx
(
oldName
,
newName
,
MOVEFILE_REPLACE_EXISTING
|
MOVEFILE_COPY_ALLOWED
);
if
(
code
<
0
)
{
uError
(
"failed to rename file %s to %s, reason:%s"
,
oldName
,
newName
,
strerror
(
errno
));
}
else
{
uTrace
(
"successfully to rename file %s to %s"
,
oldName
,
newName
);
}
return
code
;
}
\ No newline at end of file
src/os/src/windows/wGetline.c
浏览文件 @
73267640
...
...
@@ -22,6 +22,7 @@ General Public License for more details. */
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#if STDC_HEADERS
#include <stdlib.h>
...
...
@@ -40,10 +41,10 @@ null terminator), or -1 on error or EOF. On a -1 return, the caller
should check feof(), if not then errno has been set to indicate
the error. */
int
getstr
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
,
char
terminator
,
in
t
offset
)
{
int
nchars_avail
;
/* Allocated but unused chars in *LINEPTR. */
char
*
read_pos
;
/* Where we're reading into *LINEPTR. */
int
ret
;
int
32_t
getstr
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
,
char
terminator
,
int32_
t
offset
)
{
int
32_t
nchars_avail
;
/* Allocated but unused chars in *LINEPTR. */
char
*
read_pos
;
/* Where we're reading into *LINEPTR. */
int
32_t
ret
;
if
(
!
lineptr
||
!
n
||
!
stream
)
{
errno
=
EINVAL
;
...
...
@@ -59,12 +60,12 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset)
}
}
nchars_avail
=
(
int
)(
*
n
-
offset
);
nchars_avail
=
(
int
32_t
)(
*
n
-
offset
);
read_pos
=
*
lineptr
+
offset
;
for
(;;)
{
int
save_errno
;
register
int
c
=
getc
(
stream
);
int
32_t
save_errno
;
register
int
32_t
c
=
getc
(
stream
);
save_errno
=
errno
;
...
...
@@ -79,7 +80,7 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset)
else
*
n
+=
MIN_CHUNK
;
nchars_avail
=
(
int
)(
*
n
+
*
lineptr
-
read_pos
);
nchars_avail
=
(
int
32_t
)(
*
n
+
*
lineptr
-
read_pos
);
*
lineptr
=
realloc
(
*
lineptr
,
*
n
);
if
(
!*
lineptr
)
{
errno
=
ENOMEM
;
...
...
@@ -115,10 +116,8 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset)
/* Done - NUL terminate and return the number of chars read. */
*
read_pos
=
'\0'
;
ret
=
(
int
)(
read_pos
-
(
*
lineptr
+
offset
));
ret
=
(
int
32_t
)(
read_pos
-
(
*
lineptr
+
offset
));
return
ret
;
}
int
taosGetlineImp
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
)
{
return
getstr
(
lineptr
,
n
,
stream
,
'\n'
,
0
);
}
\ No newline at end of file
int32_t
tgetline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
)
{
return
getstr
(
lineptr
,
n
,
stream
,
'\n'
,
0
);
}
\ No newline at end of file
src/os/src/windows/wSocket.c
浏览文件 @
73267640
...
...
@@ -70,7 +70,8 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
return
setsockopt
(
socketfd
,
level
,
optname
,
optval
,
optlen
);
}
#ifdef TAOS_OS_FUNC_SOCKET_INET
#ifdef _MSC_VER
//#if _MSC_VER >= 1900
uint32_t
taosInetAddr
(
char
*
ipAddr
)
{
uint32_t
value
;
...
...
@@ -88,4 +89,11 @@ const char *taosInetNtoa(struct in_addr ipInt) {
return
inet_ntop
(
AF_INET
,
&
ipInt
,
tmpDstStr
,
INET6_ADDRSTRLEN
);
}
#endif
\ No newline at end of file
//#endif
#endif
#if defined(_TD_GO_DLL_)
uint64_t
htonll
(
uint64_t
val
)
{
return
(((
uint64_t
)
htonl
(
val
))
<<
32
)
+
htonl
(
val
>>
32
);
}
#endif
src/os/src/windows/wString.c
浏览文件 @
73267640
...
...
@@ -33,9 +33,9 @@
* If *stringp is NULL, strsep returns NULL.
*/
char
*
strsep
(
char
**
stringp
,
const
char
*
delim
)
{
char
*
s
;
char
*
s
;
const
char
*
spanp
;
int
c
,
sc
;
int
32_t
c
,
sc
;
char
*
tok
;
if
((
s
=
*
stringp
)
==
NULL
)
return
(
NULL
);
...
...
@@ -75,13 +75,13 @@ char *getpass(const char *prefix) {
return
passwd
;
}
int
twcslen
(
const
wchar_t
*
wcs
)
{
int
*
wstr
=
(
in
t
*
)
wcs
;
int
32_t
twcslen
(
const
wchar_t
*
wcs
)
{
int
32_t
*
wstr
=
(
int32_
t
*
)
wcs
;
if
(
NULL
==
wstr
)
{
return
0
;
}
int
n
=
0
;
int
32_t
n
=
0
;
while
(
1
)
{
if
(
0
==
*
wstr
++
)
{
break
;
...
...
@@ -92,8 +92,8 @@ int twcslen(const wchar_t *wcs) {
return
n
;
}
int
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
in
t
bytes
)
{
for
(
int
i
=
0
;
i
<
bytes
;
++
i
)
{
int
32_t
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int32_
t
bytes
)
{
for
(
int
32_t
i
=
0
;
i
<
bytes
;
++
i
)
{
int32_t
f1
=
*
(
int32_t
*
)((
char
*
)
f1_ucs4
+
i
*
4
);
int32_t
f2
=
*
(
int32_t
*
)((
char
*
)
f2_ucs4
+
i
*
4
);
...
...
@@ -127,7 +127,6 @@ int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) {
#endif
}
/* Copy memory to memory until the specified number of bytes
has been copied, return pointer to following byte.
Overlap is NOT handled correctly. */
...
...
src/os/src/windows/wTimer.c
浏览文件 @
73267640
...
...
@@ -43,7 +43,3 @@ int taosInitTimer(win_timer_f callback, int ms) {
void
taosUninitTimer
()
{
timeKillEvent
(
timerId
);
}
void
taosMsleep
(
int
mseconds
)
{
Sleep
(
mseconds
);
}
src/query/src/qTsbuf.c
浏览文件 @
73267640
...
...
@@ -484,7 +484,7 @@ void tsBufFlush(STSBuf* pTSBuf) {
.
magic
=
TS_COMP_FILE_MAGIC
,
.
numOfGroup
=
pTSBuf
->
numOfGroups
,
.
tsOrder
=
pTSBuf
->
tsOrder
};
STSBufUpdateHeader
(
pTSBuf
,
&
header
);
f
sync
(
fileno
(
pTSBuf
->
f
));
taosF
sync
(
fileno
(
pTSBuf
->
f
));
}
static
int32_t
tsBufFindGroupById
(
STSGroupBlockInfoEx
*
pGroupInfoEx
,
int32_t
numOfGroups
,
int32_t
id
)
{
...
...
@@ -868,7 +868,7 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
.
magic
=
TS_COMP_FILE_MAGIC
,
.
numOfGroup
=
pTSBuf
->
numOfGroups
,
.
tsOrder
=
pTSBuf
->
tsOrder
};
STSBufUpdateHeader
(
pTSBuf
,
&
header
);
f
sync
(
fileno
(
pTSBuf
->
f
));
taosF
sync
(
fileno
(
pTSBuf
->
f
));
return
pTSBuf
;
}
...
...
src/rpc/src/rpcTcp.c
浏览文件 @
73267640
...
...
@@ -529,9 +529,6 @@ static void *taosProcessTcpData(void *param) {
struct
epoll_event
events
[
maxEvents
];
SRecvInfo
recvInfo
;
#ifdef __APPLE__
taos_block_sigalrm
();
#endif // __APPLE__
while
(
1
)
{
int
fdNum
=
epoll_wait
(
pThreadObj
->
pollFd
,
events
,
maxEvents
,
TAOS_EPOLL_WAIT_TIME
);
if
(
pThreadObj
->
stop
)
{
...
...
src/rpc/test/rserver.c
浏览文件 @
73267640
...
...
@@ -52,7 +52,7 @@ void processShellMsg() {
if
(
commit
>=
2
)
{
num
+=
numOfMsgs
;
if
(
f
sync
(
dataFd
)
<
0
)
{
if
(
taosF
sync
(
dataFd
)
<
0
)
{
tInfo
(
"failed to flush data to file, reason:%s"
,
strerror
(
errno
));
}
...
...
src/tsdb/inc/tsdbFile.h
浏览文件 @
73267640
...
...
@@ -32,7 +32,7 @@
#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_FD(f) = -1)
#define TSDB_FILE_LEVEL(tf) TFILE_LEVEL(TSDB_FILE_F(tf))
#define TSDB_FILE_ID(tf) TFILE_ID(TSDB_FILE_F(tf))
#define TSDB_FILE_FSYNC(tf)
f
sync(TSDB_FILE_FD(tf))
#define TSDB_FILE_FSYNC(tf)
taosF
sync(TSDB_FILE_FD(tf))
#define TSDB_FILE_STATE(tf) ((tf)->state)
#define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s))
#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK)
...
...
src/tsdb/src/tsdbFS.c
浏览文件 @
73267640
...
...
@@ -390,7 +390,7 @@ static int tsdbSaveFSStatus(SFSStatus *pStatus, int vid) {
}
// fsync, close and rename
if
(
f
sync
(
fd
)
<
0
)
{
if
(
taosF
sync
(
fd
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
close
(
fd
);
remove
(
tfname
);
...
...
src/util/src/tcache.c
浏览文件 @
73267640
...
...
@@ -661,11 +661,7 @@ void* taosCacheTimedRefresh(void *handle) {
int64_t
count
=
0
;
while
(
1
)
{
#if defined LINUX
usleep
(
500
*
1000
);
#else
taosMsleep
(
500
);
#endif
// check if current cache object will be deleted every 500ms.
if
(
pCacheObj
->
deleting
)
{
...
...
src/util/src/tfile.c
浏览文件 @
73267640
...
...
@@ -98,7 +98,7 @@ int32_t tfFsync(int64_t tfd) {
if
(
p
==
NULL
)
return
-
1
;
int32_t
fd
=
(
int32_t
)(
uintptr_t
)
p
;
int32_t
code
=
f
sync
(
fd
);
int32_t
code
=
taosF
sync
(
fd
);
taosReleaseRef
(
tsFileRsetId
,
tfd
);
return
code
;
...
...
src/vnode/src/vnodeCfg.c
浏览文件 @
73267640
...
...
@@ -362,7 +362,7 @@ int32_t vnodeWriteCfg(SCreateVnodeMsg *pMsg) {
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
fwrite
(
content
,
1
,
len
,
fp
);
f
sync
(
fileno
(
fp
));
taosF
sync
(
fileno
(
fp
));
fclose
(
fp
);
free
(
content
);
terrno
=
0
;
...
...
src/vnode/src/vnodeVersion.c
浏览文件 @
73267640
...
...
@@ -90,7 +90,7 @@ int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
fwrite
(
content
,
1
,
len
,
fp
);
f
sync
(
fileno
(
fp
));
taosF
sync
(
fileno
(
fp
));
fclose
(
fp
);
free
(
content
);
terrno
=
0
;
...
...
tests/examples/c/epoll.c
浏览文件 @
73267640
...
...
@@ -20,7 +20,7 @@
// monitor and compare : glances
#ifdef __APPLE__
#include "
e
ok.h"
#include "
osE
ok.h"
#else // __APPLE__
#include <sys/epoll.h>
#endif // __APPLE__
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录