Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fc245216
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fc245216
编写于
4月 22, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(os): windows compile 3.0.
上级
db2b9931
变更
117
隐藏空白更改
内联
并排
Showing
117 changed file
with
1531 addition
and
773 deletion
+1531
-773
cmake/cmake.define
cmake/cmake.define
+9
-4
cmake/cmake.options
cmake/cmake.options
+21
-4
cmake/msvcregex_CMakeLists.txt.in
cmake/msvcregex_CMakeLists.txt.in
+13
-0
cmake/pthread_CMakeLists.txt.in
cmake/pthread_CMakeLists.txt.in
+1
-1
cmake/wcwidth_CMakeLists.txt.in
cmake/wcwidth_CMakeLists.txt.in
+13
-0
cmake/wingetopt_CMakeLists.txt.in
cmake/wingetopt_CMakeLists.txt.in
+13
-0
contrib/CMakeLists.txt
contrib/CMakeLists.txt
+90
-5
contrib/test/craft/CMakeLists.txt
contrib/test/craft/CMakeLists.txt
+8
-1
contrib/test/tdev/src/main.c
contrib/test/tdev/src/main.c
+34
-38
example/CMakeLists.txt
example/CMakeLists.txt
+1
-0
example/src/demoapi.c
example/src/demoapi.c
+22
-18
include/common/trow.h
include/common/trow.h
+1
-1
include/dnode/bnode/bnode.h
include/dnode/bnode/bnode.h
+3
-0
include/libs/qcom/query.h
include/libs/qcom/query.h
+4
-0
include/os/os.h
include/os/os.h
+9
-1
include/os/osAtomic.h
include/os/osAtomic.h
+4
-4
include/os/osDef.h
include/os/osDef.h
+1
-1
include/os/osDir.h
include/os/osDir.h
+3
-3
include/os/osFile.h
include/os/osFile.h
+0
-1
include/os/osLz4.h
include/os/osLz4.h
+1
-1
include/os/osMath.h
include/os/osMath.h
+2
-1
include/os/osSocket.h
include/os/osSocket.h
+64
-48
include/os/osString.h
include/os/osString.h
+1
-1
include/os/osThread.h
include/os/osThread.h
+11
-2
include/os/osTime.h
include/os/osTime.h
+4
-4
include/util/tencode.h
include/util/tencode.h
+4
-2
include/util/tjson.h
include/util/tjson.h
+4
-0
source/common/CMakeLists.txt
source/common/CMakeLists.txt
+2
-2
source/common/test/commonTests.cpp
source/common/test/commonTests.cpp
+1
-1
source/dnode/mgmt/exe/dmMain.c
source/dnode/mgmt/exe/dmMain.c
+3
-1
source/dnode/vnode/src/meta/metaIdx.c
source/dnode/vnode/src/meta/metaIdx.c
+3
-0
source/dnode/vnode/src/meta/metaTDBImpl.c
source/dnode/vnode/src/meta/metaTDBImpl.c
+3
-1
source/dnode/vnode/src/tq/tqMetaStore.c
source/dnode/vnode/src/tq/tqMetaStore.c
+5
-1
source/libs/catalog/inc/catalogInt.h
source/libs/catalog/inc/catalogInt.h
+4
-0
source/libs/catalog/test/catalogTests.cpp
source/libs/catalog/test/catalogTests.cpp
+95
-22
source/libs/executor/src/groupoperator.c
source/libs/executor/src/groupoperator.c
+4
-4
source/libs/executor/src/tsimplehash.c
source/libs/executor/src/tsimplehash.c
+3
-3
source/libs/executor/test/executorTests.cpp
source/libs/executor/test/executorTests.cpp
+3
-3
source/libs/function/CMakeLists.txt
source/libs/function/CMakeLists.txt
+3
-0
source/libs/function/inc/tudfInt.h
source/libs/function/inc/tudfInt.h
+3
-0
source/libs/function/inc/udfc.h
source/libs/function/inc/udfc.h
+3
-0
source/libs/index/inc/indexFstRegex.h
source/libs/index/inc/indexFstRegex.h
+3
-0
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+1
-1
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+3
-3
source/libs/index/test/jsonUT.cc
source/libs/index/test/jsonUT.cc
+1
-1
source/libs/parser/inc/parToken.h
source/libs/parser/inc/parToken.h
+0
-1
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+1
-0
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+1
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+8
-6
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+1
-0
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1
-0
source/libs/parser/test/CMakeLists.txt
source/libs/parser/test/CMakeLists.txt
+8
-0
source/libs/parser/test/mockCatalog.cpp
source/libs/parser/test/mockCatalog.cpp
+3
-1
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+5
-7
source/libs/parser/test/parserInsertTest.cpp
source/libs/parser/test/parserInsertTest.cpp
+1
-0
source/libs/parser/test/parserTestMain.cpp
source/libs/parser/test/parserTestMain.cpp
+7
-1
source/libs/planner/test/CMakeLists.txt
source/libs/planner/test/CMakeLists.txt
+9
-0
source/libs/planner/test/planTestMain.cpp
source/libs/planner/test/planTestMain.cpp
+1
-1
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+1
-0
source/libs/qworker/inc/qworkerInt.h
source/libs/qworker/inc/qworkerInt.h
+3
-0
source/libs/qworker/test/qworkerTests.cpp
source/libs/qworker/test/qworkerTests.cpp
+82
-2
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+5
-5
source/libs/scalar/test/filter/filterTests.cpp
source/libs/scalar/test/filter/filterTests.cpp
+22
-19
source/libs/scalar/test/scalar/scalarTests.cpp
source/libs/scalar/test/scalar/scalarTests.cpp
+3
-0
source/libs/scheduler/inc/schedulerInt.h
source/libs/scheduler/inc/schedulerInt.h
+12
-0
source/libs/scheduler/test/schedulerTests.cpp
source/libs/scheduler/test/schedulerTests.cpp
+35
-1
source/libs/sync/src/syncEnv.c
source/libs/sync/src/syncEnv.c
+1
-1
source/libs/tdb/CMakeLists.txt
source/libs/tdb/CMakeLists.txt
+1
-1
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+6
-3
source/libs/tdb/src/db/tdbPCache.c
source/libs/tdb/src/db/tdbPCache.c
+7
-8
source/libs/tdb/src/db/tdbPage.c
source/libs/tdb/src/db/tdbPage.c
+9
-4
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+3
-1
source/libs/tdb/src/inc/tdbPage.h
source/libs/tdb/src/inc/tdbPage.h
+17
-13
source/libs/tdb/src/inc/tdbUtil.h
source/libs/tdb/src/inc/tdbUtil.h
+14
-14
source/libs/tfs/src/tfs.c
source/libs/tfs/src/tfs.c
+3
-3
source/libs/transport/test/rclient.c
source/libs/transport/test/rclient.c
+0
-2
source/libs/transport/test/syncClient.c
source/libs/transport/test/syncClient.c
+0
-2
source/libs/transport/test/transportTests.cpp
source/libs/transport/test/transportTests.cpp
+6
-6
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+2
-2
source/os/CMakeLists.txt
source/os/CMakeLists.txt
+12
-2
source/os/src/osAtomic.c
source/os/src/osAtomic.c
+207
-121
source/os/src/osDir.c
source/os/src/osDir.c
+130
-40
source/os/src/osEnv.c
source/os/src/osEnv.c
+1
-3
source/os/src/osFile.c
source/os/src/osFile.c
+64
-143
source/os/src/osLocale.c
source/os/src/osLocale.c
+2
-2
source/os/src/osLz4.c
source/os/src/osLz4.c
+1
-1
source/os/src/osMemory.c
source/os/src/osMemory.c
+5
-1
source/os/src/osProc.c
source/os/src/osProc.c
+18
-2
source/os/src/osRand.c
source/os/src/osRand.c
+21
-2
source/os/src/osSemaphore.c
source/os/src/osSemaphore.c
+1
-1
source/os/src/osShm.c
source/os/src/osShm.c
+12
-0
source/os/src/osSignal.c
source/os/src/osSignal.c
+3
-1
source/os/src/osSleep.c
source/os/src/osSleep.c
+11
-4
source/os/src/osSocket.c
source/os/src/osSocket.c
+24
-27
source/os/src/osString.c
source/os/src/osString.c
+49
-0
source/os/src/osStrptime.c
source/os/src/osStrptime.c
+2
-2
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+41
-33
source/os/src/osSystem.c
source/os/src/osSystem.c
+23
-2
source/os/src/osThread.c
source/os/src/osThread.c
+9
-12
source/os/src/osTime.c
source/os/src/osTime.c
+36
-5
source/os/src/osTimer.c
source/os/src/osTimer.c
+3
-3
source/os/src/osTimezone.c
source/os/src/osTimezone.c
+4
-3
source/util/CMakeLists.txt
source/util/CMakeLists.txt
+1
-1
source/util/src/tcache.c
source/util/src/tcache.c
+2
-1
source/util/src/tconfig.c
source/util/src/tconfig.c
+1
-1
source/util/src/thash.c
source/util/src/thash.c
+1
-1
source/util/src/tlog.c
source/util/src/tlog.c
+1
-0
source/util/src/tprocess.c
source/util/src/tprocess.c
+3
-3
source/util/src/tskiplist.c
source/util/src/tskiplist.c
+1
-1
source/util/src/ttimer.c
source/util/src/ttimer.c
+1
-1
source/util/test/freelistTest.cpp
source/util/test/freelistTest.cpp
+1
-1
source/util/test/procTest.cpp
source/util/test/procTest.cpp
+52
-52
source/util/test/trefTest.c
source/util/test/trefTest.c
+3
-3
tests/test/c/tmqDemo.c
tests/test/c/tmqDemo.c
+4
-5
tests/test/c/tmqSim.c
tests/test/c/tmqSim.c
+3
-4
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+0
-1
tools/shell/src/shellMain.c
tools/shell/src/shellMain.c
+16
-0
未找到文件。
cmake/cmake.define
浏览文件 @
fc245216
cmake_minimum_required(VERSION 3.16)
set(CMAKE_VERBOSE_MAKEFILE ON)
#set output directory
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
...
...
@@ -43,11 +45,14 @@ ENDIF ()
IF (TD_WINDOWS)
MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}")
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
SET(COMMON_FLAGS "/
nologo /WX /wd4018 /wd4999 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-
")
SET(COMMON_FLAGS "/
W3 /D_WIN32
")
IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
ENDIF ()
# IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
# SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
# ENDIF ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
ELSE ()
IF (${SANITIZER} MATCHES "true")
...
...
cmake/cmake.options
浏览文件 @
fc245216
...
...
@@ -25,9 +25,28 @@ IF(${TD_WINDOWS})
ON
)
ENDIF ()
MESSAGE("build msvcregex Win32")
option(
BUILD_MSVCREGEX
"If build msvcregex on Windows"
ON
)
IF(${TD_LINUX} MATCHES TRUE)
MESSAGE("build wcwidth Win32")
option(
BUILD_WCWIDTH
"If build wcwidth on Windows"
ON
)
MESSAGE("build wingetopt Win32")
option(
BUILD_WINGETOPT
"If build wingetopt on Windows"
ON
)
ENDIF ()
option(
BUILD_TEST
...
...
@@ -35,8 +54,6 @@ option(
ON
)
ENDIF ()
option(
BUILD_WITH_LEVELDB
"If build with leveldb"
...
...
cmake/msvcregex_CMakeLists.txt.in
0 → 100644
浏览文件 @
fc245216
# msvcregex
ExternalProject_Add(msvcregex
GIT_REPOSITORY https://gitee.com/l0km/libgnurx-msvc.git
GIT_TAG master
SOURCE_DIR "${TD_CONTRIB_DIR}/msvcregex"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
cmake/pthread_CMakeLists.txt.in
浏览文件 @
fc245216
...
...
@@ -3,7 +3,7 @@
ExternalProject_Add(pthread
GIT_REPOSITORY https://github.com/GerHobbelt/pthread-win32
GIT_TAG v3.0.3.1
SOURCE_DIR "${TD_CONTRIB_DIR}/pthread
-win32
"
SOURCE_DIR "${TD_CONTRIB_DIR}/pthread"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
...
...
cmake/wcwidth_CMakeLists.txt.in
0 → 100644
浏览文件 @
fc245216
# wcwidth
ExternalProject_Add(wcwidth
GIT_REPOSITORY https://github.com/fumiyas/wcwidth-cjk.git
GIT_TAG master
SOURCE_DIR "${TD_CONTRIB_DIR}/wcwidth"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
cmake/wingetopt_CMakeLists.txt.in
0 → 100644
浏览文件 @
fc245216
# wingetopt
ExternalProject_Add(wingetopt
GIT_REPOSITORY https://github.com/alex85k/wingetopt.git
GIT_TAG master
SOURCE_DIR "${TD_CONTRIB_DIR}/wingetopt"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
contrib/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -14,9 +14,24 @@ if(${BUILD_PTHREAD})
cat
(
"
${
TD_SUPPORT_DIR
}
/pthread_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
endif
()
# gnu regex
if
(
${
BUILD_GNUREGEX
}
)
cat
(
"
${
TD_SUPPORT_DIR
}
/gnuregex_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
# iconv
if
(
${
BUILD_WITH_ICONV
}
)
cat
(
"
${
TD_SUPPORT_DIR
}
/iconv_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
endif
()
# msvc regex
if
(
${
BUILD_MSVCREGEX
}
)
cat
(
"
${
TD_SUPPORT_DIR
}
/msvcregex_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
endif
()
# wcwidth
if
(
${
BUILD_WCWIDTH
}
)
cat
(
"
${
TD_SUPPORT_DIR
}
/wcwidth_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
endif
()
# wingetopt
if
(
${
BUILD_WINGETOPT
}
)
cat
(
"
${
TD_SUPPORT_DIR
}
/wingetopt_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
endif
()
# googletest
...
...
@@ -99,8 +114,27 @@ if(${BUILD_TEST})
target_include_directories
(
gtest
PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/cpp-stub/src>
PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/cpp-stub/src_linux>
)
if
(
${
TD_WINDOWS
}
)
target_include_directories
(
gtest
PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/cpp-stub/src_win>
)
endif
(
${
TD_WINDOWS
}
)
if
(
${
TD_LINUX
}
)
target_include_directories
(
gtest
PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/cpp-stub/src_linux>
)
endif
(
${
TD_LINUX
}
)
if
(
${
TD_DARWIN
}
)
target_include_directories
(
gtest
PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/cpp-stub/src_darwin>
)
endif
(
${
TD_DARWIN
}
)
endif
(
${
BUILD_TEST
}
)
# cJson
...
...
@@ -182,6 +216,53 @@ if(${BUILD_WITH_NURAFT})
add_subdirectory
(
nuraft
)
endif
(
${
BUILD_WITH_NURAFT
}
)
# pthread
if
(
${
BUILD_PTHREAD
}
)
set
(
CMAKE_BUILD_TYPE release
)
add_definitions
(
-DPTW32_STATIC_LIB
)
add_subdirectory
(
pthread
)
set_target_properties
(
libpthreadVC3 PROPERTIES OUTPUT_NAME pthread
)
add_library
(
pthread STATIC IMPORTED GLOBAL
)
SET_PROPERTY
(
TARGET pthread PROPERTY IMPORTED_LOCATION
${
LIBRARY_OUTPUT_PATH
}
/pthread.lib
)
endif
()
# iconv
if
(
${
BUILD_WITH_ICONV
}
)
add_subdirectory
(
iconv
)
endif
(
${
BUILD_WITH_ICONV
}
)
# wingetopt
if
(
${
BUILD_WINGETOPT
}
)
add_subdirectory
(
wingetopt
)
endif
(
${
BUILD_WINGETOPT
}
)
# msvcregex
if
(
${
BUILD_MSVCREGEX
}
)
add_library
(
msvcregex STATIC
""
)
target_sources
(
msvcregex
PRIVATE
"msvcregex/regex.c"
)
target_include_directories
(
msvcregex
PRIVATE
"msvcregex"
)
target_link_libraries
(
msvcregex
INTERFACE Shell32
)
SET_TARGET_PROPERTIES
(
msvcregex PROPERTIES OUTPUT_NAME msvcregex
)
endif
(
${
BUILD_MSVCREGEX
}
)
# msvcregex
if
(
${
BUILD_WCWIDTH
}
)
add_library
(
wcwidth STATIC
""
)
target_sources
(
wcwidth
PRIVATE
"wcwidth/wcwidth.c"
)
target_include_directories
(
wcwidth
PRIVATE
"wcwidth"
)
SET_TARGET_PROPERTIES
(
wcwidth PROPERTIES OUTPUT_NAME wcwidth
)
endif
(
${
BUILD_WCWIDTH
}
)
# CRAFT
if
(
${
BUILD_WITH_CRAFT
}
)
add_library
(
craft STATIC IMPORTED GLOBAL
)
...
...
@@ -238,8 +319,12 @@ if(${BUILD_WITH_SQLITE})
target_link_libraries
(
sqlite
INTERFACE m
INTERFACE pthread
INTERFACE dl
)
if
(
NOT TD_WINDOWS
)
target_link_libraries
(
sqlite
INTERFACE dl
)
endif
(
NOT TD_WINDOWS
)
endif
(
${
BUILD_WITH_SQLITE
}
)
# pthread
...
...
contrib/test/craft/CMakeLists.txt
浏览文件 @
fc245216
add_executable
(
simulate_vnode
"simulate_vnode.c"
)
target_link_libraries
(
simulate_vnode PUBLIC craft lz4 uv_a
)
\ No newline at end of file
target_link_libraries
(
simulate_vnode PUBLIC craft lz4 uv_a
)
if
(
${
BUILD_WINGETOPT
}
)
target_link_libraries
(
simulate_vnode PUBLIC wingetopt
)
target_include_directories
(
simulate_vnode
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/wingetopt/src"
)
endif
()
\ No newline at end of file
contrib/test/tdev/src/main.c
浏览文件 @
fc245216
...
...
@@ -6,43 +6,39 @@
#define POINTER_SHIFT(ptr, s) ((void *)(((char *)ptr) + (s)))
#define POINTER_DISTANCE(pa, pb) ((char *)(pb) - (char *)(pa))
#define tPutA(buf, val) \
({ \
memcpy(buf, &val, sizeof(val)); \
POINTER_SHIFT(buf, sizeof(val)); \
})
static
inline
void
tPutA
(
void
**
buf
,
uint64_t
val
)
{
memcpy
(
buf
,
&
val
,
sizeof
(
val
));
*
buf
=
POINTER_SHIFT
(
buf
,
sizeof
(
val
));
}
#define tPutB(buf, val) \
({ \
((uint8_t *)buf)[7] = ((val) >> 56) & 0xff; \
((uint8_t *)buf)[6] = ((val) >> 48) & 0xff; \
((uint8_t *)buf)[5] = ((val) >> 40) & 0xff; \
((uint8_t *)buf)[4] = ((val) >> 32) & 0xff; \
((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \
((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \
((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \
((uint8_t *)buf)[0] = (val)&0xff; \
POINTER_SHIFT(buf, sizeof(val)); \
})
static
inline
void
tPutB
(
void
**
buf
,
uint64_t
val
)
{
((
uint8_t
*
)
buf
)[
7
]
=
((
val
)
>>
56
)
&
0xff
;
((
uint8_t
*
)
buf
)[
6
]
=
((
val
)
>>
48
)
&
0xff
;
((
uint8_t
*
)
buf
)[
5
]
=
((
val
)
>>
40
)
&
0xff
;
((
uint8_t
*
)
buf
)[
4
]
=
((
val
)
>>
32
)
&
0xff
;
((
uint8_t
*
)
buf
)[
3
]
=
((
val
)
>>
24
)
&
0xff
;
((
uint8_t
*
)
buf
)[
2
]
=
((
val
)
>>
16
)
&
0xff
;
((
uint8_t
*
)
buf
)[
1
]
=
((
val
)
>>
8
)
&
0xff
;
((
uint8_t
*
)
buf
)[
0
]
=
(
val
)
&
0xff
;
*
buf
=
POINTER_SHIFT
(
buf
,
sizeof
(
val
));
}
#define tPutC(buf, val) \
({ \
if (buf) { \
((uint64_t *)buf)[0] = (val); \
POINTER_SHIFT(buf, sizeof(val)); \
} \
NULL; \
})
static
inline
void
tPutC
(
void
**
buf
,
uint64_t
val
)
{
if
(
buf
)
{
((
uint64_t
*
)
buf
)[
0
]
=
(
val
);
POINTER_SHIFT
(
buf
,
sizeof
(
val
));
}
*
buf
=
NULL
;
}
#define tPutD(buf, val) \
({ \
uint64_t tmp = val; \
for (size_t i = 0; i < sizeof(val); i++) { \
((uint8_t *)buf)[i] = tmp & 0xff; \
tmp >>= 8; \
} \
POINTER_SHIFT(buf, sizeof(val)); \
})
static
inline
void
tPutD
(
void
**
buf
,
uint64_t
val
)
{
uint64_t
tmp
=
val
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
val
);
i
++
)
{
((
uint8_t
*
)
buf
)[
i
]
=
tmp
&
0xff
;
tmp
>>=
8
;
}
*
buf
=
POINTER_SHIFT
(
buf
,
sizeof
(
val
));
}
static
inline
void
tPutE
(
void
**
buf
,
uint64_t
val
)
{
if
(
buf
)
{
...
...
@@ -61,7 +57,7 @@ static void func(T t) {
switch
(
t
)
{
case
A
:
for
(
size_t
i
=
0
;
i
<
10
*
1024l
*
1024l
*
1024l
;
i
++
)
{
pBuf
=
tPutA
(
pBuf
,
val
);
tPutA
(
pBuf
,
val
);
if
(
POINTER_DISTANCE
(
buf
,
pBuf
)
==
1024
)
{
pBuf
=
buf
;
}
...
...
@@ -69,7 +65,7 @@ static void func(T t) {
break
;
case
B
:
for
(
size_t
i
=
0
;
i
<
10
*
1024l
*
1024l
*
1024l
;
i
++
)
{
pBuf
=
tPutB
(
pBuf
,
val
);
tPutB
(
pBuf
,
val
);
if
(
POINTER_DISTANCE
(
buf
,
pBuf
)
==
1024
)
{
pBuf
=
buf
;
}
...
...
@@ -77,7 +73,7 @@ static void func(T t) {
break
;
case
C
:
for
(
size_t
i
=
0
;
i
<
10
*
1024l
*
1024l
*
1024l
;
i
++
)
{
pBuf
=
tPutC
(
pBuf
,
val
);
tPutC
(
pBuf
,
val
);
if
(
POINTER_DISTANCE
(
buf
,
pBuf
)
==
1024
)
{
pBuf
=
buf
;
}
...
...
@@ -85,7 +81,7 @@ static void func(T t) {
break
;
case
D
:
for
(
size_t
i
=
0
;
i
<
10
*
1024l
*
1024l
*
1024l
;
i
++
)
{
pBuf
=
tPutD
(
pBuf
,
val
);
tPutD
(
pBuf
,
val
);
if
(
POINTER_DISTANCE
(
buf
,
pBuf
)
==
1024
)
{
pBuf
=
buf
;
}
...
...
example/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -39,6 +39,7 @@ target_include_directories(tstream
target_include_directories
(
demoapi
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/client"
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/os"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
...
...
example/src/demoapi.c
浏览文件 @
fc245216
...
...
@@ -4,10 +4,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//
#include <unistd.h>
#include <inttypes.h>
#ifndef WINDOWS
#include <argp.h>
#endif
#include "osSleep.h"
#include "taos.h"
#define debugPrint(fmt, ...) \
...
...
@@ -32,6 +34,7 @@
int64_t
g_num_of_tb
=
2
;
int64_t
g_num_of_rec
=
3
;
#ifndef WINDOWS
static
struct
argp_option
options
[]
=
{
{
"tables"
,
't'
,
"NUMBER"
,
0
,
"Number of child tables, default is 10000."
},
{
"records"
,
'n'
,
"NUMBER"
,
0
,
...
...
@@ -61,16 +64,16 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
}
static
struct
argp
argp
=
{
options
,
parse_opt
,
""
,
""
};
#endif
static
void
prepare_data
(
TAOS
*
taos
)
{
TAOS_RES
*
res
;
res
=
taos_query
(
taos
,
"drop database if exists test;"
);
taos_free_result
(
res
);
usleep
(
1000
00
);
taosMsleep
(
1
00
);
res
=
taos_query
(
taos
,
"create database test;"
);
taos_free_result
(
res
);
usleep
(
1000
00
);
taosMsleep
(
1
00
);
taos_select_db
(
taos
,
"test"
);
char
command
[
1024
]
=
{
0
};
...
...
@@ -87,18 +90,17 @@ static void prepare_data(TAOS* taos) {
taos_free_result
(
res
);
for
(
int64_t
i
=
0
;
i
<
g_num_of_tb
;
i
++
)
{
// sprintf(command, "create table t%"PRId64" using meters "
// "tags(%"PRId64", '%s', '%s', '%s');",
// i, i, (i%2)?"beijing":"shanghai",
// (i%2)?"朝阳区":"黄浦区",
// (i%2)?"长安街":"中山路");
sprintf
(
command
,
"create table t%"
PRId64
" using meters "
"tags(%"
PRId64
", '%s', '%s', '%s');"
,
i
,
i
,
(
i
%
2
)
?
"beijing"
:
"shanghai"
,
(
i
%
2
)
?
"朝阳区"
:
"黄浦区"
,
(
i
%
2
)
?
"长安街"
:
"中山路"
);
/* sprintf(command, "create table t%"PRId64" using meters "
"tags(%"
PRId64
", '%s', '%s', '%s');"
,
i
,
i
,
(
i
%
2
)
?
"beijing"
:
"shanghai"
,
(
i
%
2
)
?
"chaoyang"
:
"huangpu"
,
(
i
%
2
?
"changan street"
:
"jianguo rd"
));
*/
res
=
taos_query
(
taos
,
command
);
if
((
res
)
&&
(
0
==
taos_errno
(
res
)))
{
okPrint
(
"t%"
PRId64
" created
\n
"
,
i
);
...
...
@@ -117,7 +119,8 @@ static void prepare_data(TAOS* taos) {
"'%c%d', '%s%c%d', '%c%d')"
,
i
,
1650000000000
+
j
,
(
float
)
j
,
j
,
'a'
+
(
int
)
j
%
25
,
rand
(),
"涛思"
,
'z'
-
(
int
)
j
%
25
,
rand
(),
// "涛思", 'z' - (int)j%25, rand(),
"TAOS"
,
'z'
-
(
int
)
j
%
25
,
rand
(),
'b'
-
(
int
)
j
%
25
,
rand
()
);
res
=
taos_query
(
taos
,
command
);
...
...
@@ -196,7 +199,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
printf
(
"col%d, row: %"
PRId64
", "
"value: %"
PRId64
"
\n
"
,
f
,
c
,
*
(
int64_t
*
)(
row
[
f
]
+
c
*
sizeof
(
int64_t
)));
*
(
int64_t
*
)(
(
char
*
)(
row
[
f
])
+
c
*
sizeof
(
int64_t
)));
}
break
;
...
...
@@ -208,7 +211,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
printf
(
"col%d, row: %"
PRId64
", "
"value: %d
\n
"
,
f
,
c
,
*
(
int32_t
*
)(
row
[
f
]
+
c
*
sizeof
(
int32_t
)));
*
(
int32_t
*
)(
(
char
*
)(
row
[
f
])
+
c
*
sizeof
(
int32_t
)));
}
break
;
...
...
@@ -220,7 +223,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
printf
(
"col%d, row: %"
PRId64
", "
"value: %f
\n
"
,
f
,
c
,
*
(
float
*
)(
row
[
f
]
+
c
*
sizeof
(
float
)));
*
(
float
*
)(
(
char
*
)(
row
[
f
])
+
c
*
sizeof
(
float
)));
}
break
;
...
...
@@ -235,9 +238,9 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
if
(
offsets
)
{
for
(
int
c
=
0
;
c
<
rows
;
c
++
)
{
if
(
offsets
[
c
]
!=
-
1
)
{
int
length
=
*
(
int16_t
*
)(
row
[
f
]
+
offsets
[
c
]);
int
length
=
*
(
int16_t
*
)(
(
char
*
)(
row
[
f
])
+
offsets
[
c
]);
char
*
buf
=
calloc
(
1
,
length
+
1
);
strncpy
(
buf
,
(
char
*
)(
row
[
f
]
+
offsets
[
c
]
+
2
),
length
);
strncpy
(
buf
,
(
char
*
)(
(
char
*
)(
row
[
f
])
+
offsets
[
c
]
+
2
),
length
);
printf
(
"row: %d, col: %d, offset: %d, length: %d, content: %s
\n
"
,
c
,
f
,
offsets
[
c
],
length
,
buf
);
free
(
buf
);
...
...
@@ -314,8 +317,9 @@ int main(int argc, char *argv[]) {
const
char
*
host
=
"127.0.0.1"
;
const
char
*
user
=
"root"
;
const
char
*
passwd
=
"taosdata"
;
#ifndef WINDOWS
argp_parse
(
&
argp
,
argc
,
argv
,
0
,
0
,
NULL
);
#endif
TAOS
*
taos
=
taos_connect
(
host
,
user
,
passwd
,
""
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"
\033
[31mfailed to connect to db, reason:%s
\033
[0m
\n
"
,
taos_errstr
(
taos
));
...
...
include/common/trow.h
浏览文件 @
fc245216
...
...
@@ -1359,7 +1359,7 @@ static void tdSRowPrint(STSRow *row, STSchema *pSchema) {
printf
(
">>>"
);
for
(
int
i
=
0
;
i
<
pSchema
->
numOfCols
;
++
i
)
{
STColumn
*
stCol
=
pSchema
->
columns
+
i
;
SCellVal
sVal
=
{
.
valType
=
255
,
.
val
=
NULL
};
SCellVal
sVal
=
{
255
,
NULL
};
if
(
!
tdSTSRowIterNext
(
&
iter
,
stCol
->
colId
,
stCol
->
type
,
&
sVal
))
{
break
;
}
...
...
include/dnode/bnode/bnode.h
浏览文件 @
fc245216
...
...
@@ -26,6 +26,9 @@ extern "C" {
typedef
struct
SBnode
SBnode
;
typedef
struct
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SBnodeLoad
;
typedef
struct
{
...
...
include/libs/qcom/query.h
浏览文件 @
fc245216
...
...
@@ -51,6 +51,10 @@ typedef struct STableComInfo {
typedef
struct
SIndexMeta
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SIndexMeta
;
...
...
include/os/os.h
浏览文件 @
fc245216
...
...
@@ -22,7 +22,6 @@ extern "C" {
#include <assert.h>
#include <ctype.h>
#include <semaphore.h>
#include <regex.h>
...
...
@@ -51,6 +50,15 @@ extern "C" {
#include <sys/prctl.h>
#include <argp.h>
#endif
#else
#include <time.h>
#ifndef TD_USE_WINSOCK
#include <winsock2.h>
#else
#include <winsock.h>
#endif
#endif
...
...
include/os/osAtomic.h
浏览文件 @
fc245216
...
...
@@ -63,22 +63,22 @@ int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t
atomic_add_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_add_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_add_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_add_fetch_ptr
(
void
*
ptr
,
int32_t
val
);
void
*
atomic_add_fetch_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_fetch_add_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_fetch_add_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_fetch_add_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_fetch_add_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_fetch_add_ptr
(
void
*
ptr
,
int32_t
val
);
void
*
atomic_fetch_add_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_sub_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_sub_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_sub_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_sub_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_sub_fetch_ptr
(
void
*
ptr
,
int32_t
val
);
void
*
atomic_sub_fetch_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_fetch_sub_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_fetch_sub_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_fetch_sub_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_fetch_sub_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_fetch_sub_ptr
(
void
*
ptr
,
int32_t
val
);
void
*
atomic_fetch_sub_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_and_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_and_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_and_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
...
...
include/os/osDef.h
浏览文件 @
fc245216
...
...
@@ -191,7 +191,7 @@ extern "C" {
#define threadlocal __declspec( thread )
#endif
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#define PRIzu "ld"
#else
#define PRIzu "zu"
...
...
include/os/osDir.h
浏览文件 @
fc245216
...
...
@@ -36,12 +36,12 @@ typedef struct TdDirEntry *TdDirEntryPtr;
void
taosRemoveDir
(
const
char
*
dirname
);
bool
taosDirExist
(
char
*
dirname
);
bool
taosDirExist
(
c
onst
c
har
*
dirname
);
int32_t
taosMkDir
(
const
char
*
dirname
);
int32_t
taosMulMkDir
(
const
char
*
dirname
);
void
taosRemoveOldFiles
(
const
char
*
dirname
,
int32_t
keepDays
);
int32_t
taosExpandDir
(
const
char
*
dirname
,
char
*
outname
,
int32_t
maxlen
);
int32_t
taosRealPath
(
char
*
dirname
,
int32_t
maxlen
);
int32_t
taosRealPath
(
char
*
dirname
,
char
*
realPath
,
int32_t
maxlen
);
bool
taosIsDir
(
const
char
*
dirname
);
char
*
taosDirName
(
char
*
dirname
);
char
*
taosDirEntryBaseName
(
char
*
dirname
);
...
...
@@ -50,7 +50,7 @@ TdDirPtr taosOpenDir(const char *dirname);
TdDirEntryPtr
taosReadDir
(
TdDirPtr
pDir
);
bool
taosDirEntryIsDir
(
TdDirEntryPtr
pDirEntry
);
char
*
taosGetDirEntryName
(
TdDirEntryPtr
pDirEntry
);
int32_t
taosCloseDir
(
TdDirPtr
pDir
);
int32_t
taosCloseDir
(
TdDirPtr
*
p
pDir
);
#ifdef __cplusplus
}
...
...
include/os/osFile.h
浏览文件 @
fc245216
...
...
@@ -93,7 +93,6 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix,
int64_t
taosFSendFile
(
TdFilePtr
pFileOut
,
TdFilePtr
pFileIn
,
int64_t
*
offset
,
int64_t
size
);
void
*
taosMmapReadOnlyFile
(
TdFilePtr
pFile
,
int64_t
length
);
bool
taosValidFile
(
TdFilePtr
pFile
);
int32_t
taosGetErrorFile
(
TdFilePtr
pFile
);
...
...
include/os/osLz4.h
浏览文件 @
fc245216
...
...
@@ -20,7 +20,7 @@
extern
"C"
{
#endif
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
int32_t
BUILDIN_CLZL
(
uint64_t
val
);
int32_t
BUILDIN_CLZ
(
uint32_t
val
);
int32_t
BUILDIN_CTZL
(
uint64_t
val
);
...
...
include/os/osMath.h
浏览文件 @
fc245216
...
...
@@ -23,7 +23,7 @@ extern "C" {
#define TPOW2(x) ((x) * (x))
#define TABS(x) ((x) > 0 ? (x) : -(x))
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#define TSWAP(a, b, c) \
do { \
...
...
@@ -33,6 +33,7 @@ extern "C" {
} while (0)
#define TMAX(a, b) (((a) > (b)) ? (a) : (b))
#define TMIN(a, b) (((a) < (b)) ? (a) : (b))
#define TRANGE(aa, bb, cc) ((aa) = TMAX((aa), (bb)),(aa) = TMIN((aa), (cc)))
#else
...
...
include/os/osSocket.h
浏览文件 @
fc245216
...
...
@@ -19,32 +19,53 @@
// If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC
#define socket SOCKET_FUNC_TAOS_FORBID
#define bind BIND_FUNC_TAOS_FORBID
#define listen LISTEN_FUNC_TAOS_FORBID
#define accept ACCEPT_FUNC_TAOS_FORBID
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
#define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
#define inet_addr INET_ADDR_FUNC_TAOS_FORBID
#define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID
#define socket SOCKET_FUNC_TAOS_FORBID
#define bind BIND_FUNC_TAOS_FORBID
#define listen LISTEN_FUNC_TAOS_FORBID
#define accept ACCEPT_FUNC_TAOS_FORBID
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
#define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
#define inet_addr INET_ADDR_FUNC_TAOS_FORBID
#define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID
#endif
#if defined(WINDOWS)
#include "winsock2.h"
#include <WS2tcpip.h>
#include <winbase.h>
#include <Winsock2.h>
#if BYTE_ORDER == LITTLE_ENDIAN
#include <stdlib.h>
#define htobe16(x) _byteswap_ushort(x)
#define htole16(x) (x)
#define be16toh(x) _byteswap_ushort(x)
#define le16toh(x) (x)
#define htobe32(x) _byteswap_ulong(x)
#define htole32(x) (x)
#define be32toh(x) _byteswap_ulong(x)
#define le32toh(x) (x)
#define htobe64(x) _byteswap_uint64(x)
#define htole64(x) (x)
#define be64toh(x) _byteswap_uint64(x)
#define le64toh(x) (x)
#else
#error byte order not supported
#endif
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __PDP_ENDIAN PDP_ENDIAN
#else
#include <netinet/in.h>
#include <sys/socket.h>
#if defined(_TD_DARWIN_64)
#include <osEok.h>
#else
#include <netinet/in.h>
#include <sys/socket.h>
#if defined(_TD_DARWIN_64)
#include <osEok.h>
#else
#include <netinet/in.h>
#include <sys/epoll.h>
#endif
#include <sys/epoll.h>
#endif
#endif
#ifdef __cplusplus
...
...
@@ -52,14 +73,10 @@ extern "C" {
#endif
#if defined(WINDOWS)
#define htobe64 htonll
#endif
#if defined(WINDOWS)
typedef
int
socklen_t
;
#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)
...
...
@@ -79,31 +96,29 @@ extern "C" {
#if defined(_TD_DARWIN_64)
// #define htobe64 htonll
#
include <libkern/OSByteOrder.h>
#include <libkern/OSByteOrder.h>
#
define htobe16(x) OSSwapHostToBigInt16(x)
#
define htole16(x) OSSwapHostToLittleInt16(x)
#
define be16toh(x) OSSwapBigToHostInt16(x)
#
define le16toh(x) OSSwapLittleToHostInt16(x)
#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#
define htobe32(x) OSSwapHostToBigInt32(x)
#
define htole32(x) OSSwapHostToLittleInt32(x)
#
define be32toh(x) OSSwapBigToHostInt32(x)
#
define le32toh(x) OSSwapLittleToHostInt32(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#
define htobe64(x) OSSwapHostToBigInt64(x)
#
define htole64(x) OSSwapHostToLittleInt64(x)
#
define be64toh(x) OSSwapBigToHostInt64(x)
#
define le64toh(x) OSSwapLittleToHostInt64(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#
define __BYTE_ORDER BYTE_ORDER
#
define __BIG_ENDIAN BIG_ENDIAN
#
define __LITTLE_ENDIAN LITTLE_ENDIAN
#
define __PDP_ENDIAN PDP_ENDIAN
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __PDP_ENDIAN PDP_ENDIAN
#endif
#define TAOS_EPOLL_WAIT_TIME 500
typedef
int32_t
SocketFd
;
typedef
SocketFd
EpollFd
;
...
...
@@ -122,7 +137,7 @@ typedef struct TdEpoll *TdEpollPtr;
int32_t
taosSendto
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
,
unsigned
int
flags
,
const
struct
sockaddr
*
to
,
int
tolen
);
int32_t
taosWriteSocket
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
);
int32_t
taosReadSocket
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
);
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
socklen_
t
*
addrLen
);
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
in
t
*
addrLen
);
int32_t
taosCloseSocketNoCheck1
(
SocketFd
fd
);
int32_t
taosCloseSocket
(
TdSocketPtr
*
ppSocket
);
int32_t
taosCloseSocketServer
(
TdSocketServerPtr
*
ppSocketServer
);
...
...
@@ -139,14 +154,15 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t
taosReadMsg
(
TdSocketPtr
pSocket
,
void
*
ptr
,
int32_t
nbytes
);
int32_t
taosNonblockwrite
(
TdSocketPtr
pSocket
,
char
*
ptr
,
int32_t
nbytes
);
int64_t
taosCopyFds
(
TdSocketPtr
pSrcSocket
,
TdSocketPtr
pDestSocket
,
int64_t
len
);
void
taosWinSocketInit
();
TdSocketPtr
taosOpenUdpSocket
(
uint32_t
localIp
,
uint16_t
localPort
);
TdSocketPtr
taosOpenTcpClientSocket
(
uint32_t
ip
,
uint16_t
port
,
uint32_t
localIp
);
TdSocketServerPtr
taosOpenTcpServerSocket
(
uint32_t
ip
,
uint16_t
port
);
int32_t
taosKeepTcpAlive
(
TdSocketPtr
pSocket
);
TdSocketPtr
taosAcceptTcpConnectSocket
(
TdSocketServerPtr
pServerSocket
,
struct
sockaddr
*
destAddr
,
socklen_
t
*
addrLen
);
TdSocketPtr
taosAcceptTcpConnectSocket
(
TdSocketServerPtr
pServerSocket
,
struct
sockaddr
*
destAddr
,
in
t
*
addrLen
);
int32_t
taosGetSocketName
(
TdSocketPtr
pSocket
,
struct
sockaddr
*
destAddr
,
socklen_
t
*
addrLen
);
int32_t
taosGetSocketName
(
TdSocketPtr
pSocket
,
struct
sockaddr
*
destAddr
,
in
t
*
addrLen
);
void
taosBlockSIGPIPE
();
uint32_t
taosGetIpv4FromFqdn
(
const
char
*
);
...
...
include/os/osString.h
浏览文件 @
fc245216
...
...
@@ -39,7 +39,7 @@ typedef int32_t TdUcs4;
#define wchar_t WCHAR_T_TYPE_TAOS_FORBID
#endif
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#define tstrdup(str) _strdup(str)
#else
#define tstrdup(str) strdup(str)
...
...
include/os/osThread.h
浏览文件 @
fc245216
...
...
@@ -22,9 +22,12 @@
extern
"C"
{
#endif
#ifndef WINDOWS
#ifndef __USE_XOPEN2K
#define TD_USE_SPINLOCK_AS_MUTEX
typedef
pthread_mutex_t
pthread_spinlock_t
;
#endif
#endif
typedef
pthread_t
TdThread
;
typedef
pthread_spinlock_t
TdThreadSpinlock
;
...
...
@@ -41,6 +44,13 @@ typedef pthread_key_t TdThreadKey;
#define taosThreadCleanupPush pthread_cleanup_push
#define taosThreadCleanupPop pthread_cleanup_pop
#ifdef WINDOWS
#define TD_PTHREAD_MUTEX_INITIALIZER (TdThreadMutex)(-1)
#else
#define TD_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#endif
// If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC
...
...
@@ -218,8 +228,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock * lock);
int32_t
taosThreadSpinTrylock
(
TdThreadSpinlock
*
lock
);
int32_t
taosThreadSpinUnlock
(
TdThreadSpinlock
*
lock
);
void
taosThreadTestCancel
(
void
);
int32_t
taosThreadSigMask
(
int32_t
how
,
sigset_t
const
*
set
,
sigset_t
*
oset
);
int32_t
taosThreadSigWait
(
const
sigset_t
*
set
,
int32_t
*
sig
);
void
taosThreadClear
(
TdThread
*
thread
);
#ifdef __cplusplus
}
...
...
include/os/osTime.h
浏览文件 @
fc245216
...
...
@@ -20,8 +20,6 @@
extern
"C"
{
#endif
#include <time.h>
// If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC
...
...
@@ -34,7 +32,7 @@ extern "C" {
#define mktime MKTIME_FUNC_TAOS_FORBID
#endif
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#define CLOCK_REALTIME 0
...
...
@@ -58,6 +56,8 @@ extern "C" {
int32_t
taosGetTimeOfDay
(
struct
timeval
*
tv
);
int32_t
taosClockGetTime
(
int
clock_id
,
struct
timespec
*
pTS
);
//@return timestamp in second
int32_t
taosGetTimestampSec
();
...
...
@@ -78,7 +78,7 @@ static FORCE_INLINE int64_t taosGetTimestampUs() {
//@return timestamp in nanosecond
static
FORCE_INLINE
int64_t
taosGetTimestampNs
()
{
struct
timespec
systemTime
=
{
0
};
clock_gett
ime
(
CLOCK_REALTIME
,
&
systemTime
);
taosClockGetT
ime
(
CLOCK_REALTIME
,
&
systemTime
);
return
(
int64_t
)
systemTime
.
tv_sec
*
1000000000L
+
(
int64_t
)
systemTime
.
tv_nsec
;
}
...
...
include/util/tencode.h
浏览文件 @
fc245216
...
...
@@ -236,7 +236,8 @@ static FORCE_INLINE int32_t tEncodeFloat(SCoder* pEncoder, float val) {
union
{
uint32_t
ui
;
float
f
;
}
v
=
{.
f
=
val
};
}
v
;
v
.
f
=
val
;
return
tEncodeU32
(
pEncoder
,
v
.
ui
);
}
...
...
@@ -245,7 +246,8 @@ static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) {
union
{
uint64_t
ui
;
double
d
;
}
v
=
{.
d
=
val
};
}
v
;
v
.
d
=
val
;
return
tEncodeU64
(
pEncoder
,
v
.
ui
);
}
...
...
include/util/tjson.h
浏览文件 @
fc245216
...
...
@@ -22,6 +22,9 @@
extern
"C"
{
#endif
#ifdef WINDOWS
#define tjsonGetNumberValue(pJson, pName, val) -1
#else
#define tjsonGetNumberValue(pJson, pName, val) \
({ \
uint64_t _tmp = 0; \
...
...
@@ -29,6 +32,7 @@ extern "C" {
val = _tmp; \
_code; \
})
#endif
typedef
void
SJson
;
...
...
source/common/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -5,8 +5,8 @@ target_include_directories(
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/common"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
IF
(
${
TD_WINDOWS
}
)
PRIVATE
"
${
TD_SOURCE_DIR
}
/contrib/pthread
-win32
"
PRIVATE
"
${
TD_SOURCE_DIR
}
/contrib/
gnu
regex"
PRIVATE
"
${
TD_SOURCE_DIR
}
/contrib/pthread"
PRIVATE
"
${
TD_SOURCE_DIR
}
/contrib/
msvc
regex"
ENDIF
()
)
target_link_libraries
(
...
...
source/common/test/commonTests.cpp
浏览文件 @
fc245216
...
...
@@ -167,7 +167,7 @@ TEST(testCase, Datablock_test) {
printf
(
"the second row of binary:%s, length:%d
\n
"
,
(
char
*
)
varDataVal
(
pData
),
varDataLen
(
pData
));
SArray
*
pOrderInfo
=
taosArrayInit
(
3
,
sizeof
(
SBlockOrderInfo
));
SBlockOrderInfo
order
=
{
.
nullFirst
=
true
,
.
order
=
TSDB_ORDER_ASC
,
.
slotId
=
0
};
SBlockOrderInfo
order
=
{
true
,
TSDB_ORDER_ASC
,
0
,
NULL
};
taosArrayPush
(
pOrderInfo
,
&
order
);
blockDataSort
(
b
,
pOrderInfo
);
...
...
source/dnode/mgmt/exe/dmMain.c
浏览文件 @
fc245216
...
...
@@ -40,10 +40,12 @@ static void dmSetSignalHandle() {
taosSetSignal
(
SIGTERM
,
dmStopDnode
);
taosSetSignal
(
SIGHUP
,
dmStopDnode
);
taosSetSignal
(
SIGINT
,
dmStopDnode
);
taosSetSignal
(
SIGTSTP
,
dmStopDnode
);
taosSetSignal
(
SIGABRT
,
dmStopDnode
);
taosSetSignal
(
SIGBREAK
,
dmStopDnode
);
#ifndef WINDOWS
taosSetSignal
(
SIGTSTP
,
dmStopDnode
);
taosSetSignal
(
SIGQUIT
,
dmStopDnode
);
#endif
if
(
!
tsMultiProcess
)
{
}
else
if
(
global
.
ntype
==
DNODE
||
global
.
ntype
==
NODE_END
)
{
...
...
source/dnode/vnode/src/meta/metaIdx.c
浏览文件 @
fc245216
...
...
@@ -23,6 +23,9 @@ struct SMetaIdx {
SIndex
*
pIdx
;
#endif
/* data */
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
};
int
metaOpenIdx
(
SMeta
*
pMeta
)
{
...
...
source/dnode/vnode/src/meta/metaTDBImpl.c
浏览文件 @
fc245216
...
...
@@ -45,10 +45,12 @@ struct SMetaDB {
#endif
};
typedef
struct
__attribute__
((
__packed__
))
{
#pragma pack(push,1)
typedef
struct
{
tb_uid_t
uid
;
int32_t
sver
;
}
SSchemaDbKey
;
#pragma pack(pop)
typedef
struct
{
char
*
name
;
...
...
source/dnode/vnode/src/tq/tqMetaStore.c
浏览文件 @
fc245216
...
...
@@ -86,7 +86,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
}
strcpy
(
pMeta
->
dirPath
,
path
);
char
name
[
pathLen
+
10
]
;
char
*
name
=
taosMemoryMalloc
(
pathLen
+
10
)
;
strcpy
(
name
,
path
);
if
(
!
taosDirExist
(
name
)
&&
taosMkDir
(
name
)
!=
0
)
{
...
...
@@ -99,6 +99,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tqError
(
"failed to open file:%s since %s "
,
name
,
terrstr
());
// free memory
taosMemoryFree
(
name
);
return
NULL
;
}
...
...
@@ -106,6 +107,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
pMeta
->
unpersistHead
=
taosMemoryCalloc
(
1
,
sizeof
(
STqMetaList
));
if
(
pMeta
->
unpersistHead
==
NULL
)
{
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
taosMemoryFree
(
name
);
return
NULL
;
}
pMeta
->
unpersistHead
->
unpersistNext
=
pMeta
->
unpersistHead
->
unpersistPrev
=
pMeta
->
unpersistHead
;
...
...
@@ -116,8 +118,10 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tqError
(
"failed to open file:%s since %s"
,
name
,
terrstr
());
taosMemoryFree
(
name
);
return
NULL
;
}
taosMemoryFree
(
name
);
pMeta
->
pFile
=
pFile
;
...
...
source/libs/catalog/inc/catalogInt.h
浏览文件 @
fc245216
...
...
@@ -104,6 +104,10 @@ typedef struct SCatalog {
typedef
struct
SCtgApiStat
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SCtgApiStat
;
typedef
struct
SCtgRuntimeStat
{
...
...
source/libs/catalog/test/catalogTests.cpp
浏览文件 @
fc245216
...
...
@@ -24,6 +24,9 @@
#pragma GCC diagnostic ignored "-Wformat"
#include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "tglobal.h"
#include "catalog.h"
...
...
@@ -155,11 +158,11 @@ int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) {
}
void
ctgTestBuildCTableMetaOutput
(
STableMetaOutput
*
output
)
{
SName
cn
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
cn
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
cn
.
dbname
,
"db1"
);
strcpy
(
cn
.
tname
,
ctgTestCTablename
);
SName
sn
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
sn
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
sn
.
dbname
,
"db1"
);
strcpy
(
sn
.
tname
,
ctgTestSTablename
);
...
...
@@ -577,9 +580,16 @@ void ctgTestSetRspDbVgroups() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspDbVgroups
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspDbVgroups
);
}
...
...
@@ -590,9 +600,16 @@ void ctgTestSetRspTableMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspTableMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspTableMeta
);
}
...
...
@@ -603,9 +620,16 @@ void ctgTestSetRspCTableMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspCTableMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspCTableMeta
);
}
...
...
@@ -616,9 +640,16 @@ void ctgTestSetRspSTableMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspSTableMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspSTableMeta
);
}
...
...
@@ -629,9 +660,16 @@ void ctgTestSetRspMultiSTableMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspMultiSTableMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspMultiSTableMeta
);
}
...
...
@@ -642,9 +680,16 @@ void ctgTestSetRspByIdx() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspByIdx
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspByIdx
);
}
...
...
@@ -656,9 +701,16 @@ void ctgTestSetRspDbVgroupsAndNormalMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspDbVgroupsAndNormalMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspDbVgroupsAndNormalMeta
);
}
...
...
@@ -669,9 +721,16 @@ void ctgTestSetRspDbVgroupsAndChildMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspDbVgroupsAndChildMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspDbVgroupsAndChildMeta
);
}
...
...
@@ -682,9 +741,16 @@ void ctgTestSetRspDbVgroupsAndSuperMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspDbVgroupsAndSuperMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspDbVgroupsAndSuperMeta
);
}
...
...
@@ -695,9 +761,16 @@ void ctgTestSetRspDbVgroupsAndMultiSuperMeta() {
static
Stub
stub
;
stub
.
set
(
rpcSendRecv
,
ctgTestRspDbVgroupsAndMultiSuperMeta
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRecv"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRecv$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
ctgTestRspDbVgroupsAndMultiSuperMeta
);
}
...
...
@@ -789,7 +862,7 @@ void *ctgTestGetCtableMetaThread(void *param) {
STableMeta
*
tbMeta
=
NULL
;
bool
inCache
=
false
;
SName
cn
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
cn
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
cn
.
dbname
,
"db1"
);
strcpy
(
cn
.
tname
,
ctgTestCTablename
);
...
...
@@ -871,7 +944,7 @@ TEST(tableMeta, normalTable) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -978,7 +1051,7 @@ TEST(tableMeta, childTableCase) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestCTablename
);
...
...
@@ -1085,7 +1158,7 @@ TEST(tableMeta, superTableCase) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestSTablename
);
...
...
@@ -1210,7 +1283,7 @@ TEST(tableMeta, rmStbMeta) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestSTablename
);
...
...
@@ -1280,7 +1353,7 @@ TEST(tableMeta, updateStbMeta) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestSTablename
);
...
...
@@ -1378,7 +1451,7 @@ TEST(refreshGetMeta, normal2normal) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -1457,7 +1530,7 @@ TEST(refreshGetMeta, normal2notexist) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -1529,7 +1602,7 @@ TEST(refreshGetMeta, normal2child) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
ctgTestCurrentCTableName
=
ctgTestTablename
;
...
...
@@ -1613,7 +1686,7 @@ TEST(refreshGetMeta, stable2child) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
ctgTestCurrentSTableName
=
ctgTestTablename
;
...
...
@@ -1699,7 +1772,7 @@ TEST(refreshGetMeta, stable2stable) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
ctgTestCurrentSTableName
=
ctgTestTablename
;
...
...
@@ -1786,7 +1859,7 @@ TEST(refreshGetMeta, child2stable) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
ctgTestCurrentCTableName
=
ctgTestTablename
;
...
...
@@ -1871,7 +1944,7 @@ TEST(tableDistVgroup, normalTable) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -1913,7 +1986,7 @@ TEST(tableDistVgroup, childTableCase) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestCTablename
);
...
...
@@ -1956,7 +2029,7 @@ TEST(tableDistVgroup, superTableCase) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestSTablename
);
...
...
@@ -2006,7 +2079,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -2091,7 +2164,7 @@ TEST(multiThread, getSetRmSameDbVgroup) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -2143,7 +2216,7 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -2195,7 +2268,7 @@ TEST(multiThread, ctableMeta) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
strcpy
(
n
.
tname
,
ctgTestTablename
);
...
...
@@ -2247,7 +2320,7 @@ TEST(rentTest, allRent) {
code
=
catalogGetHandle
(
ctgTestClusterId
,
&
pCtg
);
ASSERT_EQ
(
code
,
0
);
SName
n
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
1
};
SName
n
=
{
TSDB_TABLE_NAME_T
,
1
,
{
0
},
{
0
}
};
strcpy
(
n
.
dbname
,
"db1"
);
for
(
int32_t
i
=
1
;
i
<=
10
;
++
i
)
{
...
...
source/libs/executor/src/groupoperator.c
浏览文件 @
fc245216
...
...
@@ -410,8 +410,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
int32_t
contentLen
=
0
;
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
int32_t
*
offset
=
pPage
+
startOffset
;
columnLen
=
pPage
+
startOffset
+
sizeof
(
int32_t
)
*
pInfo
->
rowCapacity
;
int32_t
*
offset
=
(
int32_t
*
)((
char
*
)
pPage
+
startOffset
)
;
columnLen
=
(
char
*
)
pPage
+
startOffset
+
sizeof
(
int32_t
)
*
pInfo
->
rowCapacity
;
char
*
data
=
(
char
*
)(
columnLen
+
sizeof
(
int32_t
));
if
(
colDataIsNull_s
(
pColInfoData
,
j
))
{
...
...
@@ -424,8 +424,8 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
contentLen
=
varDataTLen
(
src
);
}
}
else
{
char
*
bitmap
=
pPage
+
startOffset
;
columnLen
=
pPage
+
startOffset
+
BitmapLen
(
pInfo
->
rowCapacity
);
char
*
bitmap
=
(
char
*
)
pPage
+
startOffset
;
columnLen
=
(
char
*
)
pPage
+
startOffset
+
BitmapLen
(
pInfo
->
rowCapacity
);
char
*
data
=
(
char
*
)
columnLen
+
sizeof
(
int32_t
);
bool
isNull
=
colDataIsNull_f
(
pColInfoData
->
nullbitmap
,
j
);
...
...
source/libs/executor/src/tsimplehash.c
浏览文件 @
fc245216
...
...
@@ -48,7 +48,7 @@ struct SSHashObj {
};
static
FORCE_INLINE
int32_t
taosHashCapacity
(
int32_t
length
)
{
int32_t
len
=
MIN
(
length
,
HASH_MAX_CAPACITY
);
int32_t
len
=
(
length
<
HASH_MAX_CAPACITY
?
length
:
HASH_MAX_CAPACITY
);
int32_t
i
=
4
;
while
(
i
<
len
)
i
=
(
i
<<
1u
);
...
...
@@ -127,7 +127,7 @@ static void taosHashTableResize(SSHashObj *pHashObj) {
}
size_t
inc
=
newCapacity
-
pHashObj
->
capacity
;
memset
(
pNewEntryList
+
pHashObj
->
capacity
*
sizeof
(
void
*
),
0
,
inc
);
memset
(
(
char
*
)
pNewEntryList
+
pHashObj
->
capacity
*
sizeof
(
void
*
),
0
,
inc
);
pHashObj
->
hashList
=
pNewEntryList
;
pHashObj
->
capacity
=
newCapacity
;
...
...
@@ -301,7 +301,7 @@ size_t tSimpleHashGetMemSize(const SSHashObj *pHashObj) {
void
*
tSimpleHashGetKey
(
const
SSHashObj
*
pHashObj
,
void
*
data
,
size_t
*
keyLen
)
{
int32_t
offset
=
offsetof
(
SHNode
,
data
);
SHNode
*
node
=
data
-
offset
;
SHNode
*
node
=
((
SHNode
*
)(
char
*
)
data
-
offset
)
;
if
(
keyLen
!=
NULL
)
{
*
keyLen
=
pHashObj
->
keyLen
;
}
...
...
source/libs/executor/test/executorTests.cpp
浏览文件 @
fc245216
...
...
@@ -102,7 +102,7 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
}
else
if
(
pInfo
->
type
==
data_asc
)
{
v
=
++
pInfo
->
startVal
;
}
else
if
(
pInfo
->
type
==
data_rand
)
{
v
=
random
();
v
=
taosRand
();
}
colDataAppend
(
pColInfo
,
i
,
reinterpret_cast
<
const
char
*>
(
&
v
),
false
);
...
...
@@ -172,7 +172,7 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
}
else
if
(
pInfo
->
type
==
data_asc
)
{
v
=
++
pInfo
->
startVal
;
}
else
if
(
pInfo
->
type
==
data_rand
)
{
v
=
random
();
v
=
taosRand
();
}
colDataAppend
(
pColInfo1
,
i
,
reinterpret_cast
<
const
char
*>
(
&
v
),
false
);
...
...
@@ -938,7 +938,7 @@ TEST(testCase, build_executor_tree_Test) {
SExecTaskInfo
*
pTaskInfo
=
nullptr
;
DataSinkHandle
sinkHandle
=
nullptr
;
SReadHandle
handle
=
{
.
reader
=
reinterpret_cast
<
void
*>
(
0x1
),
.
meta
=
reinterpret_cast
<
void
*>
(
0x1
)
};
SReadHandle
handle
=
{
reinterpret_cast
<
void
*>
(
0x1
),
reinterpret_cast
<
void
*>
(
0x1
),
NULL
};
struct
SSubplan
*
plan
=
NULL
;
int32_t
code
=
qStringToSubplan
(
msg
,
&
plan
);
...
...
source/libs/function/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -47,6 +47,9 @@ target_include_directories(
"
${
TD_SOURCE_DIR
}
/include/os"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
target_link_libraries
(
udf1 PUBLIC os
)
#SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin)
add_executable
(
udfd src/udfd.c
)
...
...
source/libs/function/inc/tudfInt.h
浏览文件 @
fc245216
...
...
@@ -69,6 +69,9 @@ typedef struct SUdfTeardownRequest {
typedef
struct
SUdfTeardownResponse
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SUdfTeardownResponse
;
typedef
struct
SUdfRequest
{
...
...
source/libs/function/inc/udfc.h
浏览文件 @
fc245216
...
...
@@ -84,6 +84,9 @@ typedef struct SUdfTeardownRequest {
typedef
struct
SUdfTeardownResponse
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SUdfTeardownResponse
;
typedef
struct
SUdfRequest
{
...
...
source/libs/index/inc/indexFstRegex.h
浏览文件 @
fc245216
...
...
@@ -31,6 +31,9 @@ extern "C" {
typedef
enum
{
MATCH
,
JUMP
,
SPLIT
,
RANGE
}
InstType
;
typedef
struct
MatchValue
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
MatchValue
;
typedef
struct
JumpValue
{
uint32_t
step
;
...
...
source/libs/index/src/indexTfile.c
浏览文件 @
fc245216
...
...
@@ -748,7 +748,7 @@ static SArray* tfileGetFileList(const char* path) {
sprintf
(
buf
,
"%s/%s"
,
path
,
file
);
taosArrayPush
(
files
,
&
buf
);
}
taosCloseDir
(
pDir
);
taosCloseDir
(
&
pDir
);
taosArraySort
(
files
,
tfileCompare
);
tfileRmExpireFile
(
files
);
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
fc245216
...
...
@@ -485,7 +485,7 @@ TEST_F(IndexTFileEnv, test_tfile_write) {
std
::
string
colVal
(
"ab"
);
SIndexTerm
*
term
=
indexTermCreate
(
1
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
SIndexTermQuery
query
=
{
.
term
=
term
,
.
qType
=
QUERY_TERM
};
SIndexTermQuery
query
=
{
term
,
QUERY_TERM
};
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
fObj
->
Get
(
&
query
,
result
);
...
...
@@ -625,7 +625,7 @@ TEST_F(IndexCacheEnv, cache_test) {
std
::
string
colVal
(
"v3"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
SIndexTermQuery
query
=
{
.
term
=
term
,
.
qType
=
QUERY_TERM
};
SIndexTermQuery
query
=
{
term
,
QUERY_TERM
};
SArray
*
ret
=
(
SArray
*
)
taosArrayInit
(
4
,
sizeof
(
suid
));
STermValueType
valType
;
...
...
@@ -640,7 +640,7 @@ TEST_F(IndexCacheEnv, cache_test) {
std
::
string
colVal
(
"v2"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
SIndexTermQuery
query
=
{
.
term
=
term
,
.
qType
=
QUERY_TERM
};
SIndexTermQuery
query
=
{
term
,
QUERY_TERM
};
SArray
*
ret
=
(
SArray
*
)
taosArrayInit
(
4
,
sizeof
(
suid
));
STermValueType
valType
;
...
...
source/libs/index/test/jsonUT.cc
浏览文件 @
fc245216
...
...
@@ -108,7 +108,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
{
std
::
string
colName
(
"voltagefdadfa"
);
std
::
string
colVal
(
"abxxxxxxxxxxxx"
);
for
(
u
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
colVal
[
i
%
colVal
.
size
()]
=
'0'
+
i
%
128
;
SIndexTerm
*
term
=
indexTermCreate
(
1
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
...
...
source/libs/parser/inc/parToken.h
浏览文件 @
fc245216
...
...
@@ -20,7 +20,6 @@
extern
"C"
{
#endif
#include "os.h"
#include "ttokendef.h"
// used to denote the minimum unite in sql parsing
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
fc245216
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "parInt.h"
#include "parAst.h"
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
fc245216
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "parInsertData.h"
#include "parInt.h"
#include "parToken.h"
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
fc245216
...
...
@@ -49,12 +49,14 @@ static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_B
static
bool
beforeHaving
(
ESqlClause
clause
)
{
return
clause
<
SQL_CLAUSE_HAVING
;
}
#define generateDealNodeErrMsg(pCxt, code, ...) \
({ \
generateSyntaxErrMsg(&pCxt->msgBuf, code, ##__VA_ARGS__); \
pCxt->errCode = code; \
DEAL_RES_ERROR; \
})
enum
EDealRes
generateDealNodeErrMsg
(
STranslateContext
*
pCxt
,
int32_t
code
,
...)
{
va_list
ap
;
va_start
(
ap
,
code
);
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
code
,
ap
);
va_end
(
ap
);
pCxt
->
errCode
=
code
;
return
DEAL_RES_ERROR
;
}
static
int32_t
addNamespace
(
STranslateContext
*
pCxt
,
void
*
pTable
)
{
size_t
currTotalLevel
=
taosArrayGetSize
(
pCxt
->
pNsLevel
);
...
...
source/libs/parser/src/parser.c
浏览文件 @
fc245216
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "parser.h"
#include "parInt.h"
...
...
source/libs/parser/src/sql.c
浏览文件 @
fc245216
...
...
@@ -32,6 +32,7 @@
#include <assert.h>
#include <stdbool.h>
#include "os.h"
#include "functionMgt.h"
#include "nodes.h"
#include "parToken.h"
...
...
source/libs/parser/test/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -17,3 +17,11 @@ TARGET_LINK_LIBRARIES(
parserTest
PUBLIC os util common nodes parser catalog transport gtest function planner qcom
)
if
(
${
BUILD_WINGETOPT
}
)
target_include_directories
(
parserTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/wingetopt/src"
)
target_link_libraries
(
parserTest PUBLIC wingetopt
)
endif
()
\ No newline at end of file
source/libs/parser/test/mockCatalog.cpp
浏览文件 @
fc245216
...
...
@@ -12,7 +12,6 @@
* 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/>.
*/
#include <iostream>
#include "stub.h"
...
...
@@ -23,6 +22,9 @@
#pragma GCC diagnostic pop
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "mockCatalog.h"
namespace
{
...
...
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
fc245216
...
...
@@ -40,13 +40,11 @@ public:
virtual
TableBuilder
&
setVgid
(
int16_t
vgid
)
{
schema
()
->
vgId
=
vgid
;
SVgroupInfo
vgroup
=
{.
vgId
=
vgid
,
.
hashBegin
=
0
,
.
hashEnd
=
0
,
};
vgroup
.
epSet
.
eps
[
0
]
=
(
SEp
){
"dnode_1"
,
6030
};
vgroup
.
epSet
.
eps
[
1
]
=
(
SEp
){
"dnode_2"
,
6030
};
vgroup
.
epSet
.
eps
[
2
]
=
(
SEp
){
"dnode_3"
,
6030
};
SVgroupInfo
vgroup
=
{
vgid
,
0
,
0
,
{
0
},
0
};
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_2"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_3"
,
6030
);
vgroup
.
epSet
.
inUse
=
0
;
vgroup
.
epSet
.
numOfEps
=
3
;
meta_
->
vgs
.
emplace_back
(
vgroup
);
return
*
this
;
...
...
@@ -148,7 +146,7 @@ public:
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
meta_
[
db
][
tbname
]
->
schema
->
tableType
=
TSDB_CHILD_TABLE
;
SVgroupInfo
vgroup
=
{
.
vgId
=
vgid
,
.
hashBegin
=
0
,
.
hashEnd
=
0
,
};
SVgroupInfo
vgroup
=
{
vgid
,
0
,
0
,
{
0
},
0
};
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_2"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_3"
,
6030
);
...
...
source/libs/parser/test/parserInsertTest.cpp
浏览文件 @
fc245216
...
...
@@ -15,6 +15,7 @@
#include <gtest/gtest.h>
#include "os.h"
#include "parInt.h"
using
namespace
std
;
...
...
source/libs/parser/test/parserTestMain.cpp
浏览文件 @
fc245216
...
...
@@ -14,14 +14,20 @@
*/
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <gtest/gtest.h>
#include "mockCatalog.h"
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "parserTestUtil.h"
#include "parToken.h"
#include "functionMgt.h"
#include "mockCatalog.h"
bool
g_isDump
=
false
;
...
...
source/libs/planner/test/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -22,3 +22,12 @@ TARGET_INCLUDE_DIRECTORIES(
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/libs/planner/inc"
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/libs/parser/test"
)
if
(
${
BUILD_WINGETOPT
}
)
target_include_directories
(
plannerTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/wingetopt/src"
)
target_link_libraries
(
plannerTest PUBLIC wingetopt
)
endif
()
\ No newline at end of file
source/libs/planner/test/planTestMain.cpp
浏览文件 @
fc245216
...
...
@@ -16,7 +16,7 @@
#include <string>
#include <gtest/gtest.h>
#include "getopt.h"
#include "mockCatalog.h"
#include "planTestUtil.h"
...
...
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
fc245216
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <array>
#include "planTestUtil.h"
#include <algorithm>
...
...
source/libs/qworker/inc/qworkerInt.h
浏览文件 @
fc245216
...
...
@@ -95,6 +95,9 @@ typedef struct SQWPhaseInput {
}
SQWPhaseInput
;
typedef
struct
SQWPhaseOutput
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SQWPhaseOutput
;
...
...
source/libs/qworker/test/qworkerTests.cpp
浏览文件 @
fc245216
...
...
@@ -27,6 +27,9 @@
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "tglobal.h"
...
...
@@ -277,8 +280,8 @@ int32_t qwtCreateExecTask(void* tsdb, int32_t vgId, uint64_t taskId, struct SSub
qwtTestSinkMaxBlockNum
=
taosRand
()
%
100
+
1
;
qwtTestSinkQueryEnd
=
false
;
*
pTaskInfo
=
(
qTaskInfo_t
)
qwtTestCaseIdx
+
1
;
*
handle
=
(
DataSinkHandle
)
qwtTestCaseIdx
+
2
;
*
pTaskInfo
=
(
qTaskInfo_t
)
((
char
*
)
qwtTestCaseIdx
+
1
)
;
*
handle
=
(
DataSinkHandle
)
((
char
*
)
qwtTestCaseIdx
+
2
)
;
++
qwtTestCaseIdx
;
...
...
@@ -435,9 +438,16 @@ void stubSetStringToPlan() {
static
Stub
stub
;
stub
.
set
(
qStringToSubplan
,
qwtStringToPlan
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"qStringToSubplan"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libplanner.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^qStringToSubplan$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtStringToPlan
);
}
...
...
@@ -448,9 +458,16 @@ void stubSetExecTask() {
static
Stub
stub
;
stub
.
set
(
qExecTask
,
qwtExecTask
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"qExecTask"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^qExecTask$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtExecTask
);
}
...
...
@@ -463,9 +480,16 @@ void stubSetCreateExecTask() {
static
Stub
stub
;
stub
.
set
(
qCreateExecTask
,
qwtCreateExecTask
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"qCreateExecTask"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^qCreateExecTask$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtCreateExecTask
);
}
...
...
@@ -476,9 +500,16 @@ void stubSetAsyncKillTask() {
static
Stub
stub
;
stub
.
set
(
qAsyncKillTask
,
qwtKillTask
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"qAsyncKillTask"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^qAsyncKillTask$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtKillTask
);
}
...
...
@@ -489,9 +520,16 @@ void stubSetDestroyTask() {
static
Stub
stub
;
stub
.
set
(
qDestroyTask
,
qwtDestroyTask
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"qDestroyTask"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^qDestroyTask$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtDestroyTask
);
}
...
...
@@ -503,9 +541,16 @@ void stubSetDestroyDataSinker() {
static
Stub
stub
;
stub
.
set
(
dsDestroyDataSinker
,
qwtDestroyDataSinker
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"dsDestroyDataSinker"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^dsDestroyDataSinker$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtDestroyDataSinker
);
}
...
...
@@ -516,9 +561,16 @@ void stubSetGetDataLength() {
static
Stub
stub
;
stub
.
set
(
dsGetDataLength
,
qwtGetDataLength
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"dsGetDataLength"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^dsGetDataLength$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtGetDataLength
);
}
...
...
@@ -529,9 +581,16 @@ void stubSetEndPut() {
static
Stub
stub
;
stub
.
set
(
dsEndPut
,
qwtEndPut
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"dsEndPut"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^dsEndPut$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtEndPut
);
}
...
...
@@ -542,9 +601,16 @@ void stubSetPutDataBlock() {
static
Stub
stub
;
stub
.
set
(
dsPutDataBlock
,
qwtPutDataBlock
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"dsPutDataBlock"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libexecutor.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^dsPutDataBlock$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtPutDataBlock
);
}
...
...
@@ -555,9 +621,16 @@ void stubSetRpcSendResponse() {
static
Stub
stub
;
stub
.
set
(
rpcSendResponse
,
qwtRpcSendResponse
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendResponse"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendResponse$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtRpcSendResponse
);
}
...
...
@@ -568,9 +641,16 @@ void stubSetGetDataBlock() {
static
Stub
stub
;
stub
.
set
(
dsGetDataBlock
,
qwtGetDataBlock
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"dsGetDataBlock"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^dsGetDataBlock$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
qwtGetDataBlock
);
}
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
fc245216
...
...
@@ -621,13 +621,13 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
if
(
subPos
>
0
)
{
startPosBytes
=
(
GET_PARAM_TYPE
(
pInput
)
==
TSDB_DATA_TYPE_VARCHAR
)
?
subPos
-
1
:
(
subPos
-
1
)
*
TSDB_NCHAR_SIZE
;
startPosBytes
=
MIN
(
startPosBytes
,
len
);
startPosBytes
=
T
MIN
(
startPosBytes
,
len
);
}
else
{
startPosBytes
=
(
GET_PARAM_TYPE
(
pInput
)
==
TSDB_DATA_TYPE_VARCHAR
)
?
len
+
subPos
:
len
+
subPos
*
TSDB_NCHAR_SIZE
;
startPosBytes
=
MAX
(
startPosBytes
,
0
);
startPosBytes
=
T
MAX
(
startPosBytes
,
0
);
}
int32_t
resLen
=
MIN
(
subLen
,
len
-
startPosBytes
);
int32_t
resLen
=
T
MIN
(
subLen
,
len
-
startPosBytes
);
if
(
resLen
>
0
)
{
memcpy
(
varDataVal
(
output
),
varDataVal
(
input
)
+
startPosBytes
,
resLen
);
}
...
...
@@ -716,7 +716,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t
len
=
sprintf
(
varDataVal
(
output
),
"%.*s"
,
(
int32_t
)(
outputLen
-
VARSTR_HEADER_SIZE
),
*
(
int8_t
*
)
input
?
"true"
:
"false"
);
varDataSetLen
(
output
,
len
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
len
=
MIN
(
varDataLen
(
input
),
outputLen
-
VARSTR_HEADER_SIZE
);
int32_t
len
=
T
MIN
(
varDataLen
(
input
),
outputLen
-
VARSTR_HEADER_SIZE
);
len
=
sprintf
(
varDataVal
(
output
),
"%.*s"
,
len
,
varDataVal
(
input
));
varDataSetLen
(
output
,
len
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
...
...
@@ -750,7 +750,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
}
varDataSetLen
(
output
,
len
);
}
else
if
(
inputType
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
len
=
MIN
(
outputLen
,
varDataLen
(
input
)
+
VARSTR_HEADER_SIZE
);
int32_t
len
=
T
MIN
(
outputLen
,
varDataLen
(
input
)
+
VARSTR_HEADER_SIZE
);
memcpy
(
output
,
input
,
len
);
varDataSetLen
(
output
,
len
-
VARSTR_HEADER_SIZE
);
}
else
{
...
...
source/libs/scalar/test/filter/filterTests.cpp
浏览文件 @
fc245216
...
...
@@ -27,6 +27,9 @@
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "tglobal.h"
...
...
@@ -364,7 +367,7 @@ TEST(columnTest, smallint_column_greater_double_value) {
keep
=
filterRangeExecute
(
filter
,
&
stat
,
1
,
rowNum
);
ASSERT_EQ
(
keep
,
true
);
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -419,7 +422,7 @@ TEST(columnTest, int_column_greater_smallint_value) {
keep
=
filterRangeExecute
(
filter
,
&
stat
,
1
,
rowNum
);
ASSERT_EQ
(
keep
,
false
);
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -463,7 +466,7 @@ TEST(columnTest, int_column_in_double_list) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -527,7 +530,7 @@ TEST(columnTest, binary_column_in_binary_list) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -575,7 +578,7 @@ TEST(columnTest, binary_column_like_binary) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -622,7 +625,7 @@ TEST(columnTest, binary_column_is_null) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -669,7 +672,7 @@ TEST(columnTest, binary_column_is_not_null) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -706,7 +709,7 @@ TEST(opTest, smallint_column_greater_int_column) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -744,7 +747,7 @@ TEST(opTest, smallint_value_add_int_column) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -787,7 +790,7 @@ TEST(opTest, bigint_column_multi_binary_column) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -830,7 +833,7 @@ TEST(opTest, smallint_column_and_binary_column) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -868,7 +871,7 @@ TEST(opTest, smallint_column_or_float_column) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -906,7 +909,7 @@ TEST(opTest, smallint_column_or_double_value) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -950,7 +953,7 @@ TEST(opTest, binary_column_is_true) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -1021,7 +1024,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -1090,7 +1093,7 @@ TEST(filterModelogicTest, same_column_and_or_and) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -1159,7 +1162,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -1228,7 +1231,7 @@ TEST(filterModelogicTest, same_column_or_and_or) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -1299,7 +1302,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
ASSERT_EQ
(
code
,
0
);
SColumnDataAgg
stat
=
{
0
};
SFilterColumnParam
param
=
{
.
numOfCols
=
src
->
info
.
numOfCols
,
.
pDataBlock
=
src
->
pDataBlock
};
SFilterColumnParam
param
=
{
src
->
info
.
numOfCols
,
src
->
pDataBlock
};
code
=
filterSetDataFromSlotId
(
filter
,
&
param
);
ASSERT_EQ
(
code
,
0
);
...
...
source/libs/scalar/test/scalar/scalarTests.cpp
浏览文件 @
fc245216
...
...
@@ -27,6 +27,9 @@
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "tglobal.h"
...
...
source/libs/scheduler/inc/schedulerInt.h
浏览文件 @
fc245216
...
...
@@ -52,14 +52,26 @@ typedef struct SSchHbTrans {
typedef
struct
SSchApiStat
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SSchApiStat
;
typedef
struct
SSchRuntimeStat
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SSchRuntimeStat
;
typedef
struct
SSchJobStat
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SSchJobStat
;
typedef
struct
SSchedulerStat
{
...
...
source/libs/scheduler/test/schedulerTests.cpp
浏览文件 @
fc245216
...
...
@@ -25,7 +25,9 @@
#pragma GCC diagnostic ignored "-Wformat"
#include <addr_any.h>
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "tglobal.h"
...
...
@@ -275,9 +277,16 @@ void schtSetPlanToString() {
static
Stub
stub
;
stub
.
set
(
qSubPlanToString
,
schtPlanToString
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"qSubPlanToString"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libplanner.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^qSubPlanToString$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
schtPlanToString
);
}
...
...
@@ -288,9 +297,16 @@ void schtSetExecNode() {
static
Stub
stub
;
stub
.
set
(
qSetSubplanExecutionNode
,
schtExecNode
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"qSetSubplanExecutionNode"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libplanner.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^qSetSubplanExecutionNode$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
schtExecNode
);
}
...
...
@@ -301,9 +317,16 @@ void schtSetRpcSendRequest() {
static
Stub
stub
;
stub
.
set
(
rpcSendRequest
,
schtRpcSendRequest
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"rpcSendRequest"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^rpcSendRequest$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
schtRpcSendRequest
);
}
...
...
@@ -324,9 +347,16 @@ void schtSetAsyncSendMsgToServer() {
static
Stub
stub
;
stub
.
set
(
asyncSendMsgToServer
,
schtAsyncSendMsgToServer
);
{
#ifdef WINDOWS
AddrAny
any
;
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_func_addr
(
"asyncSendMsgToServer"
,
result
);
#endif
#ifdef LINUX
AddrAny
any
(
"libtransport.so"
);
std
::
map
<
std
::
string
,
void
*>
result
;
any
.
get_global_func_addr_dynsym
(
"^asyncSendMsgToServer$"
,
result
);
#endif
for
(
const
auto
&
f
:
result
)
{
stub
.
set
(
f
.
second
,
schtAsyncSendMsgToServer
);
}
...
...
@@ -382,6 +412,7 @@ void *schtCreateFetchRspThread(void *param) {
schReleaseJob
(
job
);
assert
(
code
==
0
);
return
NULL
;
}
...
...
@@ -413,6 +444,7 @@ void *schtFetchRspThread(void *aa) {
assert
(
code
==
0
||
code
);
}
return
NULL
;
}
void
schtFreeQueryJob
(
int32_t
freeThread
)
{
...
...
@@ -595,6 +627,7 @@ void* schtRunJobThread(void *aa) {
schedulerDestroy
();
return
NULL
;
}
void
*
schtFreeJobThread
(
void
*
aa
)
{
...
...
@@ -602,6 +635,7 @@ void* schtFreeJobThread(void *aa) {
taosUsleep
(
taosRand
()
%
100
);
schtFreeQueryJob
(
1
);
}
return
NULL
;
}
...
...
source/libs/sync/src/syncEnv.c
浏览文件 @
fc245216
...
...
@@ -14,7 +14,7 @@
*/
#include "syncEnv.h"
#include <assert.h>
//
#include <assert.h>
SSyncEnv
*
gSyncEnv
=
NULL
;
...
...
source/libs/tdb/CMakeLists.txt
浏览文件 @
fc245216
# tdb
add_library
(
tdb
""
)
add_library
(
tdb
STATIC
""
)
target_sources
(
tdb
PRIVATE
"src/db/tdbPCache.c"
...
...
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
fc245216
...
...
@@ -42,14 +42,17 @@ struct SBTree {
ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \
TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0))
typedef
struct
__attribute__
((
__packed__
))
{
#pragma pack(push,1)
typedef
struct
{
TDB_BTREE_PAGE_COMMON_HDR
}
SLeafHdr
;
typedef
struct
__attribute__
((
__packed__
))
{
TDB_BTREE_PAGE_COMMON_HDR
;
typedef
struct
{
TDB_BTREE_PAGE_COMMON_HDR
SPgno
pgno
;
// right-most child
}
SIntHdr
;
#pragma pack(pop)
typedef
struct
{
u8
flags
;
...
...
source/libs/tdb/src/db/tdbPCache.c
浏览文件 @
fc245216
...
...
@@ -28,11 +28,10 @@ struct SPCache {
SPage
lru
;
};
#define PCACHE_PAGE_HASH(pPgid) \
({ \
u32 *t = (u32 *)((pPgid)->fileid); \
t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno; \
})
static
inline
int
tdbPCachePageHash
(
const
SPgid
*
pPgid
)
{
u32
*
t
=
(
u32
*
)((
pPgid
)
->
fileid
);
return
t
[
0
]
+
t
[
1
]
+
t
[
2
]
+
t
[
3
]
+
t
[
4
]
+
t
[
5
]
+
(
pPgid
)
->
pgno
;
}
#define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL)
static
int
tdbPCacheOpenImpl
(
SPCache
*
pCache
);
...
...
@@ -130,7 +129,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
SPage
*
pPage
;
// 1. Search the hash table
pPage
=
pCache
->
pgHash
[
PCACHE_PAGE_HASH
(
pPgid
)
%
pCache
->
nHash
];
pPage
=
pCache
->
pgHash
[
tdbPCachePageHash
(
pPgid
)
%
pCache
->
nHash
];
while
(
pPage
)
{
if
(
TDB_IS_SAME_PAGE
(
&
(
pPage
->
pgid
),
pPgid
))
break
;
pPage
=
pPage
->
pHashNext
;
...
...
@@ -218,7 +217,7 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) {
SPage
**
ppPage
;
int
h
;
h
=
PCACHE_PAGE_HASH
(
&
(
pPage
->
pgid
));
h
=
tdbPCachePageHash
(
&
(
pPage
->
pgid
));
for
(
ppPage
=
&
(
pCache
->
pgHash
[
h
%
pCache
->
nHash
]);
*
ppPage
!=
pPage
;
ppPage
=
&
((
*
ppPage
)
->
pHashNext
))
;
ASSERT
(
*
ppPage
==
pPage
);
...
...
@@ -230,7 +229,7 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) {
static
void
tdbPCacheAddPageToHash
(
SPCache
*
pCache
,
SPage
*
pPage
)
{
int
h
;
h
=
PCACHE_PAGE_HASH
(
&
(
pPage
->
pgid
))
%
pCache
->
nHash
;
h
=
tdbPCachePageHash
(
&
(
pPage
->
pgid
))
%
pCache
->
nHash
;
pPage
->
pHashNext
=
pCache
->
pgHash
[
h
];
pCache
->
pgHash
[
h
]
=
pPage
;
...
...
source/libs/tdb/src/db/tdbPage.c
浏览文件 @
fc245216
...
...
@@ -435,17 +435,20 @@ static int tdbPageDefragment(SPage *pPage) {
}
/* ---------------------------------------------------------------------------------------------------------- */
typedef
struct
__attribute__
((
__packed__
))
{
#pragma pack(push,1)
typedef
struct
{
u16
cellNum
;
u16
cellBody
;
u16
cellFree
;
u16
nFree
;
}
SPageHdr
;
typedef
struct
__attribute__
((
__packed__
))
{
typedef
struct
{
u16
szCell
;
u16
nxOffset
;
}
SFreeCell
;
#pragma pack(pop)
// cellNum
static
inline
int
getPageCellNum
(
SPage
*
pPage
)
{
return
((
SPageHdr
*
)(
pPage
->
pPageHdr
))[
0
].
cellNum
;
}
...
...
@@ -517,17 +520,19 @@ SPageMethods pageMethods = {
setPageFreeCellInfo
// setFreeCellInfo
};
typedef
struct
__attribute__
((
__packed__
))
{
#pragma pack(push,1)
typedef
struct
{
u8
cellNum
[
3
];
u8
cellBody
[
3
];
u8
cellFree
[
3
];
u8
nFree
[
3
];
}
SPageHdrL
;
typedef
struct
__attribute__
((
__packed__
))
{
typedef
struct
{
u8
szCell
[
3
];
u8
nxOffset
[
3
];
}
SFreeCellL
;
#pragma pack(pop)
// cellNum
static
inline
int
getLPageCellNum
(
SPage
*
pPage
)
{
return
TDB_GET_U24
(((
SPageHdrL
*
)(
pPage
->
pPageHdr
))[
0
].
cellNum
);
}
...
...
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
fc245216
...
...
@@ -15,13 +15,15 @@
#include "tdbInt.h"
typedef
struct
__attribute__
((
__packed__
))
{
#pragma pack(push,1)
typedef
struct
{
u8
hdrString
[
16
];
u16
pageSize
;
SPgno
freePage
;
u32
nFreePages
;
u8
reserved
[
102
];
}
SFileHdr
;
#pragma pack(pop)
TDB_STATIC_ASSERT
(
sizeof
(
SFileHdr
)
==
128
,
"Size of file header is not correct"
);
...
...
source/libs/tdb/src/inc/tdbPage.h
浏览文件 @
fc245216
...
...
@@ -47,10 +47,13 @@ typedef struct {
void
(
*
setFreeCellInfo
)(
SCell
*
pCell
,
int
szCell
,
int
nxOffset
);
}
SPageMethods
;
#pragma pack(push,1)
// Page footer
typedef
struct
__attribute__
((
__packed__
))
{
typedef
struct
{
u8
cksm
[
4
];
}
SPageFtr
;
#pragma pack(pop)
struct
SPage
{
tdb_spinlock_t
lock
;
...
...
@@ -80,22 +83,23 @@ struct SPage {
#define P_LOCK_BUSY 1
#define P_LOCK_FAIL -1
static
inline
int
tdbTryLockPage
(
tdb_spinlock_t
*
pLock
)
{
int
ret
;
if
(
tdbSpinlockTrylock
(
pLock
)
==
0
)
{
ret
=
P_LOCK_SUCC
;
}
else
if
(
errno
==
EBUSY
)
{
ret
=
P_LOCK_BUSY
;
}
else
{
ret
=
P_LOCK_FAIL
;
}
return
ret
;
}
#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0)
#define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock))
#define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock))
#define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock))
#define TDB_TRY_LOCK_PAGE(pPage) \
({ \
int ret; \
if (tdbSpinlockTrylock(&((pPage)->lock)) == 0) { \
ret = P_LOCK_SUCC; \
} else if (errno == EBUSY) { \
ret = P_LOCK_BUSY; \
} else { \
ret = P_LOCK_FAIL; \
} \
ret; \
})
#define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock))
// APIs
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
...
...
source/libs/tdb/src/inc/tdbUtil.h
浏览文件 @
fc245216
...
...
@@ -31,20 +31,20 @@ extern "C" {
int
tdbGnrtFileID
(
const
char
*
fname
,
uint8_t
*
fileid
,
bool
unique
);
int
tdbGetFileSize
(
tdb_fd_t
fd
,
int
szPage
,
SPgno
*
size
);
#define TDB_REALLOC(PTR, SIZE) \
({ \
void *nPtr; \
if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \
nPtr = tdbOsRealloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \
if (nPtr) { \
((int *)nPtr)[0] = (SIZE); \
nPtr = (char *)nPtr + sizeof(int); \
} \
} else { \
nPtr = (PTR); \
} \
nPtr; \
}
)
static
inline
void
*
tdbRealloc
(
void
*
ptr
,
size_t
size
)
{
void
*
nPtr
;
if
((
ptr
)
==
NULL
||
((
int
*
)(
ptr
))[
-
1
]
<
(
size
))
{
nPtr
=
tdbOsRealloc
((
ptr
)
?
(
char
*
)(
ptr
)
-
sizeof
(
int
)
:
NULL
,
(
size
)
+
sizeof
(
int
));
if
(
nPtr
)
{
((
int
*
)
nPtr
)[
0
]
=
(
size
);
nPtr
=
(
char
*
)
nPtr
+
sizeof
(
int
);
}
}
else
{
nPtr
=
(
ptr
);
}
return
nPtr
;
}
#define TDB_REALLOC(PTR, SIZE) tdbRealloc(PTR, SIZE
)
#define TDB_FREE(PTR) \
do { \
...
...
source/libs/tfs/src/tfs.c
浏览文件 @
fc245216
...
...
@@ -366,7 +366,7 @@ const STfsFile *tfsReaddir(STfsDir *pTfsDir) {
void
tfsClosedir
(
STfsDir
*
pTfsDir
)
{
if
(
pTfsDir
)
{
if
(
pTfsDir
->
pDir
!=
NULL
)
{
taosCloseDir
(
pTfsDir
->
pDir
);
taosCloseDir
(
&
pTfsDir
->
pDir
);
pTfsDir
->
pDir
=
NULL
;
}
taosMemoryFree
(
pTfsDir
);
...
...
@@ -455,7 +455,7 @@ static int32_t tfsFormatDir(char *idir, char *odir) {
}
char
tmp
[
PATH_MAX
]
=
{
0
};
if
(
realpath
(
wep
.
we_wordv
[
0
],
tmp
)
==
NULL
)
{
if
(
taosRealPath
(
wep
.
we_wordv
[
0
],
tmp
,
PATH_MAX
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
wordfree
(
&
wep
);
return
-
1
;
...
...
@@ -499,7 +499,7 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pTfsDir) {
char
adir
[
TMPNAME_LEN
*
2
]
=
"
\0
"
;
if
(
pTfsDir
->
pDir
!=
NULL
)
{
taosCloseDir
(
pTfsDir
->
pDir
);
taosCloseDir
(
&
pTfsDir
->
pDir
);
pTfsDir
->
pDir
=
NULL
;
}
...
...
source/libs/transport/test/rclient.c
浏览文件 @
fc245216
...
...
@@ -12,8 +12,6 @@
* 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/>.
*/
#include <sys/time.h>
#include <tdatablock.h>
#include "os.h"
#include "rpcLog.h"
...
...
source/libs/transport/test/syncClient.c
浏览文件 @
fc245216
...
...
@@ -12,8 +12,6 @@
* 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/>.
*/
#include <sys/time.h>
#include <tdatablock.h>
#include "os.h"
#include "rpcLog.h"
...
...
source/libs/transport/test/transportTests.cpp
浏览文件 @
fc245216
...
...
@@ -156,14 +156,14 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx
*
src
=
(
STransCtx
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STransCtx
));
transCtxInit
(
src
);
{
STransCtxVal
val1
=
{
.
val
=
NULL
,
.
clone
=
NULL
,
.
freeFunc
=
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
STransCtxVal
val1
=
{
NULL
,
NULL
,
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
val1
.
val
=
taosMemoryMalloc
(
12
);
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
{
STransCtxVal
val1
=
{
.
val
=
NULL
,
.
clone
=
NULL
,
.
freeFunc
=
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
STransCtxVal
val1
=
{
NULL
,
NULL
,
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
val1
.
val
=
taosMemoryMalloc
(
12
);
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
...
...
@@ -176,14 +176,14 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx
*
src
=
(
STransCtx
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STransCtx
));
transCtxInit
(
src
);
{
STransCtxVal
val1
=
{
.
val
=
NULL
,
.
clone
=
NULL
,
.
freeFunc
=
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
STransCtxVal
val1
=
{
NULL
,
NULL
,
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
val1
.
val
=
taosMemoryMalloc
(
12
);
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
{
STransCtxVal
val1
=
{
.
val
=
NULL
,
.
clone
=
NULL
,
.
freeFunc
=
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
STransCtxVal
val1
=
{
NULL
,
NULL
,
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
val1
.
val
=
taosMemoryMalloc
(
12
);
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
...
...
@@ -198,7 +198,7 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx
*
src
=
(
STransCtx
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STransCtx
));
transCtxInit
(
src
);
{
STransCtxVal
val1
=
{
.
val
=
NULL
,
.
clone
=
NULL
,
.
freeFunc
=
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
STransCtxVal
val1
=
{
NULL
,
NULL
,
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
val1
.
val
=
taosMemoryCalloc
(
1
,
11
);
memcpy
(
val1
.
val
,
val
.
c_str
(),
val
.
size
());
...
...
@@ -206,7 +206,7 @@ TEST_F(TransCtxEnv, mergeTest) {
key
++
;
}
{
STransCtxVal
val1
=
{
.
val
=
NULL
,
.
clone
=
NULL
,
.
freeFunc
=
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
STransCtxVal
val1
=
{
NULL
,
NULL
,
(
void
(
*
)(
const
void
*
))
taosMemoryFree
};
val1
.
val
=
taosMemoryCalloc
(
1
,
11
);
memcpy
(
val1
.
val
,
val
.
c_str
(),
val
.
size
());
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
fc245216
...
...
@@ -145,7 +145,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
}
}
taosCloseDir
(
pDir
);
taosCloseDir
(
&
pDir
);
regfree
(
&
logRegPattern
);
regfree
(
&
idxRegPattern
);
...
...
@@ -351,7 +351,7 @@ static int walFindCurMetaVer(SWal* pWal) {
break
;
}
}
taosCloseDir
(
pDir
);
taosCloseDir
(
&
pDir
);
regfree
(
&
walMetaRegexPattern
);
return
metaVer
;
}
...
...
source/os/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -6,7 +6,8 @@ target_include_directories(
PUBLIC
"
${
TD_SOURCE_DIR
}
/include"
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/util"
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/pthread"
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/gnuregex"
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/iconv"
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/msvcregex"
)
# iconv
find_path
(
IconvApiIncludes iconv.h PATHS
)
...
...
@@ -17,5 +18,14 @@ if(USE_TD_MEMORY)
add_definitions
(
-DUSE_TD_MEMORY
)
endif
()
target_link_libraries
(
os pthread
dl rt m
os pthread
)
if
(
NOT TD_WINDOWS
)
target_link_libraries
(
os dl m rt
)
else
()
target_link_libraries
(
os ws2_32 iconv msvcregex wcwidth winmm
)
endif
(
NOT TD_WINDOWS
)
source/os/src/osAtomic.c
浏览文件 @
fc245216
...
...
@@ -16,78 +16,101 @@
#define ALLOW_FORBID_FUNC
#include "os.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
// add
char
interlocked_add_fetch_8
(
char
volatile
*
ptr
,
char
val
)
{
int8_t
interlocked_add_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
return
_InterlockedExchangeAdd8
(
ptr
,
val
)
+
val
;
}
short
interlocked_add_fetch_16
(
short
volatile
*
ptr
,
shor
t
val
)
{
int16_t
interlocked_add_fetch_16
(
int16_t
volatile
*
ptr
,
int16_
t
val
)
{
return
_InterlockedExchangeAdd16
(
ptr
,
val
)
+
val
;
}
long
interlocked_add_fetch_32
(
long
volatile
*
ptr
,
long
val
)
{
int32_t
interlocked_add_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
return
_InterlockedExchangeAdd
(
ptr
,
val
)
+
val
;
}
__int64
interlocked_add_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
)
{
int64_t
interlocked_add_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
return
InterlockedExchangeAdd64
(
ptr
,
val
)
+
val
;
}
char
interlocked_and_fetch_8
(
char
volatile
*
ptr
,
char
val
)
{
void
*
interlocked_add_fetch_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)(
_InterlockedExchangeAdd
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)
val
)
+
(
int32_t
)
val
);
#else
return
(
void
*
)(
InterlockedExchangeAdd64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)
val
)
+
(
int64_t
)
val
);
#endif
}
int8_t
interlocked_and_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
return
_InterlockedAnd8
(
ptr
,
val
)
&
val
;
}
short
interlocked_and_fetch_16
(
short
volatile
*
ptr
,
shor
t
val
)
{
int16_t
interlocked_and_fetch_16
(
int16_t
volatile
*
ptr
,
int16_
t
val
)
{
return
_InterlockedAnd16
(
ptr
,
val
)
&
val
;
}
long
interlocked_and_fetch_32
(
long
volatile
*
ptr
,
long
val
)
{
int32_t
interlocked_and_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
return
_InterlockedAnd
(
ptr
,
val
)
&
val
;
}
__int64
interlocked_and_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
)
{
#ifndef _M_IX86
return
_InterlockedAnd64
(
ptr
,
val
)
&
val
;
#else
__int64
old
,
res
;
int64_t
interlocked_and_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#ifdef _TD_WINDOWS_32
int64_t
old
,
res
;
do
{
old
=
*
ptr
;
res
=
old
&
val
;
}
while
(
_InterlockedCompareExchange64
(
ptr
,
res
,
old
)
!=
old
);
return
res
;
#else
return
_InterlockedAnd64
(
ptr
,
val
)
&
val
;
#endif
}
__int64
interlocked_fetch_and_64
(
__int64
volatile
*
ptr
,
__int64
val
)
{
#ifdef _M_IX86
__int64
old
;
void
*
interlocked_and_fetch_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
interlocked_and_fetch_32
((
int32_t
volatile
*
)
ptr
,
(
int32_t
)
val
);
#else
return
(
void
*
)
interlocked_and_fetch_64
((
int64_t
volatile
*
)
ptr
,
(
int64_t
)
val
);
#endif
}
int64_t
interlocked_fetch_and_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#ifdef _TD_WINDOWS_32
int64_t
old
;
do
{
old
=
*
ptr
;
}
while
(
_InterlockedCompareExchange64
(
ptr
,
old
&
val
,
old
)
!=
old
);
return
old
;
#else
return
_InterlockedAnd64
((
__int64
volatile
*
)(
ptr
),
(
__int64
)(
val
));
return
_InterlockedAnd64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#endif
}
char
interlocked_or_fetch_8
(
char
volatile
*
ptr
,
char
val
)
{
void
*
interlocked_fetch_and_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
_InterlockedAnd
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#else
return
(
void
*
)
_InterlockedAnd64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#endif
}
int8_t
interlocked_or_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
return
_InterlockedOr8
(
ptr
,
val
)
|
val
;
}
short
interlocked_or_fetch_16
(
short
volatile
*
ptr
,
shor
t
val
)
{
int16_t
interlocked_or_fetch_16
(
int16_t
volatile
*
ptr
,
int16_
t
val
)
{
return
_InterlockedOr16
(
ptr
,
val
)
|
val
;
}
long
interlocked_or_fetch_32
(
long
volatile
*
ptr
,
long
val
)
{
int32_t
interlocked_or_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
return
_InterlockedOr
(
ptr
,
val
)
|
val
;
}
__int64
interlocked_or_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
)
{
#ifdef _
M_IX86
__int64
old
,
res
;
int64_t
interlocked_or_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#ifdef _
TD_WINDOWS_32
int64_t
old
,
res
;
do
{
old
=
*
ptr
;
res
=
old
|
val
;
...
...
@@ -98,33 +121,49 @@ __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) {
#endif
}
__int64
interlocked_fetch_or_64
(
__int64
volatile
*
ptr
,
__int64
val
)
{
#ifdef _M_IX86
__int64
old
;
void
*
interlocked_or_fetch_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
interlocked_or_fetch_32
((
int32_t
volatile
*
)
ptr
,
(
int32_t
)
val
);
#else
return
(
void
*
)
interlocked_or_fetch_64
((
int64_t
volatile
*
)
ptr
,
(
int64_t
)
val
);
#endif
}
int64_t
interlocked_fetch_or_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#ifdef _TD_WINDOWS_32
int64_t
old
;
do
{
old
=
*
ptr
;
}
while
(
_InterlockedCompareExchange64
(
ptr
,
old
|
val
,
old
)
!=
old
);
return
old
;
#else
return
_InterlockedOr64
((
__int64
volatile
*
)(
ptr
),
(
__int64
)(
val
));
return
_InterlockedOr64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#endif
}
void
*
interlocked_fetch_or_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
_InterlockedOr
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#else
return
(
void
*
)
interlocked_fetch_or_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#endif
}
char
interlocked_xor_fetch_8
(
char
volatile
*
ptr
,
char
val
)
{
int8_t
interlocked_xor_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
return
_InterlockedXor8
(
ptr
,
val
)
^
val
;
}
short
interlocked_xor_fetch_16
(
short
volatile
*
ptr
,
shor
t
val
)
{
int16_t
interlocked_xor_fetch_16
(
int16_t
volatile
*
ptr
,
int16_
t
val
)
{
return
_InterlockedXor16
(
ptr
,
val
)
^
val
;
}
long
interlocked_xor_fetch_32
(
long
volatile
*
ptr
,
long
val
)
{
int32_t
interlocked_xor_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
return
_InterlockedXor
(
ptr
,
val
)
^
val
;
}
__int64
interlocked_xor_fetch_64
(
__int64
volatile
*
ptr
,
__int64
val
)
{
#ifdef _
M_IX86
__int64
old
,
res
;
int64_t
interlocked_xor_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#ifdef _
TD_WINDOWS_32
int64_t
old
,
res
;
do
{
old
=
*
ptr
;
res
=
old
^
val
;
...
...
@@ -135,15 +174,62 @@ __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) {
#endif
}
__int64
interlocked_fetch_xor_64
(
__int64
volatile
*
ptr
,
__int64
val
)
{
#ifdef _M_IX86
__int64
old
;
void
*
interlocked_xor_fetch_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
interlocked_xor_fetch_32
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#else
return
(
void
*
)
interlocked_xor_fetch_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#endif
}
int64_t
interlocked_fetch_xor_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#ifdef _TD_WINDOWS_32
int64_t
old
;
do
{
old
=
*
ptr
;
}
while
(
_InterlockedCompareExchange64
(
ptr
,
old
^
val
,
old
)
!=
old
);
return
old
;
#else
return
_InterlockedXor64
((
__int64
volatile
*
)(
ptr
),
(
__int64
)(
val
));
return
_InterlockedXor64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#endif
}
void
*
interlocked_fetch_xor_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
_InterlockedXor
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#else
return
(
void
*
)
interlocked_fetch_xor_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#endif
}
int32_t
interlocked_sub_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
return
interlocked_add_fetch_32
(
ptr
,
-
val
);
}
int64_t
interlocked_sub_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
return
interlocked_add_fetch_64
(
ptr
,
-
val
);
}
void
*
interlocked_sub_fetch_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
interlocked_sub_fetch_32
((
int32_t
volatile
*
)
ptr
,
(
int32_t
)
val
);
#else
return
(
void
*
)
interlocked_add_fetch_64
((
int64_t
volatile
*
)
ptr
,
(
int64_t
)
val
);
#endif
}
int32_t
interlocked_fetch_sub_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
return
_InterlockedExchangeAdd
(
ptr
,
-
val
);
}
int64_t
interlocked_fetch_sub_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
return
_InterlockedExchangeAdd64
(
ptr
,
-
val
);
}
void
*
interlocked_fetch_sub_ptr
(
void
*
volatile
*
ptr
,
void
*
val
)
{
#ifdef _TD_WINDOWS_32
return
(
void
*
)
interlocked_fetch_sub_32
((
int32_t
volatile
*
)
ptr
,
(
int32_t
)
val
);
#else
return
(
void
*
)
interlocked_fetch_sub_64
((
int64_t
volatile
*
)
ptr
,
(
int64_t
)
val
);
#endif
}
...
...
@@ -189,7 +275,7 @@ int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val ) {
int8_t
atomic_load_8
(
int8_t
volatile
*
ptr
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
(
*
(
int8_t
volatile
*
)(
ptr
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
0
);
...
...
@@ -199,7 +285,7 @@ int8_t atomic_load_8(int8_t volatile *ptr) {
}
int16_t
atomic_load_16
(
int16_t
volatile
*
ptr
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
(
*
(
int16_t
volatile
*
)(
ptr
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
0
);
...
...
@@ -209,7 +295,7 @@ int16_t atomic_load_16(int16_t volatile *ptr) {
}
int32_t
atomic_load_32
(
int32_t
volatile
*
ptr
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
(
*
(
int32_t
volatile
*
)(
ptr
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
0
);
...
...
@@ -219,7 +305,7 @@ int32_t atomic_load_32(int32_t volatile *ptr) {
}
int64_t
atomic_load_64
(
int64_t
volatile
*
ptr
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
(
*
(
int64_t
volatile
*
)(
ptr
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
0
);
...
...
@@ -229,7 +315,7 @@ int64_t atomic_load_64(int64_t volatile *ptr) {
}
void
*
atomic_load_ptr
(
void
*
ptr
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
(
*
(
void
*
volatile
*
)(
ptr
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
0
);
...
...
@@ -239,7 +325,7 @@ void* atomic_load_ptr(void *ptr) {
}
void
atomic_store_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
((
*
(
int8_t
volatile
*
)(
ptr
))
=
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
(
*
(
ptr
)
=
(
val
));
...
...
@@ -249,7 +335,7 @@ void atomic_store_8(int8_t volatile *ptr, int8_t val) {
}
void
atomic_store_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
((
*
(
int16_t
volatile
*
)(
ptr
))
=
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
(
*
(
ptr
)
=
(
val
));
...
...
@@ -259,7 +345,7 @@ void atomic_store_16(int16_t volatile *ptr, int16_t val) {
}
void
atomic_store_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
((
*
(
int32_t
volatile
*
)(
ptr
))
=
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
(
*
(
ptr
)
=
(
val
));
...
...
@@ -269,7 +355,7 @@ void atomic_store_32(int32_t volatile *ptr, int32_t val) {
}
void
atomic_store_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
((
*
(
int64_t
volatile
*
)(
ptr
))
=
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
(
*
(
ptr
)
=
(
val
));
...
...
@@ -279,7 +365,7 @@ void atomic_store_64(int64_t volatile *ptr, int64_t val) {
}
void
atomic_store_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
((
*
(
void
*
volatile
*
)(
ptr
))
=
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
(
*
(
ptr
)
=
(
val
));
...
...
@@ -289,7 +375,7 @@ void atomic_store_ptr(void *ptr, void *val) {
}
int8_t
atomic_exchange_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchange8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
atomic_exchange_8_impl
((
int8_t
*
)
ptr
,
(
int8_t
)
val
);
...
...
@@ -299,7 +385,7 @@ int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_exchange_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchange16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
atomic_exchange_16_impl
((
int16_t
*
)
ptr
,
(
int16_t
)
val
);
...
...
@@ -309,7 +395,7 @@ int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_exchange_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchange
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
atomic_exchange_32_impl
((
int32_t
*
)
ptr
,
(
int32_t
)
val
);
...
...
@@ -319,7 +405,7 @@ int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_exchange_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchange64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
atomic_exchange_64_impl
((
int64_t
*
)
ptr
,
(
int64_t
)
val
);
...
...
@@ -329,7 +415,7 @@ int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val) {
}
void
*
atomic_exchange_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#ifdef _WIN64
return
_InterlockedExchangePointer
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#else
...
...
@@ -343,7 +429,7 @@ void* atomic_exchange_ptr(void *ptr, void *val) {
}
int8_t
atomic_val_compare_exchange_8
(
int8_t
volatile
*
ptr
,
int8_t
oldval
,
int8_t
newval
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedCompareExchange8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
newval
),
(
int8_t
)(
oldval
));
#elif defined(_TD_NINGSI_60)
return
__sync_val_compare_and_swap
(
ptr
,
oldval
,
newval
);
...
...
@@ -353,7 +439,7 @@ int8_t atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t
}
int16_t
atomic_val_compare_exchange_16
(
int16_t
volatile
*
ptr
,
int16_t
oldval
,
int16_t
newval
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedCompareExchange16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
newval
),
(
int16_t
)(
oldval
));
#elif defined(_TD_NINGSI_60)
return
__sync_val_compare_and_swap
(
ptr
,
oldval
,
newval
);
...
...
@@ -363,7 +449,7 @@ int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, in
}
int32_t
atomic_val_compare_exchange_32
(
int32_t
volatile
*
ptr
,
int32_t
oldval
,
int32_t
newval
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedCompareExchange
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
newval
),
(
int32_t
)(
oldval
));
#elif defined(_TD_NINGSI_60)
return
__sync_val_compare_and_swap
(
ptr
,
oldval
,
newval
);
...
...
@@ -373,7 +459,7 @@ int32_t atomic_val_compare_exchange_32(int32_t volatile *ptr, int32_t oldval, in
}
int64_t
atomic_val_compare_exchange_64
(
int64_t
volatile
*
ptr
,
int64_t
oldval
,
int64_t
newval
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedCompareExchange64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
newval
),
(
int64_t
)(
oldval
));
#elif defined(_TD_NINGSI_60)
return
__sync_val_compare_and_swap
(
ptr
,
oldval
,
newval
);
...
...
@@ -383,7 +469,7 @@ int64_t atomic_val_compare_exchange_64(int64_t volatile *ptr, int64_t oldval, in
}
void
*
atomic_val_compare_exchange_ptr
(
void
*
ptr
,
void
*
oldval
,
void
*
newval
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedCompareExchangePointer
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
newval
),
(
void
*
)(
oldval
));
#elif defined(_TD_NINGSI_60)
return
__sync_val_compare_and_swap
(
ptr
,
oldval
,
newval
);
...
...
@@ -393,7 +479,7 @@ void* atomic_val_compare_exchange_ptr(void *ptr, void *oldval, void *newval) {
}
int8_t
atomic_add_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_add_fetch_8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_add_and_fetch
((
ptr
),
(
val
));
...
...
@@ -403,7 +489,7 @@ int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_add_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_add_fetch_16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_add_and_fetch
((
ptr
),
(
val
));
...
...
@@ -413,7 +499,7 @@ int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_add_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_add_fetch_32
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_add_and_fetch
((
ptr
),
(
val
));
...
...
@@ -423,7 +509,7 @@ int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_add_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_add_fetch_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_add_and_fetch
((
ptr
),
(
val
));
...
...
@@ -432,18 +518,18 @@ int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val) {
#endif
}
void
*
atomic_add_fetch_ptr
(
void
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void
*
atomic_add_fetch_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
def WINDOWS
return
interlocked_add_fetch_ptr
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_add_and_fetch
((
ptr
),
(
val
));
#else
return
__atomic_add_fetch
((
void
**
)(
ptr
),
(
val
),
__ATOMIC_SEQ_CST
);
return
__atomic_add_fetch
((
void
**
)(
ptr
),
(
size_t
)(
val
),
__ATOMIC_SEQ_CST
);
#endif
}
int8_t
atomic_fetch_add_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchangeAdd8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
(
val
));
...
...
@@ -453,7 +539,7 @@ int8_t atomic_fetch_add_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_fetch_add_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchangeAdd16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
(
val
));
...
...
@@ -463,7 +549,7 @@ int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_fetch_add_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchangeAdd
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
(
val
));
...
...
@@ -473,7 +559,7 @@ int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_fetch_add_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchangeAdd64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
(
val
));
...
...
@@ -482,18 +568,18 @@ int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val) {
#endif
}
void
*
atomic_fetch_add_ptr
(
void
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
_InterlockedExchange
Addpt
r
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
void
*
atomic_fetch_add_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
def WINDOWS
return
_InterlockedExchange
Pointe
r
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_add
((
ptr
),
(
val
));
#else
return
__atomic_fetch_add
((
void
**
)(
ptr
),
(
val
),
__ATOMIC_SEQ_CST
);
return
__atomic_fetch_add
((
void
**
)(
ptr
),
(
size_t
)(
val
),
__ATOMIC_SEQ_CST
);
#endif
}
int8_t
atomic_sub_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_add_fetch_8
((
int8_t
volatile
*
)(
ptr
),
-
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_sub_and_fetch
((
ptr
),
(
val
));
...
...
@@ -503,7 +589,7 @@ int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_sub_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_add_fetch_16
((
int16_t
volatile
*
)(
ptr
),
-
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_sub_and_fetch
((
ptr
),
(
val
));
...
...
@@ -513,8 +599,8 @@ int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_sub_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
interlocked_
add_fetch_32
((
int32_t
volatile
*
)(
ptr
),
-
(
int32_t
)(
val
)
);
#if
def WINDOWS
return
interlocked_
sub_fetch_32
(
ptr
,
val
);
#elif defined(_TD_NINGSI_60)
return
__sync_sub_and_fetch
((
ptr
),
(
val
));
#else
...
...
@@ -523,8 +609,8 @@ int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_sub_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
interlocked_
add_fetch_64
((
int64_t
volatile
*
)(
ptr
),
-
(
int64_t
)(
val
)
);
#if
def WINDOWS
return
interlocked_
sub_fetch_64
(
ptr
,
val
);
#elif defined(_TD_NINGSI_60)
return
__sync_sub_and_fetch
((
ptr
),
(
val
));
#else
...
...
@@ -532,9 +618,9 @@ int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val) {
#endif
}
void
*
atomic_sub_fetch_ptr
(
void
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
interlocked_
add_fetch_ptr
((
void
*
volatile
*
)(
ptr
),
-
(
void
*
)(
val
)
);
void
*
atomic_sub_fetch_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
def WINDOWS
return
interlocked_
sub_fetch_ptr
(
ptr
,
val
);
#elif defined(_TD_NINGSI_60)
return
__sync_sub_and_fetch
((
ptr
),
(
val
));
#else
...
...
@@ -543,7 +629,7 @@ void* atomic_sub_fetch_ptr(void *ptr, int32_t val) {
}
int8_t
atomic_fetch_sub_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchangeAdd8
((
int8_t
volatile
*
)(
ptr
),
-
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_sub
((
ptr
),
(
val
));
...
...
@@ -553,7 +639,7 @@ int8_t atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_fetch_sub_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchangeAdd16
((
int16_t
volatile
*
)(
ptr
),
-
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_sub
((
ptr
),
(
val
));
...
...
@@ -563,17 +649,17 @@ int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_fetch_sub_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
_InterlockedExchangeAdd
((
int32_t
volatile
*
)(
ptr
),
-
(
int32_t
)(
val
)
);
#if
def WINDOWS
return
interlocked_fetch_sub_32
(
ptr
,
val
);
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_sub
(
(
ptr
),
(
val
)
);
return
__sync_fetch_and_sub
(
ptr
,
val
);
#else
return
__atomic_fetch_sub
((
ptr
),
(
val
),
__ATOMIC_SEQ_CST
);
#endif
}
int64_t
atomic_fetch_sub_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedExchangeAdd64
((
int64_t
volatile
*
)(
ptr
),
-
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_sub
((
ptr
),
(
val
));
...
...
@@ -582,9 +668,9 @@ int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val) {
#endif
}
void
*
atomic_fetch_sub_ptr
(
void
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
_InterlockedExchangeAddptr
((
void
*
volatile
*
)(
ptr
),
-
(
void
*
)(
val
)
);
void
*
atomic_fetch_sub_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
def WINDOWS
return
interlocked_fetch_sub_ptr
(
ptr
,
val
);
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_sub
((
ptr
),
(
val
));
#else
...
...
@@ -593,7 +679,7 @@ void* atomic_fetch_sub_ptr(void *ptr, int32_t val) {
}
int8_t
atomic_and_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_and_fetch_8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_and_and_fetch
((
ptr
),
(
val
));
...
...
@@ -603,7 +689,7 @@ int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_and_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_and_fetch_16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_and_and_fetch
((
ptr
),
(
val
));
...
...
@@ -613,7 +699,7 @@ int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_and_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_and_fetch_32
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_and_and_fetch
((
ptr
),
(
val
));
...
...
@@ -623,7 +709,7 @@ int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_and_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_and_fetch_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_and_and_fetch
((
ptr
),
(
val
));
...
...
@@ -633,7 +719,7 @@ int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val) {
}
void
*
atomic_and_fetch_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_and_fetch_ptr
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_and_and_fetch
((
ptr
),
(
val
));
...
...
@@ -643,7 +729,7 @@ void* atomic_and_fetch_ptr(void *ptr, void *val) {
}
int8_t
atomic_fetch_and_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedAnd8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_and
((
ptr
),
(
val
));
...
...
@@ -653,7 +739,7 @@ int8_t atomic_fetch_and_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_fetch_and_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedAnd16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_and
((
ptr
),
(
val
));
...
...
@@ -663,7 +749,7 @@ int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_fetch_and_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedAnd
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_and
((
ptr
),
(
val
));
...
...
@@ -673,7 +759,7 @@ int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_fetch_and_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_fetch_and_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_and
((
ptr
),
(
val
));
...
...
@@ -683,7 +769,7 @@ int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val) {
}
void
*
atomic_fetch_and_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_fetch_and_ptr
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_and
((
ptr
),
(
val
));
...
...
@@ -693,7 +779,7 @@ void* atomic_fetch_and_ptr(void *ptr, void *val) {
}
int8_t
atomic_or_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_or_fetch_8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_or_and_fetch
((
ptr
),
(
val
));
...
...
@@ -703,7 +789,7 @@ int8_t atomic_or_fetch_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_or_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_or_fetch_16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_or_and_fetch
((
ptr
),
(
val
));
...
...
@@ -713,7 +799,7 @@ int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_or_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_or_fetch_32
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_or_and_fetch
((
ptr
),
(
val
));
...
...
@@ -723,7 +809,7 @@ int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_or_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_or_fetch_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_or_and_fetch
((
ptr
),
(
val
));
...
...
@@ -733,7 +819,7 @@ int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val) {
}
void
*
atomic_or_fetch_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_or_fetch_ptr
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_or_and_fetch
((
ptr
),
(
val
));
...
...
@@ -743,7 +829,7 @@ void* atomic_or_fetch_ptr(void *ptr, void *val) {
}
int8_t
atomic_fetch_or_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedOr8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_or
((
ptr
),
(
val
));
...
...
@@ -753,7 +839,7 @@ int8_t atomic_fetch_or_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_fetch_or_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedOr16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_or
((
ptr
),
(
val
));
...
...
@@ -763,7 +849,7 @@ int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_fetch_or_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedOr
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_or
((
ptr
),
(
val
));
...
...
@@ -773,7 +859,7 @@ int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_fetch_or_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_fetch_or_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_or
((
ptr
),
(
val
));
...
...
@@ -783,7 +869,7 @@ int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val) {
}
void
*
atomic_fetch_or_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_fetch_or_ptr
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_or
((
ptr
),
(
val
));
...
...
@@ -793,7 +879,7 @@ void* atomic_fetch_or_ptr(void *ptr, void *val) {
}
int8_t
atomic_xor_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_xor_fetch_8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_xor_and_fetch
((
ptr
),
(
val
));
...
...
@@ -803,7 +889,7 @@ int8_t atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_xor_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_xor_fetch_16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_xor_and_fetch
((
ptr
),
(
val
));
...
...
@@ -813,7 +899,7 @@ int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_xor_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_xor_fetch_32
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_xor_and_fetch
((
ptr
),
(
val
));
...
...
@@ -823,7 +909,7 @@ int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_xor_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_xor_fetch_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_xor_and_fetch
((
ptr
),
(
val
));
...
...
@@ -833,7 +919,7 @@ int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val) {
}
void
*
atomic_xor_fetch_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_xor_fetch_ptr
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_xor_and_fetch
((
ptr
),
(
val
));
...
...
@@ -843,7 +929,7 @@ void* atomic_xor_fetch_ptr(void *ptr, void *val) {
}
int8_t
atomic_fetch_xor_8
(
int8_t
volatile
*
ptr
,
int8_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedXor8
((
int8_t
volatile
*
)(
ptr
),
(
int8_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_xor
((
ptr
),
(
val
));
...
...
@@ -853,7 +939,7 @@ int8_t atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val) {
}
int16_t
atomic_fetch_xor_16
(
int16_t
volatile
*
ptr
,
int16_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedXor16
((
int16_t
volatile
*
)(
ptr
),
(
int16_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_xor
((
ptr
),
(
val
));
...
...
@@ -863,7 +949,7 @@ int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val) {
}
int32_t
atomic_fetch_xor_32
(
int32_t
volatile
*
ptr
,
int32_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
_InterlockedXor
((
int32_t
volatile
*
)(
ptr
),
(
int32_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_xor
((
ptr
),
(
val
));
...
...
@@ -873,7 +959,7 @@ int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val) {
}
int64_t
atomic_fetch_xor_64
(
int64_t
volatile
*
ptr
,
int64_t
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_fetch_xor_64
((
int64_t
volatile
*
)(
ptr
),
(
int64_t
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_xor
((
ptr
),
(
val
));
...
...
@@ -883,7 +969,7 @@ int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val) {
}
void
*
atomic_fetch_xor_ptr
(
void
*
ptr
,
void
*
val
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
interlocked_fetch_xor_ptr
((
void
*
volatile
*
)(
ptr
),
(
void
*
)(
val
));
#elif defined(_TD_NINGSI_60)
return
__sync_fetch_and_xor
((
ptr
),
(
val
));
...
...
source/os/src/osDir.c
浏览文件 @
fc245216
...
...
@@ -17,19 +17,40 @@
#define ALLOW_FORBID_FUNC
#include "os.h"
#include "osString.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
/*
* windows implementation
*/
#ifdef WINDOWS
#include <windows.h>
typedef
struct
TdDirEntry
{
WIN32_FIND_DATA
findFileData
;
}
TdDirEntry
;
typedef
struct
TdDir
{
TdDirEntry
dirEntry
;
HANDLE
hFind
;
}
TdDir
;
int
wordexp
(
char
*
words
,
wordexp_t
*
pwordexp
,
int
flags
)
{
pwordexp
->
we_offs
=
0
;
pwordexp
->
we_wordc
=
1
;
pwordexp
->
we_wordv
[
0
]
=
pwordexp
->
wordPos
;
memset
(
pwordexp
->
wordPos
,
0
,
1025
);
if
(
_fullpath
(
pwordexp
->
wordPos
,
words
,
1024
)
==
NULL
)
{
pwordexp
->
we_wordv
[
0
]
=
words
;
printf
(
"failed to parse relative path:%s to abs path"
,
words
);
return
-
1
;
}
printf
(
"parse relative path:%s to abs path:%s"
,
words
,
pwordexp
->
wordPos
);
return
0
;
}
// todo
void
wordfree
(
wordexp_t
*
pwordexp
)
{}
#else
/*
* linux implementation
*/
#include <dirent.h>
#include <fcntl.h>
...
...
@@ -39,19 +60,21 @@
typedef
struct
dirent
dirent
;
typedef
struct
DIR
TdDir
;
typedef
struct
dirent
TdDirent
;
typedef
struct
dirent
TdDirEntry
;
#endif
void
taosRemoveDir
(
const
char
*
dirname
)
{
DIR
*
dir
=
opend
ir
(
dirname
);
if
(
d
ir
==
NULL
)
return
;
TdDirPtr
pDir
=
taosOpenD
ir
(
dirname
);
if
(
pD
ir
==
NULL
)
return
;
struct
dirent
*
de
=
NULL
;
while
((
de
=
readdir
(
d
ir
))
!=
NULL
)
{
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
continue
;
TdDirEntryPtr
de
=
NULL
;
while
((
de
=
taosReadDir
(
pD
ir
))
!=
NULL
)
{
if
(
strcmp
(
taosGetDirEntryName
(
de
),
"."
)
==
0
||
strcmp
(
taosGetDirEntryName
(
de
)
,
".."
)
==
0
)
continue
;
char
filename
[
1024
];
snprintf
(
filename
,
sizeof
(
filename
),
"%s/%s"
,
dirname
,
de
->
d_name
);
if
(
de
->
d_type
&
DT_DIR
)
{
snprintf
(
filename
,
sizeof
(
filename
),
"%s/%s"
,
dirname
,
taosGetDirEntryName
(
de
)
);
if
(
taosDirEntryIsDir
(
de
)
)
{
taosRemoveDir
(
filename
);
}
else
{
(
void
)
taosRemoveFile
(
filename
);
...
...
@@ -59,13 +82,14 @@ void taosRemoveDir(const char *dirname) {
}
}
closedir
(
d
ir
);
taosCloseDir
(
&
pD
ir
);
rmdir
(
dirname
);
//printf("dir:%s is removed\n", dirname);
return
;
}
bool
taosDirExist
(
char
*
dirname
)
{
return
taosCheckExistFile
(
dirname
);
}
bool
taosDirExist
(
c
onst
c
har
*
dirname
)
{
return
taosCheckExistFile
(
dirname
);
}
int32_t
taosMkDir
(
const
char
*
dirname
)
{
int32_t
code
=
mkdir
(
dirname
,
0755
);
...
...
@@ -118,18 +142,18 @@ int32_t taosMulMkDir(const char *dirname) {
}
void
taosRemoveOldFiles
(
const
char
*
dirname
,
int32_t
keepDays
)
{
DIR
*
dir
=
opend
ir
(
dirname
);
if
(
d
ir
==
NULL
)
return
;
TdDirPtr
pDir
=
taosOpenD
ir
(
dirname
);
if
(
pD
ir
==
NULL
)
return
;
int64_t
sec
=
taosGetTimestampSec
();
struct
dirent
*
de
=
NULL
;
int64_t
sec
=
taosGetTimestampSec
();
TdDirEntryPtr
de
=
NULL
;
while
((
de
=
readdir
(
d
ir
))
!=
NULL
)
{
if
(
strcmp
(
de
->
d_name
,
"."
)
==
0
||
strcmp
(
de
->
d_name
,
".."
)
==
0
)
continue
;
while
((
de
=
taosReadDir
(
pD
ir
))
!=
NULL
)
{
if
(
strcmp
(
taosGetDirEntryName
(
de
),
"."
)
==
0
||
strcmp
(
taosGetDirEntryName
(
de
)
,
".."
)
==
0
)
continue
;
char
filename
[
1024
];
snprintf
(
filename
,
sizeof
(
filename
),
"%s/%s"
,
dirname
,
de
->
d_name
);
if
(
de
->
d_type
&
DT_DIR
)
{
snprintf
(
filename
,
sizeof
(
filename
),
"%s/%s"
,
dirname
,
taosGetDirEntryName
(
de
)
);
if
(
taosDirEntryIsDir
(
de
)
)
{
continue
;
}
else
{
int32_t
len
=
(
int32_t
)
strlen
(
filename
);
...
...
@@ -156,7 +180,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
}
}
closedir
(
d
ir
);
taosCloseDir
(
&
pD
ir
);
rmdir
(
dirname
);
}
...
...
@@ -177,65 +201,131 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
return
0
;
}
int32_t
taosRealPath
(
char
*
dirname
,
int32_t
maxlen
)
{
int32_t
taosRealPath
(
char
*
dirname
,
char
*
realPath
,
int32_t
maxlen
)
{
char
tmp
[
PATH_MAX
]
=
{
0
};
#ifdef WINDOWS
if
(
_fullpath
(
dirname
,
tmp
,
maxlen
)
!=
NULL
)
{
#else
if
(
realpath
(
dirname
,
tmp
)
!=
NULL
)
{
strncpy
(
dirname
,
tmp
,
maxlen
);
#endif
if
(
realPath
==
NULL
)
{
strncpy
(
dirname
,
tmp
,
maxlen
);
}
else
{
strncpy
(
realPath
,
tmp
,
maxlen
);
}
return
0
;
}
return
0
;
return
-
1
;
}
bool
taosIsDir
(
const
char
*
dirname
)
{
DIR
*
dir
=
opend
ir
(
dirname
);
if
(
d
ir
!=
NULL
)
{
closedir
(
d
ir
);
TdDirPtr
pDir
=
taosOpenD
ir
(
dirname
);
if
(
pD
ir
!=
NULL
)
{
taosCloseDir
(
&
pD
ir
);
return
true
;
}
return
false
;
}
char
*
taosDirName
(
char
*
name
)
{
#ifdef WINDOWS
char
Drive1
[
MAX_PATH
],
Dir1
[
MAX_PATH
];
_splitpath
(
name
,
Drive1
,
Dir1
,
NULL
,
NULL
);
size_t
dirNameLen
=
strlen
(
Drive1
)
+
strlen
(
Dir1
);
if
(
dirNameLen
>
0
)
{
name
[
dirNameLen
]
=
0
;
}
return
name
;
#else
return
dirname
(
name
);
#endif
}
char
*
taosDirEntryBaseName
(
char
*
name
)
{
return
basename
(
name
);
#ifdef WINDOWS
char
Filename1
[
MAX_PATH
],
Ext1
[
MAX_PATH
];
_splitpath
(
name
,
NULL
,
NULL
,
Filename1
,
Ext1
);
return
name
+
(
strlen
(
name
)
-
strlen
(
Filename1
)
-
strlen
(
Ext1
));
#else
return
(
char
*
)
basename
(
name
);
#endif
}
TdDirPtr
taosOpenDir
(
const
char
*
dirname
)
{
if
(
dirname
==
NULL
)
{
return
NULL
;
}
#ifdef WINDOWS
char
szFind
[
MAX_PATH
];
//这是要找的
HANDLE
hFind
;
TdDirPtr
pDir
=
taosMemoryMalloc
(
sizeof
(
TdDir
));
strcpy
(
szFind
,
dirname
);
strcat
(
szFind
,
"
\\
*.*"
);
//利用通配符找这个目录下的所以文件,包括目录
pDir
->
hFind
=
FindFirstFile
(
szFind
,
&
(
pDir
->
dirEntry
.
findFileData
));
if
(
INVALID_HANDLE_VALUE
==
pDir
->
hFind
)
{
taosMemoryFree
(
pDir
);
return
NULL
;
}
return
pDir
;
#else
return
(
TdDirPtr
)
opendir
(
dirname
);
#endif
}
TdDirEntryPtr
taosReadDir
(
TdDirPtr
pDir
)
{
if
(
pDir
==
NULL
)
{
return
NULL
;
}
#ifdef WINDOWS
if
(
!
FindNextFile
(
pDir
->
hFind
,
&
(
pDir
->
dirEntry
.
findFileData
)))
{
return
NULL
;
}
return
(
TdDirEntryPtr
)
&
(
pDir
->
dirEntry
.
findFileData
);
#else
return
(
TdDirEntryPtr
)
readdir
((
DIR
*
)
pDir
);
#endif
}
bool
taosDirEntryIsDir
(
TdDirEntryPtr
pDirEntry
)
{
if
(
pDirEntry
==
NULL
)
{
return
false
;
}
#ifdef WINDOWS
return
(
pDirEntry
->
findFileData
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
!=
0
;
#else
return
(((
dirent
*
)
pDirEntry
)
->
d_type
&
DT_DIR
)
!=
0
;
#endif
}
char
*
taosGetDirEntryName
(
TdDirEntryPtr
pDirEntry
)
{
if
(
pDirEntry
==
NULL
)
{
return
NULL
;
}
#ifdef WINDOWS
return
pDirEntry
->
findFileData
.
cFileName
;
#else
return
((
dirent
*
)
pDirEntry
)
->
d_name
;
#endif
}
int32_t
taosCloseDir
(
TdDirPtr
pDir
)
{
if
(
pDir
==
NULL
)
{
int32_t
taosCloseDir
(
TdDirPtr
*
p
pDir
)
{
if
(
p
pDir
==
NULL
||
*
pp
Dir
==
NULL
)
{
return
-
1
;
}
return
closedir
((
DIR
*
)
pDir
);
}
#ifdef WINDOWS
FindClose
((
*
ppDir
)
->
hFind
);
taosMemoryFree
(
*
ppDir
);
*
ppDir
=
NULL
;
return
0
;
#else
closedir
((
DIR
*
)
*
ppDir
);
*
ppDir
=
NULL
;
return
0
;
#endif
}
source/os/src/osEnv.c
浏览文件 @
fc245216
...
...
@@ -16,8 +16,6 @@
#define _DEFAULT_SOURCE
#include "osEnv.h"
extern
void
taosWinSocketInit
();
char
configDir
[
PATH_MAX
]
=
{
0
};
char
tsDataDir
[
PATH_MAX
]
=
{
0
};
char
tsLogDir
[
PATH_MAX
]
=
{
0
};
...
...
@@ -51,7 +49,7 @@ void osDefaultInit() {
tsNumOfCores
=
2
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
taosWinSocketInit
();
const
char
*
tmpDir
=
getenv
(
"tmp"
);
...
...
source/os/src/osFile.c
浏览文件 @
fc245216
...
...
@@ -16,8 +16,11 @@
#include "os.h"
#include "osSemaphore.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#include <io.h>
#define F_OK 0
#define W_OK 2
#define R_OK 4
#if defined(_MSDOS)
#define open _open
...
...
@@ -33,6 +36,8 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
#endif
/* defined(_UTF8_SOURCE) */
#endif
/* defined(_WIN32) */
#define _SEND_FILE_STEP_ 1000
#else
#include <fcntl.h>
#include <sys/file.h>
...
...
@@ -66,7 +71,7 @@ typedef struct TdFile {
#define FILE_WITH_LOCK 1
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
char
tmpPath
[
PATH_MAX
];
...
...
@@ -117,7 +122,7 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
}
int64_t
taosCopyFile
(
const
char
*
from
,
const
char
*
to
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
char
buffer
[
4096
];
...
...
@@ -160,7 +165,7 @@ _err:
int32_t
taosRemoveFile
(
const
char
*
path
)
{
return
remove
(
path
);
}
int32_t
taosRenameFile
(
const
char
*
oldName
,
const
char
*
newName
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
int32_t
code
=
MoveFileEx
(
oldName
,
newName
,
MOVEFILE_REPLACE_EXISTING
|
MOVEFILE_COPY_ALLOWED
);
if
(
code
<
0
)
{
// printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
...
...
@@ -178,7 +183,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
}
int32_t
taosStatFile
(
const
char
*
path
,
int64_t
*
size
,
int32_t
*
mtime
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
struct
stat
fileStat
;
...
...
@@ -199,7 +204,7 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
#endif
}
int32_t
taosDevInoFile
(
const
char
*
path
,
int64_t
*
stDev
,
int64_t
*
stIno
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
struct
stat
fileStat
;
...
...
@@ -223,7 +228,7 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) {
void
autoDelFileListAdd
(
const
char
*
path
)
{
return
;
}
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
NULL
;
#else
int
fd
=
-
1
;
...
...
@@ -285,7 +290,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
}
int64_t
taosCloseFile
(
TdFilePtr
*
ppFile
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
)
{
...
...
@@ -365,8 +370,15 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
#if FILE_WITH_LOCK
taosThreadRwlockRdlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
#ifdef WINDOWS
size_t
pos
=
lseek
(
pFile
->
fd
,
0
,
SEEK_CUR
);
lseek
(
pFile
->
fd
,
(
long
)
offset
,
SEEK_SET
);
int64_t
ret
=
read
(
pFile
->
fd
,
buf
,
count
);
lseek
(
pFile
->
fd
,
pos
,
SEEK_SET
);
#else
int64_t
ret
=
pread
(
pFile
->
fd
,
buf
,
count
,
offset
);
#endif
#if FILE_WITH_LOCK
taosThreadRwlockUnlock
(
&
(
pFile
->
rwlock
));
#endif
...
...
@@ -423,7 +435,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
}
int32_t
taosFStatFile
(
TdFilePtr
pFile
,
int64_t
*
size
,
int32_t
*
mtime
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
if
(
pFile
==
NULL
)
{
...
...
@@ -450,7 +462,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
}
int32_t
taosLockFile
(
TdFilePtr
pFile
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
if
(
pFile
==
NULL
)
{
...
...
@@ -463,7 +475,7 @@ int32_t taosLockFile(TdFilePtr pFile) {
}
int32_t
taosUnLockFile
(
TdFilePtr
pFile
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
if
(
pFile
==
NULL
)
{
...
...
@@ -476,10 +488,10 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
}
int32_t
taosFtruncateFile
(
TdFilePtr
pFile
,
int64_t
l_size
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
if
(
pFile
->
fd
<
0
)
{
errno
=
EBADF
;
uError
(
"%s
\n
"
,
"fd arg was negative"
);
printf
(
"%s
\n
"
,
"fd arg was negative"
);
return
-
1
;
}
...
...
@@ -489,7 +501,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
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
"
);
printf
(
"SetFilePointerEx Error getting current position in file.
\n
"
);
return
-
1
;
}
...
...
@@ -498,7 +510,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
BOOL
cur2
=
SetFilePointerEx
(
h
,
li_size
,
NULL
,
FILE_BEGIN
);
if
(
cur2
==
0
)
{
int
error
=
GetLastError
();
uError
(
"SetFilePointerEx GetLastError is: %d
\n
"
,
error
);
printf
(
"SetFilePointerEx GetLastError is: %d
\n
"
,
error
);
switch
(
error
)
{
case
ERROR_INVALID_HANDLE
:
errno
=
EBADF
;
...
...
@@ -512,7 +524,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
if
(
!
SetEndOfFile
(
h
))
{
int
error
=
GetLastError
();
uError
(
"SetEndOfFile GetLastError is:%d"
,
error
);
printf
(
"SetEndOfFile GetLastError is:%d"
,
error
);
switch
(
error
)
{
case
ERROR_INVALID_HANDLE
:
errno
=
EBADF
;
...
...
@@ -536,10 +548,10 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
}
int32_t
taosFsyncFile
(
TdFilePtr
pFile
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
if
(
pFile
->
fd
<
0
)
{
errno
=
EBADF
;
uError
(
"%s
\n
"
,
"fd arg was negative"
);
printf
(
"%s
\n
"
,
"fd arg was negative"
);
return
-
1
;
}
...
...
@@ -558,84 +570,51 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
#endif
}
#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
;
}
int64_t
taosFSendFile
(
TdFilePtr
pFileOut
,
TdFilePtr
pFileIn
,
int64_t
*
offset
,
int64_t
size
)
{
if
(
pFileOut
==
NULL
||
pFileIn
==
NULL
)
{
return
0
;
}
assert
(
pFileIn
->
fd
>=
0
&&
pFileOut
->
fd
>=
0
);
return
writeLen
;
}
int64_t
taosSendFile
(
SocketFd
dfd
,
FileFd
sfd
,
int64_t
*
offset
,
int64_t
count
)
{
if
(
offset
!=
NULL
)
lseek
(
sfd
,
(
int32_t
)(
*
offset
),
0
);
#ifdef WINDOWS
lseek
(
pFileIn
->
fd
,
(
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_
);
for
(
int64_t
len
=
0
;
len
<
(
size
-
_SEND_FILE_STEP_
);
len
+=
_SEND_FILE_STEP_
)
{
size_t
rlen
=
read
(
pFileIn
->
fd
,
(
void
*
)
buffer
,
_SEND_FILE_STEP_
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
if
(
rlen
<
_SEND_FILE_STEP_
)
{
taosWriteSocket
(
dfd
,
buffer
,
rlen
);
write
(
pFileOut
->
fd
,
(
void
*
)
buffer
,
(
uint32_t
)
rlen
);
return
(
int64_t
)(
writeLen
+
rlen
);
}
else
{
taosWriteSocket
(
dfd
,
buffer
,
_SEND_FILE_STEP_
);
write
(
pFileOut
->
fd
,
(
void
*
)
buffer
,
_SEND_FILE_STEP_
);
writeLen
+=
_SEND_FILE_STEP_
;
}
}
int64_t
remain
=
count
-
writeLen
;
int64_t
remain
=
size
-
writeLen
;
if
(
remain
>
0
)
{
int32_t
rlen
=
read
(
sfd
,
buffer
,
(
int32
_t
)
remain
);
size_t
rlen
=
read
(
pFileIn
->
fd
,
(
void
*
)
buffer
,
(
size
_t
)
remain
);
if
(
rlen
<=
0
)
{
return
writeLen
;
}
else
{
taosWriteSocket
(
sfd
,
buffer
,
(
int32_t
)
remain
);
write
(
pFileOut
->
fd
,
(
void
*
)
buffer
,
(
u
int32_t
)
remain
);
writeLen
+=
remain
;
}
}
return
writeLen
;
}
#elif defined(_TD_DARWIN_64)
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
;
off_t
len
=
size
;
while
(
len
>
0
)
{
char
buf
[
1024
*
16
];
off_t
n
=
sizeof
(
buf
);
...
...
@@ -651,64 +630,10 @@ int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t co
}
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
;
}
return
size
-
len
;
#else
// int64_t taosSendFile(int fdDst, TdFilePtr pFileSrc, int64_t *offset, int64_t size) {
// if (pFileSrc == NULL) {
// return 0;
// }
// assert(pFileSrc->fd >= 0);
// int64_t leftbytes = size;
// int64_t sentbytes;
// while (leftbytes > 0) {
// sentbytes = sendfile(fdDst, pFileSrc->fd, offset, leftbytes);
// if (sentbytes == -1) {
// if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
// continue;
// } else {
// return -1;
// }
// } else if (sentbytes == 0) {
// return (int64_t)(size - leftbytes);
// }
// leftbytes -= sentbytes;
// }
// return size;
// }
int64_t
taosFSendFile
(
TdFilePtr
pFileOut
,
TdFilePtr
pFileIn
,
int64_t
*
offset
,
int64_t
size
)
{
if
(
pFileOut
==
NULL
||
pFileIn
==
NULL
)
{
return
0
;
}
assert
(
pFileIn
->
fd
>=
0
&&
pFileOut
->
fd
>=
0
);
int64_t
leftbytes
=
size
;
int64_t
sentbytes
;
...
...
@@ -728,9 +653,8 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
}
return
size
;
}
#endif
}
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...)
{
if
(
pFile
==
NULL
)
{
...
...
@@ -745,22 +669,10 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
fflush
(
pFile
->
fp
);
}
#if !defined(WINDOWS)
void
*
taosMmapReadOnlyFile
(
TdFilePtr
pFile
,
int64_t
length
)
{
if
(
pFile
==
NULL
)
{
return
NULL
;
}
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
void
*
ptr
=
mmap
(
NULL
,
length
,
PROT_READ
,
MAP_SHARED
,
pFile
->
fd
,
0
);
return
ptr
;
}
#endif
bool
taosValidFile
(
TdFilePtr
pFile
)
{
return
pFile
!=
NULL
;
}
int32_t
taosUmaskFile
(
int32_t
maskVal
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
return
umask
(
maskVal
);
...
...
@@ -769,16 +681,26 @@ int32_t taosUmaskFile(int32_t maskVal) {
int32_t
taosGetErrorFile
(
TdFilePtr
pFile
)
{
return
errno
;
}
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict
ptrBuf
)
{
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
||
ptrBuf
==
NULL
)
{
return
-
1
;
}
if
(
*
ptrBuf
!=
NULL
)
{
taosMemoryFreeClear
(
*
ptrBuf
);
}
assert
(
pFile
->
fp
!=
NULL
);
#ifdef WINDOWS
*
ptrBuf
=
taosMemoryMalloc
(
1024
);
if
(
*
ptrBuf
==
NULL
)
return
-
1
;
if
(
fgets
(
*
ptrBuf
,
1023
,
pFile
->
fp
)
==
NULL
)
{
taosMemoryFreeClear
(
*
ptrBuf
);
return
-
1
;
}
(
*
ptrBuf
)[
1023
]
=
0
;
return
strlen
(
*
ptrBuf
);
#else
size_t
len
=
0
;
return
getline
(
ptrBuf
,
&
len
,
pFile
->
fp
);
#endif
}
int32_t
taosEOFFile
(
TdFilePtr
pFile
)
{
if
(
pFile
==
NULL
)
{
...
...
@@ -789,8 +711,6 @@ int32_t taosEOFFile(TdFilePtr pFile) {
return
feof
(
pFile
->
fp
);
}
#if !defined(WINDOWS)
bool
taosCheckAccessFile
(
const
char
*
pathname
,
int32_t
tdFileAccessOptions
)
{
int
flags
=
0
;
...
...
@@ -805,10 +725,11 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
if
(
tdFileAccessOptions
&
TD_FILE_ACCESS_WRITE_OK
)
{
flags
|=
W_OK
;
}
#ifdef WINDOWS
return
_access
(
pathname
,
flags
)
==
0
;
#else
return
access
(
pathname
,
flags
)
==
0
;
#endif
}
bool
taosCheckExistFile
(
const
char
*
pathname
)
{
return
taosCheckAccessFile
(
pathname
,
TD_FILE_ACCESS_EXIST_OK
);
};
#endif // WINDOWS
source/os/src/osLocale.c
浏览文件 @
fc245216
...
...
@@ -17,7 +17,7 @@
#define _DEFAULT_SOURCE
#include "osLocale.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#if (_WIN64)
#include <iphlpapi.h>
#include <mswsock.h>
...
...
@@ -87,7 +87,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
}
void
taosGetSystemLocale
(
char
*
outLocale
,
char
*
outCharset
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
char
*
locale
=
setlocale
(
LC_CTYPE
,
"chs"
);
if
(
locale
!=
NULL
)
{
tstrncpy
(
outLocale
,
locale
,
TD_LOCALE_LEN
);
...
...
source/os/src/osLz4.c
浏览文件 @
fc245216
...
...
@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
/*
* windows implementation
...
...
source/os/src/osMemory.c
浏览文件 @
fc245216
...
...
@@ -35,7 +35,7 @@ typedef struct TdMemoryInfo {
// static TdMemoryInfoPtr GlobalMemoryPtr = NULL;
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#define tstrdup(str) _strdup(str)
#else
#define tstrdup(str) strdup(str)
...
...
@@ -181,7 +181,11 @@ int32_t taosMemorySize(void *ptr) {
assert
(
pTdMemoryInfo
->
symbol
==
TD_MEMORY_SYMBOL
);
return
pTdMemoryInfo
->
memorySize
;
#else
#ifdef WINDOWS
return
_msize
(
ptr
);
#else
return
malloc_usable_size
(
ptr
);
#endif
#endif
}
source/os/src/osProc.c
浏览文件 @
fc245216
...
...
@@ -20,6 +20,9 @@
char
*
tsProcPath
=
NULL
;
int32_t
taosNewProc
(
char
**
args
)
{
#ifdef WINDOWS
return
0
;
#else
int32_t
pid
=
fork
();
if
(
pid
==
0
)
{
args
[
0
]
=
tsProcPath
;
...
...
@@ -30,23 +33,36 @@ int32_t taosNewProc(char **args) {
}
else
{
return
pid
;
}
#endif
}
void
taosWaitProc
(
int32_t
pid
)
{
#ifdef WINDOWS
#else
int32_t
status
=
-
1
;
waitpid
(
pid
,
&
status
,
0
);
#endif
}
void
taosKillProc
(
int32_t
pid
)
{
kill
(
pid
,
SIGINT
);
}
void
taosKillProc
(
int32_t
pid
)
{
#ifdef WINDOWS
#else
kill
(
pid
,
SIGINT
);
#endif
}
bool
taosProcExist
(
int32_t
pid
)
{
#ifdef WINDOWS
return
false
;
#else
int32_t
p
=
getpgid
(
pid
);
return
p
>=
0
;
#endif
}
// the length of the new name must be less than the original name to take effect
void
taosSetProcName
(
int32_t
argc
,
char
**
argv
,
const
char
*
name
)
{
prctl
(
PR_SET_NAME
,
name
);
setThreadName
(
name
);
for
(
int32_t
i
=
0
;
i
<
argc
;
++
i
)
{
int32_t
len
=
strlen
(
argv
[
i
]);
...
...
source/os/src/osRand.c
浏览文件 @
fc245216
...
...
@@ -15,7 +15,9 @@
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#ifdef WINDOWS
#include "windows.h"
#include "wincrypt.h"
#else
#include <sys/file.h>
#include <unistd.h>
...
...
@@ -25,9 +27,25 @@ void taosSeedRand(uint32_t seed) { return srand(seed); }
uint32_t
taosRand
(
void
)
{
return
rand
();
}
uint32_t
taosRandR
(
uint32_t
*
pSeed
)
{
return
rand_r
(
pSeed
);
}
uint32_t
taosRandR
(
uint32_t
*
pSeed
)
{
#ifdef WINDOWS
return
rand_s
(
pSeed
);
#else
return
rand_r
(
pSeed
);
#endif
}
uint32_t
taosSafeRand
(
void
)
{
#ifdef WINDOWS
uint32_t
seed
;
HCRYPTPROV
hCryptProv
;
if
(
!
CryptAcquireContext
(
&
hCryptProv
,
NULL
,
NULL
,
PROV_RSA_FULL
,
0
))
return
seed
;
if
(
hCryptProv
!=
NULL
)
{
if
(
!
CryptGenRandom
(
hCryptProv
,
4
,
&
seed
))
return
seed
;
}
if
(
hCryptProv
!=
NULL
)
CryptReleaseContext
(
hCryptProv
,
0
);
return
seed
;
#else
TdFilePtr
pFile
;
int
seed
;
...
...
@@ -43,6 +61,7 @@ uint32_t taosSafeRand(void) {
}
return
(
uint32_t
)
seed
;
#endif
}
void
taosRandStr
(
char
*
str
,
int32_t
size
)
{
...
...
source/os/src/osSemaphore.c
浏览文件 @
fc245216
...
...
@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
/*
* windows implementation
...
...
source/os/src/osShm.c
浏览文件 @
fc245216
...
...
@@ -22,15 +22,20 @@
static
int32_t
shmids
[
MAX_SHMIDS
]
=
{
0
};
static
void
taosDeleteCreatedShms
()
{
#if defined(WINDOWS)
#else
for
(
int32_t
i
=
0
;
i
<
MAX_SHMIDS
;
++
i
)
{
int32_t
shmid
=
shmids
[
i
]
-
1
;
if
(
shmid
>=
0
)
{
shmctl
(
shmid
,
IPC_RMID
,
NULL
);
}
}
#endif
}
int32_t
taosCreateShm
(
SShm
*
pShm
,
int32_t
key
,
int32_t
shmsize
)
{
#if defined(WINDOWS)
#else
pShm
->
id
=
-
1
;
#if 1
...
...
@@ -64,10 +69,13 @@ int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) {
shmctl
(
pShm
->
id
,
IPC_RMID
,
NULL
);
#endif
#endif
return
0
;
}
void
taosDropShm
(
SShm
*
pShm
)
{
#if defined(WINDOWS)
#else
if
(
pShm
->
id
>=
0
)
{
if
(
pShm
->
ptr
!=
NULL
)
{
shmdt
(
pShm
->
ptr
);
...
...
@@ -77,14 +85,18 @@ void taosDropShm(SShm* pShm) {
pShm
->
id
=
-
1
;
pShm
->
size
=
0
;
pShm
->
ptr
=
NULL
;
#endif
}
int32_t
taosAttachShm
(
SShm
*
pShm
)
{
#if defined(WINDOWS)
#else
errno
=
0
;
void
*
ptr
=
shmat
(
pShm
->
id
,
NULL
,
0
);
if
(
errno
==
0
)
{
pShm
->
ptr
=
ptr
;
}
#endif
return
errno
;
}
source/os/src/osSignal.c
浏览文件 @
fc245216
...
...
@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
/*
* windows implementation
...
...
@@ -47,6 +47,8 @@ void taosDflSignal(int32_t signum) {
signal
(
signum
,
SIG_DFL
);
}
void
taosKillChildOnParentStopped
()
{
}
#else
/*
...
...
source/os/src/osSleep.c
浏览文件 @
fc245216
...
...
@@ -23,7 +23,7 @@
#endif
void
taosSsleep
(
int32_t
s
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
Sleep
(
1000
*
s
);
#else
sleep
(
s
);
...
...
@@ -31,7 +31,7 @@ void taosSsleep(int32_t s) {
}
void
taosMsleep
(
int32_t
ms
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
Sleep
(
ms
);
#else
usleep
(
ms
*
1000
);
...
...
@@ -39,8 +39,15 @@ void taosMsleep(int32_t ms) {
}
void
taosUsleep
(
int32_t
us
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
nanosleep
(
1000
*
us
);
#ifdef WINDOWS
HANDLE
timer
;
LARGE_INTEGER
interval
;
interval
.
QuadPart
=
(
10
*
us
);
timer
=
CreateWaitableTimer
(
NULL
,
TRUE
,
NULL
);
SetWaitableTimer
(
timer
,
&
interval
,
0
,
NULL
,
NULL
,
0
);
WaitForSingleObject
(
timer
,
INFINITE
);
CloseHandle
(
timer
);
#else
usleep
(
us
);
#endif
...
...
source/os/src/osSocket.c
浏览文件 @
fc245216
...
...
@@ -25,9 +25,6 @@
#include <string.h>
#include <tchar.h>
#include <winbase.h>
#include <winsock2.h>
#include <ws2def.h>
#include "winsock2.h"
#else
#include <arpa/inet.h>
#include <fcntl.h>
...
...
@@ -68,7 +65,7 @@ int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags,
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
sendto
(
pSocket
->
fd
,
buf
,
len
,
flags
,
dest_addr
,
addrlen
);
#else
return
sendto
(
pSocket
->
fd
,
buf
,
len
,
flags
,
dest_addr
,
addrlen
);
...
...
@@ -78,7 +75,7 @@ int32_t taosWriteSocket(TdSocketPtr pSocket, void *buf, int len) {
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
send
(
pSocket
->
fd
,
buf
,
len
,
0
);
;
#else
...
...
@@ -89,7 +86,7 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) {
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
recv
(
pSocket
->
fd
,
buf
,
len
,
0
);
;
#else
...
...
@@ -97,14 +94,14 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) {
#endif
}
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
socklen_
t
*
addrLen
)
{
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
in
t
*
addrLen
)
{
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
return
recvfrom
(
pSocket
->
fd
,
buf
,
len
,
flags
,
destAddr
,
addrLen
);
}
int32_t
taosCloseSocketNoCheck1
(
SocketFd
fd
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
closesocket
(
fd
);
#else
return
close
(
fd
);
...
...
@@ -205,8 +202,8 @@ int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer) {
#endif
}
void
taosWinSocketInit
1
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void
taosWinSocketInit
()
{
#if
def WINDOWS
static
char
flag
=
0
;
if
(
flag
==
0
)
{
WORD
wVersionRequested
;
...
...
@@ -223,7 +220,7 @@ int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) {
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
u_long
mode
;
if
(
on
)
{
mode
=
1
;
...
...
@@ -255,7 +252,7 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
if
(
level
==
SOL_SOCKET
&&
optname
==
TCP_KEEPCNT
)
{
return
0
;
}
...
...
@@ -274,21 +271,21 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void
return
setsockopt
(
pSocket
->
fd
,
level
,
optname
,
optval
,
optlen
);
#else
return
setsockopt
(
pSocket
->
fd
,
level
,
optname
,
optval
,
(
socklen_
t
)
optlen
);
return
setsockopt
(
pSocket
->
fd
,
level
,
optname
,
optval
,
(
in
t
)
optlen
);
#endif
}
int32_t
taosGetSockOpt
(
TdSocketPtr
pSocket
,
int32_t
level
,
int32_t
optname
,
void
*
optval
,
int32_t
*
optlen
)
{
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
0
;
#else
return
getsockopt
(
pSocket
->
fd
,
level
,
optname
,
optval
,
(
socklen_
t
*
)
optlen
);
return
getsockopt
(
pSocket
->
fd
,
level
,
optname
,
optval
,
(
in
t
*
)
optlen
);
#endif
}
uint32_t
taosInetAddr
(
const
char
*
ipAddr
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
uint32_t
value
;
int32_t
ret
=
inet_pton
(
AF_INET
,
ipAddr
,
&
value
);
if
(
ret
<=
0
)
{
...
...
@@ -301,7 +298,7 @@ uint32_t taosInetAddr(const char *ipAddr) {
#endif
}
const
char
*
taosInetNtoa
(
struct
in_addr
ipInt
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
// not thread safe, only for debug usage while print log
static
char
tmpDstStr
[
16
];
return
inet_ntop
(
AF_INET
,
&
ipInt
,
tmpDstStr
,
INET6_ADDRSTRLEN
);
...
...
@@ -693,7 +690,7 @@ TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
}
TdSocketPtr
taosAcceptTcpConnectSocket
(
TdSocketServerPtr
pServerSocket
,
struct
sockaddr
*
destAddr
,
socklen_
t
*
addrLen
)
{
in
t
*
addrLen
)
{
if
(
pServerSocket
==
NULL
||
pServerSocket
->
fd
<
0
)
{
return
NULL
;
}
...
...
@@ -753,12 +750,12 @@ int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len
}
void
taosBlockSIGPIPE
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#else
sigset_t
signal_mask
;
sigemptyset
(
&
signal_mask
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
int32_t
rc
=
taosThreadSigM
ask
(
SIG_BLOCK
,
&
signal_mask
,
NULL
);
int32_t
rc
=
pthread_sigm
ask
(
SIG_BLOCK
,
&
signal_mask
,
NULL
);
if
(
rc
!=
0
)
{
// printf("failed to block SIGPIPE");
}
...
...
@@ -864,26 +861,26 @@ void tinet_ntoa(char *ipstr, uint32_t ip) {
}
void
taosIgnSIGPIPE
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#else
signal
(
SIGPIPE
,
SIG_IGN
);
#endif
}
void
taosSetMaskSIGPIPE
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#else
sigset_t
signal_mask
;
sigemptyset
(
&
signal_mask
);
sigaddset
(
&
signal_mask
,
SIGPIPE
);
int32_t
rc
=
taosThreadSigM
ask
(
SIG_SETMASK
,
&
signal_mask
,
NULL
);
int32_t
rc
=
pthread_sigm
ask
(
SIG_SETMASK
,
&
signal_mask
,
NULL
);
if
(
rc
!=
0
)
{
// printf("failed to setmask SIGPIPE");
}
#endif
}
int32_t
taosGetSocketName
(
TdSocketPtr
pSocket
,
struct
sockaddr
*
destAddr
,
socklen_
t
*
addrLen
)
{
int32_t
taosGetSocketName
(
TdSocketPtr
pSocket
,
struct
sockaddr
*
destAddr
,
in
t
*
addrLen
)
{
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
}
...
...
@@ -893,7 +890,7 @@ int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, sockle
TdEpollPtr
taosCreateEpoll
(
int32_t
size
)
{
EpollFd
fd
=
-
1
;
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#else
fd
=
epoll_create
(
size
);
#endif
...
...
@@ -915,7 +912,7 @@ int32_t taosCtlEpoll(TdEpollPtr pEpoll, int32_t epollOperate, TdSocketPtr pSocke
if
(
pEpoll
==
NULL
||
pEpoll
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#else
code
=
epoll_ctl
(
pEpoll
->
fd
,
epollOperate
,
pSocket
->
fd
,
event
);
#endif
...
...
@@ -926,7 +923,7 @@ int32_t taosWaitEpoll(TdEpollPtr pEpoll, struct epoll_event *event, int32_t maxE
if
(
pEpoll
==
NULL
||
pEpoll
->
fd
<
0
)
{
return
-
1
;
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#else
code
=
epoll_wait
(
pEpoll
->
fd
,
event
,
maxEvents
,
timeout
);
#endif
...
...
source/os/src/osString.c
浏览文件 @
fc245216
...
...
@@ -24,6 +24,55 @@
extern
int
wcwidth
(
wchar_t
c
);
extern
int
wcswidth
(
const
wchar_t
*
s
,
size_t
n
);
#ifdef WINDOWS
char
*
strsep
(
char
**
stringp
,
const
char
*
delim
)
{
char
*
s
;
const
char
*
spanp
;
int32_t
c
,
sc
;
char
*
tok
;
if
((
s
=
*
stringp
)
==
NULL
)
return
(
NULL
);
for
(
tok
=
s
;;)
{
c
=
*
s
++
;
spanp
=
delim
;
do
{
if
((
sc
=
*
spanp
++
)
==
c
)
{
if
(
c
==
0
)
s
=
NULL
;
else
s
[
-
1
]
=
0
;
*
stringp
=
s
;
return
(
tok
);
}
}
while
(
sc
!=
0
);
}
/* NOTREACHED */
}
/* Duplicate a string, up to at most size characters */
char
*
strndup
(
const
char
*
s
,
size_t
size
)
{
size_t
l
;
char
*
s2
;
l
=
strlen
(
s
);
if
(
l
>
size
)
l
=
size
;
s2
=
malloc
(
l
+
1
);
if
(
s2
)
{
strncpy
(
s2
,
s
,
l
);
s2
[
l
]
=
'\0'
;
}
return
s2
;
}
/* Copy no more than N characters of SRC to DEST, returning the address of
the terminating '\0' in DEST, if any, or else DEST + N. */
char
*
stpncpy
(
char
*
dest
,
const
char
*
src
,
size_t
n
)
{
size_t
size
=
strnlen
(
src
,
n
);
memcpy
(
dest
,
src
,
size
);
dest
+=
size
;
if
(
size
==
n
)
return
dest
;
return
memset
(
dest
,
'\0'
,
n
-
size
);
}
#endif
int64_t
taosStr2int64
(
const
char
*
str
)
{
char
*
endptr
=
NULL
;
return
strtoll
(
str
,
&
endptr
,
10
);
...
...
source/os/src/osStrptime.c
浏览文件 @
fc245216
...
...
@@ -38,7 +38,7 @@
//
//#include "lukemftp.h"
// #if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
// #if
def WINDOWS
// #include <time.h>
// #include <stdlib.h>
...
...
@@ -100,7 +100,7 @@
// #endif
// char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
// #if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
// #if
def WINDOWS
// char c;
// const char *bp;
// size_t len = 0;
...
...
source/os/src/osSysinfo.c
浏览文件 @
fc245216
...
...
@@ -17,7 +17,23 @@
#include "os.h"
#include "taoserror.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define PROCESS_ITEM 12
typedef
struct
{
uint64_t
user
;
uint64_t
nice
;
uint64_t
system
;
uint64_t
idle
;
}
SysCpuInfo
;
typedef
struct
{
uint64_t
utime
;
// user time
uint64_t
stime
;
// kernel time
uint64_t
cutime
;
// all user time
uint64_t
cstime
;
// all dead time
}
ProcCpuInfo
;
#ifdef WINDOWS
/*
* windows implementation
...
...
@@ -92,22 +108,6 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
#include <sys/utsname.h>
#include <unistd.h>
#define PROCESS_ITEM 12
typedef
struct
{
uint64_t
user
;
uint64_t
nice
;
uint64_t
system
;
uint64_t
idle
;
}
SysCpuInfo
;
typedef
struct
{
uint64_t
utime
;
// user time
uint64_t
stime
;
// kernel time
uint64_t
cutime
;
// all user time
uint64_t
cstime
;
// all dead time
}
ProcCpuInfo
;
static
pid_t
tsProcId
;
static
char
tsSysNetFile
[]
=
"/proc/net/dev"
;
static
char
tsSysCpuFile
[]
=
"/proc/stat"
;
...
...
@@ -125,8 +125,12 @@ static void taosGetProcIOnfos() {
snprintf
(
tsProcCpuFile
,
sizeof
(
tsProcCpuFile
),
"/proc/%d/stat"
,
tsProcId
);
snprintf
(
tsProcIOFile
,
sizeof
(
tsProcIOFile
),
"/proc/%d/io"
,
tsProcId
);
}
#endif
static
int32_t
taosGetSysCpuInfo
(
SysCpuInfo
*
cpuInfo
)
{
#ifdef WINDOWS
#elif defined(_TD_DARWIN_64)
#else
TdFilePtr
pFile
=
taosOpenFile
(
tsSysCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
return
-
1
;
...
...
@@ -145,10 +149,14 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
taosCloseFile
(
&
pFile
);
#endif
return
0
;
}
static
int32_t
taosGetProcCpuInfo
(
ProcCpuInfo
*
cpuInfo
)
{
#ifdef WINDOWS
#elif defined(_TD_DARWIN_64)
#else
TdFilePtr
pFile
=
taosOpenFile
(
tsProcCpuFile
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
return
-
1
;
...
...
@@ -172,10 +180,10 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
taosCloseFile
(
&
pFile
);
#endif
return
0
;
}
#endif
bool
taosCheckSystemIsSmallEnd
()
{
union
check
{
...
...
@@ -187,7 +195,7 @@ bool taosCheckSystemIsSmallEnd() {
}
void
taosGetSystemInfo
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
taosGetCpuCores
(
&
tsNumOfCores
);
taosGetTotalMemory
(
&
tsTotalMemoryKB
);
...
...
@@ -210,7 +218,7 @@ void taosGetSystemInfo() {
}
int32_t
taosGetEmail
(
char
*
email
,
int32_t
maxLen
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#elif defined(_TD_DARWIN_64)
const
char
*
filepath
=
"/usr/local/taos/email"
;
...
...
@@ -241,7 +249,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
}
int32_t
taosGetOsReleaseName
(
char
*
releaseName
,
int32_t
maxLen
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#elif defined(_TD_DARWIN_64)
char
*
line
=
NULL
;
size_t
size
=
0
;
...
...
@@ -296,7 +304,7 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
}
int32_t
taosGetCpuInfo
(
char
*
cpuModel
,
int32_t
maxLen
,
float
*
numOfCores
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#elif defined(_TD_DARWIN_64)
char
*
line
=
NULL
;
size_t
size
=
0
;
...
...
@@ -355,7 +363,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
}
int32_t
taosGetCpuCores
(
float
*
numOfCores
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
SYSTEM_INFO
info
;
GetSystemInfo
(
&
info
);
*
numOfCores
=
info
.
dwNumberOfProcessors
;
...
...
@@ -399,7 +407,7 @@ void taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
}
int32_t
taosGetTotalMemory
(
int64_t
*
totalKB
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
...
...
@@ -417,7 +425,7 @@ int32_t taosGetTotalMemory(int64_t *totalKB) {
}
int32_t
taosGetProcMemory
(
int64_t
*
usedKB
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
unsigned
bytes_used
=
0
;
#if defined(_WIN64) && defined(_MSC_VER)
...
...
@@ -469,7 +477,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) {
}
int32_t
taosGetSysMemory
(
int64_t
*
usedKB
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
MEMORYSTATUSEX
memsStat
;
memsStat
.
dwLength
=
sizeof
(
memsStat
);
if
(
!
GlobalMemoryStatusEx
(
&
memsStat
))
{
...
...
@@ -534,7 +542,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
}
int32_t
taosGetProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
IO_COUNTERS
io_counter
;
if
(
GetProcessIoCounters
(
GetCurrentProcess
(),
&
io_counter
))
{
if
(
rchars
)
*
rchars
=
io_counter
.
ReadTransferCount
;
...
...
@@ -620,7 +628,7 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i
}
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
*
receive_bytes
=
0
;
*
transmit_bytes
=
0
;
return
0
;
...
...
@@ -691,7 +699,7 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
}
void
taosKillSystem
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
printf
(
"function taosKillSystem, exit!"
);
exit
(
0
);
#elif defined(_TD_DARWIN_64)
...
...
@@ -705,7 +713,7 @@ void taosKillSystem() {
}
int32_t
taosGetSystemUUID
(
char
*
uid
,
int32_t
uidlen
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
GUID
guid
;
CoCreateGuid
(
&
guid
);
...
...
@@ -741,7 +749,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
}
char
*
taosGetCmdlineByPID
(
int
pid
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
return
""
;
#elif defined(_TD_DARWIN_64)
static
char
cmdline
[
1024
];
...
...
@@ -777,7 +785,7 @@ char *taosGetCmdlineByPID(int pid) {
}
void
taosSetCoreDump
(
bool
enable
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
SetUnhandledExceptionFilter
(
&
FlCrashDump
);
#elif defined(_TD_DARWIN_64)
#else
...
...
@@ -857,7 +865,7 @@ void taosSetCoreDump(bool enable) {
}
SysNameInfo
taosGetSysNameInfo
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#elif defined(_TD_DARWIN_64)
SysNameInfo
info
=
{
0
};
...
...
source/os/src/osSystem.c
浏览文件 @
fc245216
...
...
@@ -183,16 +183,33 @@ void resetTerminalMode() {
TdCmdPtr
taosOpenCmd
(
const
char
*
cmd
)
{
if
(
cmd
==
NULL
)
return
NULL
;
#ifdef WINDOWS
return
(
TdCmdPtr
)
_popen
(
cmd
,
"r"
);
#else
return
(
TdCmdPtr
)
popen
(
cmd
,
"r"
);
#endif
}
int64_t
taosGetLineCmd
(
TdCmdPtr
pCmd
,
char
**
__restrict
ptrBuf
)
{
if
(
pCmd
==
NULL
)
{
if
(
pCmd
==
NULL
||
ptrBuf
==
NULL
)
{
return
-
1
;
}
if
(
*
ptrBuf
!=
NULL
)
{
taosMemoryFreeClear
(
*
ptrBuf
);
}
#ifdef WINDOWS
*
ptrBuf
=
taosMemoryMalloc
(
1024
);
if
(
*
ptrBuf
==
NULL
)
return
-
1
;
if
(
fgets
(
*
ptrBuf
,
1023
,
(
FILE
*
)
pCmd
)
==
NULL
)
{
taosMemoryFreeClear
(
*
ptrBuf
);
return
-
1
;
}
(
*
ptrBuf
)[
1023
]
=
0
;
return
strlen
(
*
ptrBuf
);
#else
size_t
len
=
0
;
return
getline
(
ptrBuf
,
&
len
,
(
FILE
*
)
pCmd
);
#endif
}
int32_t
taosEOFCmd
(
TdCmdPtr
pCmd
)
{
...
...
@@ -206,7 +223,11 @@ int64_t taosCloseCmd(TdCmdPtr *ppCmd) {
if
(
ppCmd
==
NULL
||
*
ppCmd
==
NULL
)
{
return
0
;
}
#ifdef WINDOWS
_pclose
((
FILE
*
)(
*
ppCmd
));
#else
pclose
((
FILE
*
)(
*
ppCmd
));
#endif
*
ppCmd
=
NULL
;
return
0
;
}
source/os/src/osThread.c
浏览文件 @
fc245216
...
...
@@ -294,7 +294,7 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
}
int32_t
taosThreadSpinDestroy
(
TdThreadSpinlock
*
lock
)
{
#if
ndef __USE_XOPEN2K
#if
def TD_USE_SPINLOCK_AS_MUTEX
return
pthread_mutex_destroy
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_destroy
((
pthread_spinlock_t
*
)
lock
);
...
...
@@ -302,15 +302,16 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
}
int32_t
taosThreadSpinInit
(
TdThreadSpinlock
*
lock
,
int32_t
pshared
)
{
#ifndef __USE_XOPEN2K
return
pthread_mutex_init
((
pthread_mutex_t
*
)
lock
,
pshared
);
#ifdef TD_USE_SPINLOCK_AS_MUTEX
assert
(
pshared
==
NULL
);
return
pthread_mutex_init
((
pthread_mutex_t
*
)
lock
,
NULL
);
#else
return
pthread_spin_init
((
pthread_spinlock_t
*
)
lock
,
pshared
);
#endif
}
int32_t
taosThreadSpinLock
(
TdThreadSpinlock
*
lock
)
{
#if
ndef __USE_XOPEN2K
#if
def TD_USE_SPINLOCK_AS_MUTEX
return
pthread_mutex_lock
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_lock
((
pthread_spinlock_t
*
)
lock
);
...
...
@@ -318,7 +319,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
}
int32_t
taosThreadSpinTrylock
(
TdThreadSpinlock
*
lock
)
{
#if
ndef __USE_XOPEN2K
#if
def TD_USE_SPINLOCK_AS_MUTEX
return
pthread_mutex_trylock
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_trylock
((
pthread_spinlock_t
*
)
lock
);
...
...
@@ -326,7 +327,7 @@ int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
}
int32_t
taosThreadSpinUnlock
(
TdThreadSpinlock
*
lock
)
{
#if
ndef __USE_XOPEN2K
#if
def TD_USE_SPINLOCK_AS_MUTEX
return
pthread_mutex_unlock
((
pthread_mutex_t
*
)
lock
);
#else
return
pthread_spin_unlock
((
pthread_spinlock_t
*
)
lock
);
...
...
@@ -337,10 +338,6 @@ void taosThreadTestCancel(void) {
return
pthread_testcancel
();
}
int32_t
taosThreadSigMask
(
int32_t
how
,
sigset_t
const
*
set
,
sigset_t
*
oset
)
{
return
pthread_sigmask
(
how
,
set
,
oset
);
}
int32_t
taosThreadSigWait
(
const
sigset_t
*
set
,
int32_t
*
sig
)
{
return
sigwait
(
set
,
sig
);
void
taosThreadClear
(
TdThread
*
thread
)
{
memset
(
thread
,
0
,
sizeof
(
TdThread
));
}
\ No newline at end of file
source/os/src/osTime.c
浏览文件 @
fc245216
...
...
@@ -26,12 +26,11 @@
#include "os.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
//#define TM_YEAR_BASE 1970 //origin
#define TM_YEAR_BASE 1900 //slguan
/*
...
...
@@ -85,13 +84,43 @@ static const char *am_pm[2] = {
"AM"
,
"PM"
};
#define BILLION (1E9)
static
BOOL
g_first_time
=
1
;
static
LARGE_INTEGER
g_counts_per_sec
;
int
clock_gettime
(
int
dummy
,
struct
timespec
*
ct
)
{
LARGE_INTEGER
count
;
if
(
g_first_time
)
{
g_first_time
=
0
;
if
(
0
==
QueryPerformanceFrequency
(
&
g_counts_per_sec
))
{
g_counts_per_sec
.
QuadPart
=
0
;
}
}
if
((
NULL
==
ct
)
||
(
g_counts_per_sec
.
QuadPart
<=
0
)
||
(
0
==
QueryPerformanceCounter
(
&
count
)))
{
return
-
1
;
}
ct
->
tv_sec
=
count
.
QuadPart
/
g_counts_per_sec
.
QuadPart
;
ct
->
tv_nsec
=
((
count
.
QuadPart
%
g_counts_per_sec
.
QuadPart
)
*
BILLION
)
/
g_counts_per_sec
.
QuadPart
;
return
0
;
}
#else
#include <sys/time.h>
#endif
char
*
taosStrpTime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
char
c
;
const
char
*
bp
;
size_t
len
=
0
;
...
...
@@ -391,7 +420,7 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
}
FORCE_INLINE
int32_t
taosGetTimeOfDay
(
struct
timeval
*
tv
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
time_t
t
;
t
=
taosGetTimestampSec
();
SYSTEMTIME
st
;
...
...
@@ -418,7 +447,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) {
if
(
result
==
NULL
)
{
return
localtime
(
timep
);
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
localtime_s
(
result
,
timep
);
#else
localtime_r
(
timep
,
result
);
...
...
@@ -427,3 +456,5 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) {
}
int32_t
taosGetTimestampSec
()
{
return
(
int32_t
)
time
(
NULL
);
}
int32_t
taosClockGetTime
(
int
clock_id
,
struct
timespec
*
pTS
)
{
return
clock_gettime
(
clock_id
,
pTS
);
}
\ No newline at end of file
source/os/src/osTimer.c
浏览文件 @
fc245216
...
...
@@ -17,7 +17,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#include <Mmsystem.h>
#include <Windows.h>
#include <stdint.h>
...
...
@@ -143,7 +143,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
#endif
int
taosInitTimer
(
void
(
*
callback
)(
int
),
int
ms
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
DWORD_PTR
param
=
*
((
int64_t
*
)
&
callback
);
timerId
=
timeSetEvent
(
ms
,
1
,
(
LPTIMECALLBACK
)
taosWinOnTimer
,
param
,
TIME_PERIODIC
);
...
...
@@ -190,7 +190,7 @@ int taosInitTimer(void (*callback)(int), int ms) {
}
void
taosUninitTimer
()
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
timeKillEvent
(
timerId
);
#elif defined(_TD_DARWIN_64)
int
r
=
0
;
...
...
source/os/src/osTimezone.c
浏览文件 @
fc245216
...
...
@@ -17,7 +17,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
#if (_WIN64)
#include <iphlpapi.h>
#include <mswsock.h>
...
...
@@ -59,11 +59,12 @@ void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8
buf
[
i
]
=
inTimezoneStr
[
i
];
}
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
char
winStr
[
TD_LOCALE_LEN
*
2
];
sprintf
(
winStr
,
"TZ=%s"
,
buf
);
putenv
(
winStr
);
tzset
();
/*
* get CURRENT time zone.
* system current time zone is affected by daylight saving time(DST)
*
...
...
@@ -116,7 +117,7 @@ void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8
}
void
taosGetSystemTimezone
(
char
*
outTimezoneStr
,
enum
TdTimezone
*
tsTimezone
)
{
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
char
*
tz
=
getenv
(
"TZ"
);
if
(
tz
==
NULL
||
strlen
(
tz
)
==
0
)
{
strcpy
(
outTimezoneStr
,
"not configured"
);
...
...
source/util/CMakeLists.txt
浏览文件 @
fc245216
...
...
@@ -8,7 +8,7 @@ target_include_directories(
)
target_link_libraries
(
util
P
RIVATE
os
P
UBLIC
os
PUBLIC lz4_static
PUBLIC api cjson
)
...
...
source/util/src/tcache.c
浏览文件 @
fc245216
...
...
@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE
#include "tcache.h"
#include "taoserror.h"
#include "osThread.h"
#include "tlog.h"
#include "tutil.h"
...
...
@@ -24,7 +25,7 @@
static
TdThread
cacheRefreshWorker
=
{
0
};
static
TdThreadOnce
cacheThreadInit
=
PTHREAD_ONCE_INIT
;
static
TdThreadMutex
guard
=
PTHREAD_MUTEX_INITIALIZER
;
static
TdThreadMutex
guard
=
TD_
PTHREAD_MUTEX_INITIALIZER
;
static
SArray
*
pCacheArrayList
=
NULL
;
static
bool
stopRefreshWorker
=
false
;
static
bool
refreshWorkerNormalStopped
=
false
;
...
...
source/util/src/tconfig.c
浏览文件 @
fc245216
...
...
@@ -139,7 +139,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
return
-
1
;
}
if
(
taosRealPath
(
fullDir
,
PATH_MAX
)
!=
0
)
{
if
(
taosRealPath
(
fullDir
,
NULL
,
PATH_MAX
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
uError
(
"failed to get realpath of dir:%s since %s"
,
inputDir
,
terrstr
());
return
-
1
;
...
...
source/util/src/thash.c
浏览文件 @
fc245216
...
...
@@ -135,7 +135,7 @@ static FORCE_INLINE void taosHashEntryRUnlock(const SHashObj *pHashObj, SHashEnt
}
static
FORCE_INLINE
int32_t
taosHashCapacity
(
int32_t
length
)
{
int32_t
len
=
MIN
(
length
,
HASH_MAX_CAPACITY
);
int32_t
len
=
(
length
<
HASH_MAX_CAPACITY
?
length
:
HASH_MAX_CAPACITY
);
int32_t
i
=
4
;
while
(
i
<
len
)
i
=
(
i
<<
1u
);
...
...
source/util/src/tlog.c
浏览文件 @
fc245216
...
...
@@ -14,6 +14,7 @@
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tlog.h"
#include "tutil.h"
...
...
source/util/src/tprocess.c
浏览文件 @
fc245216
...
...
@@ -286,13 +286,13 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea
pQueue
->
head
=
headLen
+
bodyLen
;
}
else
if
(
remain
<
8
+
headLen
)
{
memcpy
(
pHead
,
pQueue
->
pBuffer
+
pQueue
->
head
+
8
,
remain
-
8
);
memcpy
(
pHead
+
remain
-
8
,
pQueue
->
pBuffer
,
headLen
-
(
remain
-
8
));
memcpy
(
(
char
*
)
pHead
+
remain
-
8
,
pQueue
->
pBuffer
,
headLen
-
(
remain
-
8
));
memcpy
(
pBody
,
pQueue
->
pBuffer
+
headLen
-
(
remain
-
8
),
bodyLen
);
pQueue
->
head
=
headLen
-
(
remain
-
8
)
+
bodyLen
;
}
else
if
(
remain
<
8
+
headLen
+
bodyLen
)
{
memcpy
(
pHead
,
pQueue
->
pBuffer
+
pQueue
->
head
+
8
,
headLen
);
memcpy
(
pBody
,
pQueue
->
pBuffer
+
pQueue
->
head
+
8
+
headLen
,
remain
-
8
-
headLen
);
memcpy
(
pBody
+
remain
-
8
-
headLen
,
pQueue
->
pBuffer
,
bodyLen
-
(
remain
-
8
-
headLen
));
memcpy
(
(
char
*
)
pBody
+
remain
-
8
-
headLen
,
pQueue
->
pBuffer
,
bodyLen
-
(
remain
-
8
-
headLen
));
pQueue
->
head
=
bodyLen
-
(
remain
-
8
-
headLen
);
}
else
{
memcpy
(
pHead
,
pQueue
->
pBuffer
+
pQueue
->
head
+
8
,
headLen
);
...
...
@@ -434,7 +434,7 @@ void taosProcStop(SProcObj *pProc) {
}
tsem_post
(
&
pQueue
->
sem
);
taosThreadJoin
(
pProc
->
thread
,
NULL
);
pProc
->
thread
=
0
;
taosThreadClear
(
&
pProc
->
thread
)
;
}
void
taosProcCleanup
(
SProcObj
*
pProc
)
{
...
...
source/util/src/tskiplist.c
浏览文件 @
fc245216
...
...
@@ -559,7 +559,7 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) {
const
uint32_t
factor
=
4
;
int32_t
n
=
1
;
#if
defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if
def WINDOWS
while
((
taosRand
()
%
factor
)
==
0
&&
n
<=
pSkipList
->
maxLevel
)
{
#else
while
((
taosRandR
(
&
(
pSkipList
->
seed
))
%
factor
)
==
0
&&
n
<=
pSkipList
->
maxLevel
)
{
...
...
source/util/src/ttimer.c
浏览文件 @
fc245216
...
...
@@ -132,7 +132,7 @@ static timer_map_t timerMap;
static
uintptr_t
getNextTimerId
()
{
uintptr_t
id
;
do
{
id
=
(
uintptr_t
)
atomic_add_fetch_ptr
((
void
**
)
&
nextTimerId
,
1
);
id
=
(
uintptr_t
)
atomic_add_fetch_ptr
((
void
**
)
&
nextTimerId
,
(
void
*
)
1
);
}
while
(
id
==
0
);
return
id
;
}
...
...
source/util/test/freelistTest.cpp
浏览文件 @
fc245216
...
...
@@ -14,4 +14,4 @@ TEST(TD_UTIL_FREELIST_TEST, simple_test) {
}
tFreeListClear
(
&
fl
);
}
\ No newline at end of file
}
source/util/test/procTest.cpp
浏览文件 @
fc245216
...
...
@@ -63,19 +63,19 @@ TEST_F(UtilTesProc, 00_Init_Cleanup) {
ASSERT_EQ
(
taosCreateShm
(
&
shm
,
1234
,
1024
*
1024
*
2
),
0
);
shm
.
size
=
1023
;
SProcCfg
cfg
=
{
.
childConsumeFp
=
(
ProcConsumeFp
)
NULL
,
.
childMallocHeadFp
=
(
ProcMallocFp
)
taosAllocateQitem
,
.
childFreeHeadFp
=
(
ProcFreeFp
)
taosFreeQitem
,
.
childMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
childFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryMalloc
,
.
parentConsumeFp
=
(
ProcConsumeFp
)
NULL
,
.
parentMallocHeadFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeHeadFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryMalloc
,
.
shm
=
shm
,
.
parent
=
&
shm
,
.
name
=
"1234"
};
SProcCfg
cfg
=
{(
ProcConsumeFp
)
NULL
,
(
ProcMallocFp
)
taosAllocateQitem
,
(
ProcFreeFp
)
taosFreeQitem
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryMalloc
,
(
ProcConsumeFp
)
NULL
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryMalloc
,
shm
,
&
shm
,
"1234"
};
SProcObj
*
proc
=
taosProcInit
(
&
cfg
);
ASSERT_EQ
(
proc
,
nullptr
);
...
...
@@ -104,19 +104,19 @@ void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int3
TEST_F
(
UtilTesProc
,
01
_Push_Pop_Child
)
{
shm
.
size
=
3000
;
ASSERT_EQ
(
taosCreateShm
(
&
shm
,
1235
,
shm
.
size
),
0
);
SProcCfg
cfg
=
{
.
childConsumeFp
=
(
ProcConsumeFp
)
ConsumeChild1
,
.
childMallocHeadFp
=
(
ProcMallocFp
)
taosAllocateQitem
,
.
childFreeHeadFp
=
(
ProcFreeFp
)
taosFreeQitem
,
.
childMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
childFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentConsumeFp
=
(
ProcConsumeFp
)
NULL
,
.
parentMallocHeadFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeHeadFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
shm
=
shm
,
.
parent
=
(
void
*
)((
int64_t
)
1235
),
.
name
=
"1235_c"
};
SProcCfg
cfg
=
{(
ProcConsumeFp
)
ConsumeChild1
,
(
ProcMallocFp
)
taosAllocateQitem
,
(
ProcFreeFp
)
taosFreeQitem
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
(
ProcConsumeFp
)
NULL
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
shm
,
(
void
*
)((
int64_t
)
1235
),
"1235_c"
};
SProcObj
*
cproc
=
taosProcInit
(
&
cfg
);
ASSERT_NE
(
cproc
,
nullptr
);
...
...
@@ -162,19 +162,19 @@ void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int
TEST_F
(
UtilTesProc
,
02
_Push_Pop_Parent
)
{
shm
.
size
=
3000
;
ASSERT_EQ
(
taosCreateShm
(
&
shm
,
1236
,
shm
.
size
),
0
);
SProcCfg
cfg
=
{
.
childConsumeFp
=
(
ProcConsumeFp
)
NULL
,
.
childMallocHeadFp
=
(
ProcMallocFp
)
taosAllocateQitem
,
.
childFreeHeadFp
=
(
ProcFreeFp
)
taosFreeQitem
,
.
childMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
childFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentConsumeFp
=
(
ProcConsumeFp
)
ConsumeParent1
,
.
parentMallocHeadFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeHeadFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
shm
=
shm
,
.
parent
=
(
void
*
)((
int64_t
)
1236
),
.
name
=
"1236_c"
};
SProcCfg
cfg
=
{(
ProcConsumeFp
)
NULL
,
(
ProcMallocFp
)
taosAllocateQitem
,
(
ProcFreeFp
)
taosFreeQitem
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
(
ProcConsumeFp
)
ConsumeParent1
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
shm
,
(
void
*
)((
int64_t
)
1236
),
"1236_c"
};
SProcObj
*
cproc
=
taosProcInit
(
&
cfg
);
ASSERT_NE
(
cproc
,
nullptr
);
...
...
@@ -216,19 +216,19 @@ TEST_F(UtilTesProc, 03_Handle) {
// uDebugFlag = 207;
shm
.
size
=
3000
;
ASSERT_EQ
(
taosCreateShm
(
&
shm
,
1237
,
shm
.
size
),
0
);
SProcCfg
cfg
=
{
.
childConsumeFp
=
(
ProcConsumeFp
)
ConsumeChild3
,
.
childMallocHeadFp
=
(
ProcMallocFp
)
taosAllocateQitem
,
.
childFreeHeadFp
=
(
ProcFreeFp
)
taosFreeQitem
,
.
childMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
childFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentConsumeFp
=
(
ProcConsumeFp
)
NULL
,
.
parentMallocHeadFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeHeadFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentMallocBodyFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeBodyFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
shm
=
shm
,
.
parent
=
(
void
*
)((
int64_t
)
1235
),
.
name
=
"1237_p"
};
SProcCfg
cfg
=
{(
ProcConsumeFp
)
ConsumeChild3
,
(
ProcMallocFp
)
taosAllocateQitem
,
(
ProcFreeFp
)
taosFreeQitem
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
(
ProcConsumeFp
)
NULL
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
(
ProcMallocFp
)
taosMemoryMalloc
,
(
ProcFreeFp
)
taosMemoryFree
,
shm
,
(
void
*
)((
int64_t
)
1235
),
"1237_p"
};
SProcObj
*
cproc
=
taosProcInit
(
&
cfg
);
ASSERT_NE
(
cproc
,
nullptr
);
...
...
source/util/test/trefTest.c
浏览文件 @
fc245216
...
...
@@ -36,7 +36,7 @@ void *addRef(void *param) {
for
(
int
i
=
0
;
i
<
pSpace
->
steps
;
++
i
)
{
printf
(
"a"
);
id
=
random
()
%
pSpace
->
refNum
;
id
=
taosRand
()
%
pSpace
->
refNum
;
if
(
pSpace
->
rid
[
id
]
<=
0
)
{
pSpace
->
p
[
id
]
=
taosMemoryMalloc
(
128
);
pSpace
->
rid
[
id
]
=
taosAddRef
(
pSpace
->
rsetId
,
pSpace
->
p
[
id
]);
...
...
@@ -53,7 +53,7 @@ void *removeRef(void *param) {
for
(
int
i
=
0
;
i
<
pSpace
->
steps
;
++
i
)
{
printf
(
"d"
);
id
=
random
()
%
pSpace
->
refNum
;
id
=
taosRand
()
%
pSpace
->
refNum
;
if
(
pSpace
->
rid
[
id
]
>
0
)
{
code
=
taosRemoveRef
(
pSpace
->
rsetId
,
pSpace
->
rid
[
id
]);
if
(
code
==
0
)
pSpace
->
rid
[
id
]
=
0
;
...
...
@@ -72,7 +72,7 @@ void *acquireRelease(void *param) {
for
(
int
i
=
0
;
i
<
pSpace
->
steps
;
++
i
)
{
printf
(
"a"
);
id
=
random
()
%
pSpace
->
refNum
;
id
=
taosRand
()
%
pSpace
->
refNum
;
void
*
p
=
taosAcquireRef
(
pSpace
->
rsetId
,
(
int64_t
)
pSpace
->
p
[
id
]);
if
(
p
)
{
taosUsleep
(
id
%
5
+
1
);
...
...
tests/test/c/tmqDemo.c
浏览文件 @
fc245216
...
...
@@ -14,14 +14,13 @@
*/
#include <assert.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
//
#include <unistd.h>
#include "taos.h"
#include "taoserror.h"
...
...
@@ -227,7 +226,7 @@ int64_t getDirectorySize(char* dir) {
}
}
taosCloseDir
(
pDir
);
taosCloseDir
(
&
pDir
);
return
totalSize
;
}
...
...
@@ -595,8 +594,8 @@ void printParaIntoFile() {
taosOpenFile
(
g_stConfInfo
.
resultFileName
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
|
TD_FILE_STREAM
);
if
(
NULL
==
pFile
)
{
fprintf
(
stderr
,
"Failed to open %s for save result
\n
"
,
g_stConfInfo
.
resultFileName
);
exit
-
1
;
}
;
exit
(
-
1
)
;
}
g_fp
=
pFile
;
time_t
tTime
=
taosGetTimestampSec
();
...
...
tests/test/c/tmqSim.c
浏览文件 @
fc245216
...
...
@@ -14,14 +14,13 @@
*/
#include <assert.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
//
#include <unistd.h>
#include "taos.h"
#include "taoserror.h"
...
...
@@ -103,8 +102,8 @@ void initLogFile() {
TdFilePtr
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
|
TD_FILE_STREAM
);
if
(
NULL
==
pFile
)
{
fprintf
(
stderr
,
"Failed to open %s for save result
\n
"
,
"./tmqlog.txt"
);
exit
-
1
;
}
;
exit
(
-
1
)
;
}
g_fp
=
pFile
;
}
...
...
tools/shell/src/shellEngine.c
浏览文件 @
fc245216
...
...
@@ -29,7 +29,6 @@
#include "tutil.h"
#include <regex.h>
#include <wordexp.h>
/**************** Global variables ****************/
#ifdef _TD_POWER_
...
...
tools/shell/src/shellMain.c
浏览文件 @
fc245216
...
...
@@ -18,9 +18,11 @@
#include "tglobal.h"
#include "tlog.h"
#ifndef WINDOWS
#include <argp.h>
#include <termio.h>
#include <wordexp.h>
#endif
#define OPT_ABORT 1
/* abort */
...
...
@@ -37,6 +39,7 @@ TdThread pid;
static
tsem_t
cancelSem
;
extern
void
taos_init
();
#ifndef WINDOWS
static
struct
argp_option
options
[]
=
{
{
"host"
,
'h'
,
"HOST"
,
0
,
"TDengine server FQDN to connect. The default host is localhost."
},
{
"password"
,
'p'
,
NULL
,
0
,
"The password to use when connecting to the server."
},
...
...
@@ -213,7 +216,10 @@ static void parse_args(int argc, char *argv[], SShellArguments *arguments) {
}
}
#endif
void
shellParseArgument
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
#ifdef WINDOWS
#else
static
char
verType
[
32
]
=
{
0
};
sprintf
(
verType
,
"version: %s
\n
"
,
version
);
...
...
@@ -233,9 +239,12 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
abort
();
#endif
}
#endif
}
int32_t
shellReadCommand
(
TAOS
*
con
,
char
*
command
)
{
#ifdef WINDOWS
#else
unsigned
hist_counter
=
history
.
hend
;
char
utf8_array
[
10
]
=
"
\0
"
;
Command
cmd
;
...
...
@@ -390,6 +399,7 @@ int32_t shellReadCommand(TAOS *con, char *command) {
}
}
#endif
return
0
;
}
...
...
@@ -435,6 +445,8 @@ void *shellLoopQuery(void *arg) {
void
get_history_path
(
char
*
_history
)
{
snprintf
(
_history
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
getenv
(
"HOME"
),
HISTORY_FILE
);
}
void
clearScreen
(
int
ecmd_pos
,
int
cursor_pos
)
{
#ifdef WINDOWS
#else
struct
winsize
w
;
if
(
ioctl
(
0
,
TIOCGWINSZ
,
&
w
)
<
0
||
w
.
ws_col
==
0
||
w
.
ws_row
==
0
)
{
// fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n");
...
...
@@ -453,9 +465,12 @@ void clearScreen(int ecmd_pos, int cursor_pos) {
fprintf
(
stdout
,
"
\033
[2K"
);
}
fflush
(
stdout
);
#endif
}
void
showOnScreen
(
Command
*
cmd
)
{
#ifdef WINDOWS
#else
struct
winsize
w
;
if
(
ioctl
(
0
,
TIOCGWINSZ
,
&
w
)
<
0
||
w
.
ws_col
==
0
||
w
.
ws_row
==
0
)
{
// fprintf(stderr, "No stream device\n");
...
...
@@ -526,6 +541,7 @@ void showOnScreen(Command *cmd) {
positionCursor
(
cursor_x
,
DOWN
);
positionCursor
(
cursor_y
,
RIGHT
);
fflush
(
stdout
);
#endif
}
void
cleanup_handler
(
void
*
arg
)
{
resetTerminalMode
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录