未验证 提交 ba8d9a79 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Feature/sangshuduo/td 13063 3.0 windows (#10708)

* [TD-13063]<feature>: 3.0 on Windows

* add pthread in contrib

* fix linux compile

* fix osSemaphore

* add gnu regex for Windows

* fix compile error for Windows
上级 3ef2facd
...@@ -6,40 +6,14 @@ project( ...@@ -6,40 +6,14 @@ project(
DESCRIPTION "An open-source big data platform designed and optimized for the Internet of Things(IOT)" DESCRIPTION "An open-source big data platform designed and optimized for the Internet of Things(IOT)"
) )
IF ("${BUILD_TOOLS}" STREQUAL "")
IF (TD_LINUX)
IF (TD_ARM_32)
SET(BUILD_TOOLS "false")
ELSEIF (TD_ARM_64)
SET(BUILD_TOOLS "false")
ELSE ()
SET(BUILD_TOOLS "false")
ENDIF ()
ELSEIF (TD_DARWIN)
SET(BUILD_TOOLS "false")
ELSE ()
SET(BUILD_TOOLS "false")
ENDIF ()
ENDIF ()
IF ("${BUILD_TOOLS}" MATCHES "false")
MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}")
SET(TD_TAOS_TOOLS FALSE)
ELSE ()
MESSAGE("")
MESSAGE("${Green} Will build taos_tools! ${ColourReset}")
MESSAGE("")
SET(TD_TAOS_TOOLS TRUE)
ENDIF ()
set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib") set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib")
include(${CMAKE_SUPPORT_DIR}/cmake.platform)
include(${CMAKE_SUPPORT_DIR}/cmake.define)
include(${CMAKE_SUPPORT_DIR}/cmake.options) include(${CMAKE_SUPPORT_DIR}/cmake.options)
include(${CMAKE_SUPPORT_DIR}/cmake.version) include(${CMAKE_SUPPORT_DIR}/cmake.version)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
# contrib # contrib
add_subdirectory(contrib) add_subdirectory(contrib)
...@@ -52,6 +26,7 @@ if(${BUILD_TEST}) ...@@ -52,6 +26,7 @@ if(${BUILD_TEST})
include(CTest) include(CTest)
enable_testing() enable_testing()
endif(${BUILD_TEST}) endif(${BUILD_TEST})
add_subdirectory(source) add_subdirectory(source)
add_subdirectory(tools) add_subdirectory(tools)
add_subdirectory(tests) add_subdirectory(tests)
......
cmake_minimum_required(VERSION 3.16)
IF ("${BUILD_TOOLS}" STREQUAL "")
IF (TD_LINUX)
IF (TD_ARM_32)
SET(BUILD_TOOLS "false")
ELSEIF (TD_ARM_64)
SET(BUILD_TOOLS "false")
ELSE ()
SET(BUILD_TOOLS "false")
ENDIF ()
ELSEIF (TD_DARWIN)
SET(BUILD_TOOLS "false")
ELSE ()
SET(BUILD_TOOLS "false")
ENDIF ()
ENDIF ()
IF ("${BUILD_TOOLS}" MATCHES "false")
MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}")
SET(TD_TAOS_TOOLS FALSE)
ELSE ()
MESSAGE("")
MESSAGE("${Green} Will build taos_tools! ${ColourReset}")
MESSAGE("")
SET(TD_TAOS_TOOLS TRUE)
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-")
IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
ENDIF ()
ELSE ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
ENDIF ()
# ========================================================= # =========================================================
# Deps options # Deps options
# ========================================================= # =========================================================
IF(${TD_WINDOWS})
MESSAGE("build pthread Win32")
option(
BUILD_PTHREAD
"If build pthread on Windows"
ON
)
MESSAGE("build gnu regex for Windows")
option(
BUILD_GNUREGEX
"If build gnu regex on Windows"
ON
)
ENDIF ()
IF(${TD_LINUX} MATCHES TRUE)
option( option(
BUILD_TEST BUILD_TEST
"If build unit tests using googletest" "If build unit tests using googletest"
ON ON
) )
ENDIF ()
option( option(
BUILD_WITH_LEVELDB BUILD_WITH_LEVELDB
"If build with leveldb" "If build with leveldb"
...@@ -25,11 +48,16 @@ option( ...@@ -25,11 +48,16 @@ option(
OFF OFF
) )
option( IF(${TD_WINDOWS})
BUILD_WITH_BDB MESSAGE("Not build BDB on Windows")
"If build with BerkleyDB" ELSE ()
ON option(
) BUILD_WITH_BDB
"If build with BerkleyDB"
ON
)
ENDIF ()
option( option(
BUILD_WITH_LUCENE BUILD_WITH_LUCENE
...@@ -68,12 +96,16 @@ option( ...@@ -68,12 +96,16 @@ option(
OFF OFF
) )
IF(${TD_LINUX} MATCHES TRUE)
option( option(
BUILD_DEPENDENCY_TESTS BUILD_DEPENDENCY_TESTS
"If build dependency tests" "If build dependency tests"
ON ON
) )
ENDIF ()
option( option(
BUILD_DOCS BUILD_DOCS
"If use doxygen build documents" "If use doxygen build documents"
......
cmake_minimum_required(VERSION 3.16)
MESSAGE("Current system is ${CMAKE_SYSTEM_NAME}")
# init
SET(TD_LINUX FALSE)
SET(TD_WINDOWS FALSE)
SET(TD_DARWIN FALSE)
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(TD_LINUX TRUE)
SET(OSTYPE "Linux")
ADD_DEFINITIONS("-DLINUX")
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
SET(TD_LINUX_64 TRUE)
ELSE ()
SET(TD_LINUX_32 TRUE)
ENDIF ()
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(TD_DARWIN TRUE)
SET(OSTYPE "macOS")
ADD_DEFINITIONS("-DDARWIN")
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
MESSAGE("Current system arch is arm64")
SET(TD_DARWIN_64 TRUE)
ADD_DEFINITIONS("-D_TD_DARWIN_64")
ENDIF ()
ADD_DEFINITIONS("-DHAVE_UNISTD_H")
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
SET(TD_WINDOWS TRUE)
SET(OSTYPE "Windows")
ADD_DEFINITIONS("-DWINDOWS")
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
SET(TD_WINDOWS_64 TRUE)
ADD_DEFINITIONS("-D_TD_WINDOWS_64")
ELSE ()
SET(TD_WINDOWS_32 TRUE)
ADD_DEFINITIONS("-D_TD_WINDOWS_32")
ENDIF ()
ENDIF()
MESSAGE("C Compiler ID: ${CMAKE_C_COMPILER_ID}")
MESSAGE("CXX Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
# gnuregex
ExternalProject_Add(gnuregex
URL https://launchpad.net/gnuregex/trunk/2.9/+download/libgnurx-src-2.9.zip
DOWNLOAD_NAME libgnurx-src.zip
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/gnuregex"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
# pthread
ExternalProject_Add(pthread
GIT_REPOSITORY https://github.com/GerHobbelt/pthread-win32
GIT_TAG v3.0.3.1
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/pthread-win32"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
...@@ -9,6 +9,16 @@ endfunction(cat IN_FILE OUT_FILE) ...@@ -9,6 +9,16 @@ endfunction(cat IN_FILE OUT_FILE)
set(CONTRIB_TMP_FILE "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in") set(CONTRIB_TMP_FILE "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in")
configure_file("${CMAKE_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) configure_file("${CMAKE_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
# pthread
if(${BUILD_PTHREAD})
cat("${CMAKE_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()
# gnu regex
if(${BUILD_GNUREGEX})
cat("${CMAKE_SUPPORT_DIR}/gnuregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()
# googletest # googletest
if(${BUILD_TEST}) if(${BUILD_TEST})
cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
...@@ -193,7 +203,10 @@ endif(${BUILD_WITH_TRAFT}) ...@@ -193,7 +203,10 @@ endif(${BUILD_WITH_TRAFT})
# LIBUV # LIBUV
if(${BUILD_WITH_UV}) if(${BUILD_WITH_UV})
add_compile_options(-Wno-sign-compare) if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
MESSAGE("Windows need set no-sign-compare")
add_compile_options(-Wno-sign-compare)
endif ()
add_subdirectory(libuv) add_subdirectory(libuv)
endif(${BUILD_WITH_UV}) endif(${BUILD_WITH_UV})
...@@ -224,6 +237,7 @@ if(${BUILD_WITH_SQLITE}) ...@@ -224,6 +237,7 @@ if(${BUILD_WITH_SQLITE})
) )
endif(${BUILD_WITH_SQLITE}) endif(${BUILD_WITH_SQLITE})
# pthread
# ================================================================================================ # ================================================================================================
......
...@@ -1356,6 +1356,7 @@ typedef struct SVCreateTbReq { ...@@ -1356,6 +1356,7 @@ typedef struct SVCreateTbReq {
} SVCreateTbReq, SVUpdateTbReq; } SVCreateTbReq, SVUpdateTbReq;
typedef struct { typedef struct {
int tmp; // TODO: to avoid compile error
} SVCreateTbRsp, SVUpdateTbRsp; } SVCreateTbRsp, SVUpdateTbRsp;
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq); int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
...@@ -1367,6 +1368,7 @@ typedef struct { ...@@ -1367,6 +1368,7 @@ typedef struct {
} SVCreateTbBatchReq; } SVCreateTbBatchReq;
typedef struct { typedef struct {
int tmp; // TODO: to avoid compile error
} SVCreateTbBatchRsp; } SVCreateTbBatchRsp;
int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq); int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq);
...@@ -1380,6 +1382,7 @@ typedef struct { ...@@ -1380,6 +1382,7 @@ typedef struct {
} SVDropTbReq; } SVDropTbReq;
typedef struct { typedef struct {
int tmp; // TODO: to avoid compile error
} SVDropTbRsp; } SVDropTbRsp;
int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq); int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq);
...@@ -1930,7 +1933,9 @@ typedef struct { ...@@ -1930,7 +1933,9 @@ typedef struct {
int64_t ver; // use a general definition int64_t ver; // use a general definition
char indexName[TSDB_INDEX_NAME_LEN]; char indexName[TSDB_INDEX_NAME_LEN];
} SVDropTSmaReq; } SVDropTSmaReq;
typedef struct { typedef struct {
int tmp; // TODO: to avoid compile error
} SVCreateTSmaRsp, SVDropTSmaRsp; } SVCreateTSmaRsp, SVDropTSmaRsp;
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq); int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
......
...@@ -103,6 +103,7 @@ typedef struct { ...@@ -103,6 +103,7 @@ typedef struct {
typedef struct { typedef struct {
// TODO // TODO
int tmp; // TODO: to avoid compile error
} STpRow; // tuple } STpRow; // tuple
#pragma pack(push, 1) #pragma pack(push, 1)
...@@ -1098,4 +1099,4 @@ const STSRow *tRowBatchIterNext(STSRowBatchIter *pRowBatchIter); ...@@ -1098,4 +1099,4 @@ const STSRow *tRowBatchIterNext(STSRowBatchIter *pRowBatchIter);
} }
#endif #endif
#endif /*_TD_COMMON_ROW_H_*/ #endif /*_TD_COMMON_ROW_H_*/
\ No newline at end of file
...@@ -22,7 +22,22 @@ extern "C" { ...@@ -22,7 +22,22 @@ extern "C" {
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#if !defined(WINDOWS)
#include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <regex.h>
#include <sched.h>
#include <wordexp.h>
#include <libgen.h>
#include <sys/utsname.h>
#include <sys/param.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#endif
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <float.h> #include <float.h>
...@@ -30,8 +45,6 @@ extern "C" { ...@@ -30,8 +45,6 @@ extern "C" {
#include <limits.h> #include <limits.h>
#include <locale.h> #include <locale.h>
#include <math.h> #include <math.h>
#include <regex.h>
#include <sched.h>
#include <setjmp.h> #include <setjmp.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -43,16 +56,9 @@ extern "C" { ...@@ -43,16 +56,9 @@ extern "C" {
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/utsname.h>
#include <sys/param.h>
#include <unistd.h>
#include <wchar.h> #include <wchar.h>
#include <wctype.h> #include <wctype.h>
#include <wordexp.h>
#include <libgen.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include "osAtomic.h" #include "osAtomic.h"
#include "osDef.h" #include "osDef.h"
......
...@@ -49,7 +49,7 @@ extern "C" { ...@@ -49,7 +49,7 @@ extern "C" {
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(WINDOWS)
char *stpcpy (char *dest, const char *src); char *stpcpy (char *dest, const char *src);
char *stpncpy (char *dest, const char *src, size_t n); char *stpncpy (char *dest, const char *src, size_t n);
...@@ -63,14 +63,46 @@ extern "C" { ...@@ -63,14 +63,46 @@ extern "C" {
#define strtok_r strtok_s #define strtok_r strtok_s
#define snprintf _snprintf #define snprintf _snprintf
#define in_addr_t unsigned long #define in_addr_t unsigned long
#define socklen_t int // #define socklen_t int
char * strsep(char **stringp, const char *delim); char * strsep(char **stringp, const char *delim);
char * getpass(const char *prefix); char * getpass(const char *prefix);
char * strndup(const char *s, size_t n); char * strndup(const char *s, size_t n);
int gettimeofday(struct timeval *ptv, void *pTimeZone);
#endif
// for send function in tsocket.c
#define MSG_NOSIGNAL 0
#define SO_NO_CHECK 0x1234
#define SOL_TCP 0x1234
#define SHUT_RDWR SD_BOTH
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
#define LOCK_EX 1
#define LOCK_NB 2
#define LOCK_UN 3
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
typedef struct {
int we_wordc;
char *we_wordv[1];
int we_offs;
char wordPos[1025];
} wordexp_t;
int wordexp(char *words, wordexp_t *pwordexp, int flags);
void wordfree(wordexp_t *pwordexp);
#define openlog(a, b, c)
#define closelog()
#define LOG_ERR 0
#define LOG_INFO 1
void syslog(int unused, const char *format, ...);
#endif // WINDOWS
#ifndef WINDOWS #ifndef WINDOWS
#ifndef O_BINARY #ifndef O_BINARY
#define O_BINARY 0 #define O_BINARY 0
...@@ -164,7 +196,7 @@ extern "C" { ...@@ -164,7 +196,7 @@ extern "C" {
#define PRIzu "zu" #define PRIzu "zu"
#endif #endif
#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64) #if !defined(WINDOWS)
#if defined(_TD_DARWIN_64) #if defined(_TD_DARWIN_64)
// MacOS // MacOS
#if !defined(_GNU_SOURCE) #if !defined(_GNU_SOURCE)
...@@ -179,8 +211,7 @@ extern "C" { ...@@ -179,8 +211,7 @@ extern "C" {
#endif #endif
#else #else
// Windows // Windows
// #define setThreadName(name) #define setThreadName(name)
#define setThreadName(name) do { prctl(PR_SET_NAME, (name)); } while (0)
#endif #endif
#if defined(_WIN32) #if defined(_WIN32)
...@@ -197,4 +228,4 @@ extern "C" { ...@@ -197,4 +228,4 @@ extern "C" {
} }
#endif #endif
#endif /*_TD_OS_DEF_H_*/ #endif /*_TD_OS_DEF_H_*/
\ No newline at end of file
...@@ -22,6 +22,15 @@ extern "C" { ...@@ -22,6 +22,15 @@ extern "C" {
#include "osSocket.h" #include "osSocket.h"
#if defined(WINDOWS)
typedef int32_t FileFd;
typedef SOCKET SocketFd;
#else
typedef int32_t FileFd;
typedef int32_t SocketFd;
#endif
int64_t taosRead(FileFd fd, void *buf, int64_t count);
// If the error is in a third-party library, place this header file under the third-party library header file. // If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC #ifndef ALLOW_FORBID_FUNC
#define open OPEN_FUNC_TAOS_FORBID #define open OPEN_FUNC_TAOS_FORBID
...@@ -76,7 +85,13 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count); ...@@ -76,7 +85,13 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count);
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset); int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset);
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count); int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
void taosFprintfFile(TdFilePtr pFile, const char *format, ...); void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
#if defined(WINDOWS)
#define __restrict__
#endif // WINDOWS
int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf); int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf);
int32_t taosEOFFile(TdFilePtr pFile); int32_t taosEOFFile(TdFilePtr pFile);
int64_t taosCloseFile(TdFilePtr *ppFile); int64_t taosCloseFile(TdFilePtr *ppFile);
......
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
#ifndef _TD_OS_SEMPHONE_H_ #ifndef _TD_OS_SEMPHONE_H_
#define _TD_OS_SEMPHONE_H_ #define _TD_OS_SEMPHONE_H_
#include <semaphore.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <pthread.h>
#include <semaphore.h>
#if defined (_TD_DARWIN_64) #if defined (_TD_DARWIN_64)
typedef struct tsem_s *tsem_t; typedef struct tsem_s *tsem_t;
int tsem_init(tsem_t *sem, int pshared, unsigned int value); int tsem_init(tsem_t *sem, int pshared, unsigned int value);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID #define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(WINDOWS)
#include "winsock2.h" #include "winsock2.h"
#include <WS2tcpip.h> #include <WS2tcpip.h>
#include <winbase.h> #include <winbase.h>
......
...@@ -52,6 +52,13 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen); ...@@ -52,6 +52,13 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
char *taosGetCmdlineByPID(int32_t pid); char *taosGetCmdlineByPID(int32_t pid);
void taosSetCoreDump(bool enable); void taosSetCoreDump(bool enable);
#if defined(WINDOWS)
#define _UTSNAME_LENGTH 65
#define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH
#endif // WINDOWS
typedef struct { typedef struct {
char sysname[_UTSNAME_MACHINE_LENGTH]; char sysname[_UTSNAME_MACHINE_LENGTH];
char nodename[_UTSNAME_MACHINE_LENGTH]; char nodename[_UTSNAME_MACHINE_LENGTH];
......
...@@ -30,6 +30,9 @@ extern "C" { ...@@ -30,6 +30,9 @@ extern "C" {
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define CLOCK_REALTIME 0
#ifdef _TD_GO_DLL_ #ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL) #define MILLISECOND_PER_SECOND (1000LL)
#else #else
......
...@@ -4,6 +4,10 @@ target_include_directories( ...@@ -4,6 +4,10 @@ target_include_directories(
common common
PUBLIC "${CMAKE_SOURCE_DIR}/include/common" PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
IF(${TD_WINDOWS})
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32"
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/gnuregex"
ENDIF ()
) )
target_link_libraries( target_link_libraries(
common common
......
...@@ -3,7 +3,9 @@ add_library(os STATIC ${OS_SRC}) ...@@ -3,7 +3,9 @@ add_library(os STATIC ${OS_SRC})
target_include_directories( target_include_directories(
os os
PUBLIC "${CMAKE_SOURCE_DIR}/include/os" PUBLIC "${CMAKE_SOURCE_DIR}/include/os"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" PRIVATE "${CMAKE_SOURCE_DIR}/include"
PRIVATE "${CMAKE_SOURCE_DIR}/include/util"
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32"
) )
target_link_libraries( target_link_libraries(
os pthread dl rt m os pthread dl rt m
......
...@@ -735,6 +735,7 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) { ...@@ -735,6 +735,7 @@ void taosFprintfFile(TdFilePtr pFile, const char *format, ...) {
fflush(pFile->fp); fflush(pFile->fp);
} }
#if !defined(WINDOWS)
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) { void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
if (pFile == NULL) { if (pFile == NULL) {
return NULL; return NULL;
...@@ -744,6 +745,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) { ...@@ -744,6 +745,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0); void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0);
return ptr; return ptr;
} }
#endif
bool taosValidFile(TdFilePtr pFile) { return pFile != NULL; } bool taosValidFile(TdFilePtr pFile) { return pFile != NULL; }
...@@ -773,6 +775,9 @@ int32_t taosEOFFile(TdFilePtr pFile) { ...@@ -773,6 +775,9 @@ int32_t taosEOFFile(TdFilePtr pFile) {
return feof(pFile->fp); return feof(pFile->fp);
} }
#if !defined(WINDOWS)
bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
int flags = 0; int flags = 0;
...@@ -790,4 +795,7 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { ...@@ -790,4 +795,7 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
return access(pathname, flags) == 0; return access(pathname, flags) == 0;
} }
bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); };
\ No newline at end of file bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); };
#endif // WINDOWS
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "tdef.h"
#include <wchar.h> #include <wchar.h>
#include <wctype.h> #include <wctype.h>
...@@ -360,4 +361,4 @@ int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncha ...@@ -360,4 +361,4 @@ int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncha
return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / ncharSize); return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / ncharSize);
} }
#endif #endif
\ No newline at end of file
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
...@@ -374,12 +375,12 @@ int32_t taosGetCpuCores(float *numOfCores) { ...@@ -374,12 +375,12 @@ int32_t taosGetCpuCores(float *numOfCores) {
int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) { int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
*sysCpuUsage = 0; *cpu_system = 0;
*procCpuUsage = 0; *cpu_engine = 0;
return 0; return 0;
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
*sysCpuUsage = 0; *cpu_system = 0;
*procCpuUsage = 0; *cpu_engine = 0;
return 0; return 0;
#else #else
static uint64_t lastSysUsed = 0; static uint64_t lastSysUsed = 0;
...@@ -514,7 +515,7 @@ int32_t taosGetSysMemory(int64_t *usedKB) { ...@@ -514,7 +515,7 @@ int32_t taosGetSysMemory(int64_t *usedKB) {
} }
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(WINDOWS)
unsigned _int64 i64FreeBytesToCaller; unsigned _int64 i64FreeBytesToCaller;
unsigned _int64 i64TotalBytes; unsigned _int64 i64TotalBytes;
unsigned _int64 i64FreeBytes; unsigned _int64 i64FreeBytes;
...@@ -522,7 +523,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { ...@@ -522,7 +523,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
BOOL fResult = GetDiskFreeSpaceExA(dataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, BOOL fResult = GetDiskFreeSpaceExA(dataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes); (PULARGE_INTEGER)&i64FreeBytes);
if (fResult) { if (fResult) {
diskSize->tsize = (int64_t)(i64TotalBytes); diskSize->total = (int64_t)(i64TotalBytes);
diskSize->avail = (int64_t)(i64FreeBytesToCaller); diskSize->avail = (int64_t)(i64FreeBytesToCaller);
diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes); diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes);
return 0; return 0;
...@@ -538,7 +539,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { ...@@ -538,7 +539,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} else { } else {
diskSize->tsize = info.f_blocks * info.f_frsize; diskSize->total = info.f_blocks * info.f_frsize;
diskSize->avail = info.f_bavail * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize;
diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize; diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize;
return 0; return 0;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(WINDOWS)
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
#else #else
#include <dlfcn.h> #include <dlfcn.h>
...@@ -25,10 +25,12 @@ ...@@ -25,10 +25,12 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#if !defined(WINDOWS)
struct termios oldtio; struct termios oldtio;
#endif
int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) { int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(WINDOWS)
FILE *fp; FILE *fp;
if (cmd == NULL) { if (cmd == NULL) {
// printf("taosSystem cmd is NULL!"); // printf("taosSystem cmd is NULL!");
...@@ -51,6 +53,7 @@ int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) { ...@@ -51,6 +53,7 @@ int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) {
} }
return 0; return 0;
}
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
printf("no support funtion"); printf("no support funtion");
return -1; return -1;
...@@ -82,7 +85,7 @@ int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) { ...@@ -82,7 +85,7 @@ int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) {
} }
void* taosLoadDll(const char* filename) { void* taosLoadDll(const char* filename) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(WINDOWS)
return NULL; return NULL;
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
return NULL; return NULL;
...@@ -252,7 +255,7 @@ void setTerminalMode() { ...@@ -252,7 +255,7 @@ void setTerminalMode() {
} }
int32_t getOldTerminalMode() { int32_t getOldTerminalMode() {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(WINDOWS)
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
/* Make sure stdin is a terminal. */ /* Make sure stdin is a terminal. */
...@@ -295,4 +298,4 @@ void resetTerminalMode() { ...@@ -295,4 +298,4 @@ void resetTerminalMode() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif #endif
} }
\ No newline at end of file
...@@ -5,6 +5,10 @@ target_include_directories( ...@@ -5,6 +5,10 @@ target_include_directories(
util util
PUBLIC "${CMAKE_SOURCE_DIR}/include/util" PUBLIC "${CMAKE_SOURCE_DIR}/include/util"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
IF(${TD_WINDOWS})
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32"
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/gnuregex"
ENDIF ()
) )
target_link_libraries( target_link_libraries(
util util
......
...@@ -351,7 +351,7 @@ static void lruListMoveToFront(SList* pList, SPageInfo* pi) { ...@@ -351,7 +351,7 @@ static void lruListMoveToFront(SList* pList, SPageInfo* pi) {
static SPageInfo* getPageInfoFromPayload(void* page) { static SPageInfo* getPageInfoFromPayload(void* page) {
int32_t offset = offsetof(SPageInfo, pData); int32_t offset = offsetof(SPageInfo, pData);
char* p = page - offset; char* p = (char *)page - offset;
SPageInfo* ppi = ((SPageInfo**)p)[0]; SPageInfo* ppi = ((SPageInfo**)p)[0];
return ppi; return ppi;
......
...@@ -628,6 +628,8 @@ void taosTmrCleanUp(void* handle) { ...@@ -628,6 +628,8 @@ void taosTmrCleanUp(void* handle) {
tmrCtrls = NULL; tmrCtrls = NULL;
unusedTmrCtrl = NULL; unusedTmrCtrl = NULL;
#if !defined(WINDOWS)
tmrModuleInit = PTHREAD_ONCE_INIT; // to support restart tmrModuleInit = PTHREAD_ONCE_INIT; // to support restart
#endif
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册