From 15fc9ccb40b91a21f893abb1325089fe1aac4f2f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 12:07:18 +0800 Subject: [PATCH 1/9] TD-4088 --- cmake/define.inc | 14 +- cmake/env.inc | 1 + src/dnode/src/dnodeCfg.c | 2 +- src/dnode/src/dnodeEps.c | 2 +- src/dnode/src/dnodeMInfos.c | 2 +- src/kit/shell/src/shellCheck.c | 2 +- src/mnode/src/mnodeUser.c | 2 +- src/os/inc/os.h | 1 + src/os/inc/osDef.h | 2 - src/os/inc/osFile.h | 63 +++---- src/os/inc/osSleep.h | 29 ++++ src/os/inc/osTimer.h | 1 - src/os/inc/osWindows.h | 2 - src/os/src/darwin/darwinFile.c | 44 ----- src/os/src/detail/osFile.c | 306 +++++++++++++++++++++++++++------ src/os/src/detail/osSleep.c | 60 +++++++ src/os/src/detail/osTimer.c | 39 ----- src/os/src/windows/wFile.c | 158 ----------------- src/os/src/windows/wTimer.c | 4 - src/query/src/qTsbuf.c | 4 +- src/rpc/test/rserver.c | 2 +- src/tsdb/inc/tsdbFile.h | 2 +- src/tsdb/src/tsdbFS.c | 2 +- src/util/src/tcache.c | 4 - src/util/src/tfile.c | 2 +- src/vnode/src/vnodeCfg.c | 2 +- src/vnode/src/vnodeVersion.c | 2 +- 27 files changed, 392 insertions(+), 362 deletions(-) create mode 100644 src/os/inc/osSleep.h create mode 100644 src/os/src/detail/osSleep.c diff --git a/cmake/define.inc b/cmake/define.inc index e825dce024..4115dd0c41 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -57,7 +57,7 @@ IF (TD_LINUX_64) ADD_DEFINITIONS(-D_M_X64) ADD_DEFINITIONS(-D_TD_LINUX_64) MESSAGE(STATUS "linux64 is defined") - SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ADD_DEFINITIONS(-DUSE_LIBICONV) ENDIF () @@ -65,7 +65,7 @@ IF (TD_LINUX_32) ADD_DEFINITIONS(-D_TD_LINUX_32) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "linux32 is defined") - SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () IF (TD_ARM_64) @@ -73,7 +73,7 @@ IF (TD_ARM_64) ADD_DEFINITIONS(-D_TD_ARM_) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "arm64 is defined") - SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () IF (TD_ARM_32) @@ -81,7 +81,7 @@ IF (TD_ARM_32) ADD_DEFINITIONS(-D_TD_ARM_) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "arm32 is defined") - SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ") + SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ") ENDIF () IF (TD_MIPS_64) @@ -89,7 +89,7 @@ IF (TD_MIPS_64) ADD_DEFINITIONS(-D_TD_MIPS_64) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "mips64 is defined") - SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () IF (TD_MIPS_32) @@ -97,7 +97,7 @@ IF (TD_MIPS_32) ADD_DEFINITIONS(-D_TD_MIPS_32) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "mips32 is defined") - SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () IF (TD_APLHINE) @@ -138,7 +138,7 @@ IF (TD_DARWIN_64) ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "darwin64 is defined") - SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) diff --git a/cmake/env.inc b/cmake/env.inc index efcc996176..3989993953 100755 --- a/cmake/env.inc +++ b/cmake/env.inc @@ -32,6 +32,7 @@ ENDIF () # # Set compiler options +SET(COMMON_C_FLAGS "${COMMON_FLAGS} -std=gnu99") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_FLAGS} ${DEBUG_FLAGS}") SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FLAGS}") diff --git a/src/dnode/src/dnodeCfg.c b/src/dnode/src/dnodeCfg.c index c573d709f5..586adacc98 100644 --- a/src/dnode/src/dnodeCfg.c +++ b/src/dnode/src/dnodeCfg.c @@ -158,7 +158,7 @@ static int32_t dnodeWriteCfg() { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fsync(fileno(fp)); + taosFsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/dnode/src/dnodeEps.c b/src/dnode/src/dnodeEps.c index 9554651776..9b15353647 100644 --- a/src/dnode/src/dnodeEps.c +++ b/src/dnode/src/dnodeEps.c @@ -277,7 +277,7 @@ static int32_t dnodeWriteEps() { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fsync(fileno(fp)); + taosFsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/dnode/src/dnodeMInfos.c b/src/dnode/src/dnodeMInfos.c index 0dca116d84..611c30b843 100644 --- a/src/dnode/src/dnodeMInfos.c +++ b/src/dnode/src/dnodeMInfos.c @@ -286,7 +286,7 @@ static int32_t dnodeWriteMInfos() { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fsync(fileno(fp)); + taosFsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/kit/shell/src/shellCheck.c b/src/kit/shell/src/shellCheck.c index b88244ea01..8f7f475536 100644 --- a/src/kit/shell/src/shellCheck.c +++ b/src/kit/shell/src/shellCheck.c @@ -142,7 +142,7 @@ static void *shellCheckThreadFp(void *arg) { taos_free_result(pSql); } - fsync(fileno(fp)); + taosFsync(fileno(fp)); fclose(fp); return NULL; diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 55ee39b6bc..e77c1b3e59 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -123,7 +123,7 @@ static void mnodePrintUserAuth() { mnodeDecUserRef(pUser); } - fsync(fileno(fp)); + taosFsync(fileno(fp)); fclose(fp); } diff --git a/src/os/inc/os.h b/src/os/inc/os.h index c3e02b14db..b71b382176 100644 --- a/src/os/inc/os.h +++ b/src/os/inc/os.h @@ -67,6 +67,7 @@ extern "C" { #include "osRand.h" #include "osSemphone.h" #include "osSignal.h" +#include "osSleep.h" #include "osSocket.h" #include "osString.h" #include "osSysinfo.h" diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index bbe0f98ec0..64ad7e55c4 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -26,8 +26,6 @@ extern "C" { #endif #endif -#define FD_VALID(x) ((x) > STDERR_FILENO) -#define FD_INITIALIZER ((int32_t)-1) // #define WCHAR wchar_t diff --git a/src/os/inc/osFile.h b/src/os/inc/osFile.h index c117ae4039..262f19ad22 100644 --- a/src/os/inc/osFile.h +++ b/src/os/inc/osFile.h @@ -22,50 +22,39 @@ extern "C" { #include "osSocket.h" -int64_t taosReadImp(int32_t fd, void *buf, int64_t count); -int64_t taosWriteImp(int32_t fd, void *buf, int64_t count); -int64_t taosLSeekImp(int32_t fd, int64_t offset, int32_t whence); -int32_t taosRenameFile(char *fullPath, char *suffix, char delimiter, char **dstPath); +#define FD_VALID(x) ((x) > STDERR_FILENO) +#define FD_INITIALIZER ((int32_t)-1) + +#ifndef PATH_MAX + #define PATH_MAX 256 +#endif + +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +typedef int32_t FileFd; +typedef SOCKET SocketFd; +#else +typedef int32_t FileFd; +typedef int32_t SocketFd; +#endif + +int64_t taosRead(FileFd fd, void *buf, int64_t count); +int64_t taosWrite(FileFd fd, void *buf, int64_t count); + +int64_t taosLSeek(FileFd fd, int64_t offset, int32_t whence); +int32_t taosFtruncate(FileFd fd, int64_t length); +int32_t taosFsync(FileFd fd); + +int32_t taosRename(char* oldName, char *newName); int64_t taosCopy(char *from, char *to); -#define taosRead(fd, buf, count) taosReadImp(fd, buf, count) -#define taosWrite(fd, buf, count) taosWriteImp(fd, buf, count) -#define taosLSeek(fd, offset, whence) taosLSeekImp(fd, offset, whence) -#define taosClose(fd) \ - { \ - if (FD_VALID(fd)) { \ - close(fd); \ - fd = FD_INITIALIZER; \ - } \ - } - -// TAOS_OS_FUNC_FILE_SENDIFLE -int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t size); +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size); int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size); -#ifdef TAOS_RANDOM_FILE_FAIL - void taosSetRandomFileFailFactor(int32_t factor); - void taosSetRandomFileFailOutput(const char *path); - #ifdef TAOS_RANDOM_FILE_FAIL_TEST - int64_t taosReadFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line); - int64_t taosWriteFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line); - int64_t taosLSeekRandomFail(int32_t fd, int64_t offset, int32_t whence, const char *file, uint32_t line); - #undef taosRead - #undef taosWrite - #undef taosLSeek - #define taosRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) - #endif -#endif - -// TAOS_OS_FUNC_FILE_GETTMPFILEPATH void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath); +void taosClose(FileFd fd); -// TAOS_OS_FUNC_FILE_FTRUNCATE -int32_t taosFtruncate(int32_t fd, int64_t length); #ifdef __cplusplus } #endif -#endif +#endif \ No newline at end of file diff --git a/src/os/inc/osSleep.h b/src/os/inc/osSleep.h new file mode 100644 index 0000000000..e42da8d5a6 --- /dev/null +++ b/src/os/inc/osSleep.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_SLEEP_H +#define TDENGINE_OS_SLEEP_H + +#ifdef __cplusplus +extern "C" { +#endif + +void taosMsleep(int32_t ms); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/os/inc/osTimer.h b/src/os/inc/osTimer.h index d6deae2a6d..413db51c31 100644 --- a/src/os/inc/osTimer.h +++ b/src/os/inc/osTimer.h @@ -21,7 +21,6 @@ extern "C" { #endif // TAOS_OS_FUNC_TIMER -void taosMsleep(int mseconds); int taosInitTimer(void (*callback)(int), int ms); void taosUninitTimer(); diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index a058f2cc99..68b6834def 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -133,7 +133,6 @@ char *stpncpy (char *dest, const char *src, size_t n); #define MILLISECOND_PER_SECOND (1000i64) #endif -#define TAOS_OS_FUNC_TIMER_SLEEP #define TAOS_OS_FUNC_TIMER // specific @@ -154,7 +153,6 @@ char * strptime(const char *buf, const char *fmt, struct tm *tm); char * strsep(char **stringp, const char *delim); char * getpass(const char *prefix); int flock(int fd, int option); -int fsync(int filedes); char * strndup(const char *s, size_t n); int gettimeofday(struct timeval *ptv, void *pTimeZone); diff --git a/src/os/src/darwin/darwinFile.c b/src/os/src/darwin/darwinFile.c index 4236ea1c5f..bcca3fa53d 100644 --- a/src/os/src/darwin/darwinFile.c +++ b/src/os/src/darwin/darwinFile.c @@ -17,49 +17,5 @@ #include "os.h" #include "tulog.h" -int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) { - int r = 0; - if (offset) { - r = fseek(in_file, *offset, SEEK_SET); - if (r==-1) return -1; - } - off_t len = count; - while (len>0) { - char buf[1024*16]; - off_t n = sizeof(buf); - if (len0) { - char buf[1024*16]; - off_t n = sizeof(buf); - if (len= 0) close(fidfrom); - if (fidto >= 0) close(fidto); + if (fidfrom >= 0) taosClose(fidfrom); + if (fidto >= 0) taosClose(fidto); remove(to); return -1; } -#ifndef TAOS_OS_FUNC_FILE_SENDIFLE +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) -int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t size) { +#define _SEND_FILE_STEP_ 1000 + +int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) { + fseek(in_file, (int32_t)(*offset), 0); + int64_t writeLen = 0; + uint8_t buffer[_SEND_FILE_STEP_] = {0}; + + for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { + size_t rlen = fread(buffer, 1, _SEND_FILE_STEP_, in_file); + if (rlen <= 0) { + return writeLen; + } else if (rlen < _SEND_FILE_STEP_) { + fwrite(buffer, 1, rlen, out_file); + return (int64_t)(writeLen + rlen); + } else { + fwrite(buffer, 1, _SEND_FILE_STEP_, in_file); + writeLen += _SEND_FILE_STEP_; + } + } + + int64_t remain = count - writeLen; + if (remain > 0) { + size_t rlen = fread(buffer, 1, (size_t)remain, in_file); + if (rlen <= 0) { + return writeLen; + } else { + fwrite(buffer, 1, (size_t)remain, out_file); + writeLen += remain; + } + } + + return writeLen; +} + +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) { + if (offset != NULL) lseek(sfd, (int32_t)(*offset), 0); + + int64_t writeLen = 0; + uint8_t buffer[_SEND_FILE_STEP_] = {0}; + + for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { + int32_t rlen = (int32_t)read(sfd, buffer, _SEND_FILE_STEP_); + if (rlen <= 0) { + return writeLen; + } else if (rlen < _SEND_FILE_STEP_) { + taosWriteSocket(dfd, buffer, rlen); + return (int64_t)(writeLen + rlen); + } else { + taosWriteSocket(dfd, buffer, _SEND_FILE_STEP_); + writeLen += _SEND_FILE_STEP_; + } + } + + int64_t remain = count - writeLen; + if (remain > 0) { + int32_t rlen = read(sfd, buffer, (int32_t)remain); + if (rlen <= 0) { + return writeLen; + } else { + taosWriteSocket(sfd, buffer, (int32_t)remain); + writeLen += remain; + } + } + + return writeLen; +} + +#elif defined(_TD_DARWIN_64) + +int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) { + int r = 0; + if (offset) { + r = fseek(in_file, *offset, SEEK_SET); + if (r == -1) return -1; + } + off_t len = count; + while (len > 0) { + char buf[1024 * 16]; + off_t n = sizeof(buf); + if (len < n) n = len; + size_t m = fread(buf, 1, n, in_file); + if (m < n) { + int e = ferror(in_file); + if (e) return -1; + } + if (m == 0) break; + if (m != fwrite(buf, 1, m, out_file)) { + return -1; + } + len -= m; + } + return count - len; +} + +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) { + int r = 0; + if (offset) { + r = lseek(sfd, *offset, SEEK_SET); + if (r == -1) return -1; + } + off_t len = count; + while (len > 0) { + char buf[1024 * 16]; + off_t n = sizeof(buf); + if (len < n) n = len; + size_t m = read(sfd, buf, n); + if (m == -1) return -1; + if (m == 0) break; + size_t l = write(dfd, buf, m); + if (l == -1) return -1; + len -= l; + } + return count - len; +} + +#else + +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size) { int64_t leftbytes = size; int64_t sentbytes; @@ -188,10 +306,96 @@ int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size #endif -#ifndef TAOS_OS_FUNC_FILE_FTRUNCATE +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) -int32_t taosFtruncate(int32_t fd, int64_t length) { - return ftruncate(fd, length); +int32_t taosFtruncate(int32_t fd, int64_t l_size) { + if (fd < 0) { + errno = EBADF; + uError("%s\n", "fd arg was negative"); + return -1; + } + + HANDLE h = (HANDLE)_get_osfhandle(fd); + + LARGE_INTEGER li_0; + li_0.QuadPart = (int64_t)0; + BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT); + if (!cur) { + uError("SetFilePointerEx Error getting current position in file.\n"); + return -1; + } + + LARGE_INTEGER li_size; + li_size.QuadPart = l_size; + BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN); + if (cur2 == 0) { + int error = GetLastError(); + uError("SetFilePointerEx GetLastError is: %d\n", error); + switch (error) { + case ERROR_INVALID_HANDLE: + errno = EBADF; + break; + default: + errno = EIO; + break; + } + return -1; + } + + if (!SetEndOfFile(h)) { + int error = GetLastError(); + uError("SetEndOfFile GetLastError is:%d", error); + switch (error) { + case ERROR_INVALID_HANDLE: + errno = EBADF; + break; + default: + errno = EIO; + break; + } + return -1; + } + + return 0; } -#endif \ No newline at end of file +int32_t taosFsync(FileFd fd) { + if (fd < 0) { + errno = EBADF; + uError("%s\n", "fd arg was negative"); + return -1; + } + + HANDLE h = (HANDLE)_get_osfhandle(fd); + + return FlushFileBuffers(h); +} + +int32_t taosRename(char *oldName, char *newName) { + int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); + if (code < 0) { + uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); + } else { + uTrace("successfully to rename file %s to %s", oldName, newName); + } + + return code; +} + +#else + +int32_t taosFtruncate(FileFd fd, int64_t length) { return ftruncate(fd, length); } +int32_t taosFsync(FileFd fd) { return fsync(fd); } + +int32_t taosRename(char *oldName, char *newName) { + int32_t code = rename(oldName, newName); + if (code < 0) { + uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); + } else { + uTrace("successfully to rename file %s to %s", oldName, newName); + } + + return code; +} + +#endif diff --git a/src/os/src/detail/osSleep.c b/src/os/src/detail/osSleep.c new file mode 100644 index 0000000000..e5d469f9a1 --- /dev/null +++ b/src/os/src/detail/osSleep.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "os.h" + +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + +void taosMsleep(int32_t ms) { Sleep(ms); } + +#else + +/* + to make taosMsleep work, + signal SIGALRM shall be blocked in the calling thread, + + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGALRM); + pthread_sigmask(SIG_BLOCK, &set, NULL); +*/ +void taosMsleep(int32_t mseconds) { +#ifdef _TD_DARWIN_64 + taos_block_sigalrm(); +#endif +#if 1 + usleep(mseconds * 1000); +#else + struct timeval timeout; + int32_t seconds, useconds; + + seconds = mseconds / 1000; + useconds = (mseconds % 1000) * 1000; + timeout.tv_sec = seconds; + timeout.tv_usec = useconds; + + /* sigset_t set; */ + /* sigemptyset(&set); */ + /* sigaddset(&set, SIGALRM); */ + /* pthread_sigmask(SIG_BLOCK, &set, NULL); */ + + select(0, NULL, NULL, NULL, &timeout); + +/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */ +#endif +} + +#endif diff --git a/src/os/src/detail/osTimer.c b/src/os/src/detail/osTimer.c index c1135ce292..387daab3e6 100644 --- a/src/os/src/detail/osTimer.c +++ b/src/os/src/detail/osTimer.c @@ -104,42 +104,3 @@ void taosUninitTimer() { } #endif - -#ifndef TAOS_OS_FUNC_TIMER_SLEEP -/* - to make taosMsleep work, - signal SIGALRM shall be blocked in the calling thread, - - sigset_t set; - sigemptyset(&set); - sigaddset(&set, SIGALRM); - pthread_sigmask(SIG_BLOCK, &set, NULL); -*/ -void taosMsleep(int mseconds) { -#ifdef __APPLE__ - taos_block_sigalrm(); -#endif // __APPLE__ -#if 1 - usleep(mseconds * 1000); -#else - struct timeval timeout; - int seconds, useconds; - - seconds = mseconds / 1000; - useconds = (mseconds % 1000) * 1000; - timeout.tv_sec = seconds; - timeout.tv_usec = useconds; - - /* sigset_t set; */ - /* sigemptyset(&set); */ - /* sigaddset(&set, SIGALRM); */ - /* pthread_sigmask(SIG_BLOCK, &set, NULL); */ - - select(0, NULL, NULL, NULL, &timeout); - -/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */ -#endif - -} - -#endif diff --git a/src/os/src/windows/wFile.c b/src/os/src/windows/wFile.c index 3bfe1c1b5d..ee97062b38 100644 --- a/src/os/src/windows/wFile.c +++ b/src/os/src/windows/wFile.c @@ -19,166 +19,8 @@ #include "tglobal.h" #include "tulog.h" -void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { - const char *tdengineTmpFileNamePrefix = "tdengine-"; - char tmpPath[PATH_MAX]; - int32_t len = (int32_t)strlen(tsTempDir); - memcpy(tmpPath, tsTempDir, len); - if (tmpPath[len - 1] != '/' && tmpPath[len - 1] != '\\') { - tmpPath[len++] = '\\'; - } - strcpy(tmpPath + len, tdengineTmpFileNamePrefix); - strcat(tmpPath, tdengineTmpFileNamePrefix); - if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { - strcat(tmpPath, fileNamePrefix); - strcat(tmpPath, "-%d-%s"); - } - char rand[8] = {0}; - taosRandStr(rand, tListLen(rand) - 1); - snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); -} -#define _SEND_FILE_STEP_ 1000 - -int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) { - fseek(in_file, (int32_t)(*offset), 0); - int64_t writeLen = 0; - uint8_t buffer[_SEND_FILE_STEP_] = {0}; - - for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { - size_t rlen = fread(buffer, 1, _SEND_FILE_STEP_, in_file); - if (rlen <= 0) { - return writeLen; - } else if (rlen < _SEND_FILE_STEP_) { - fwrite(buffer, 1, rlen, out_file); - return (int64_t)(writeLen + rlen); - } else { - fwrite(buffer, 1, _SEND_FILE_STEP_, in_file); - writeLen += _SEND_FILE_STEP_; - } - } - - int64_t remain = count - writeLen; - if (remain > 0) { - size_t rlen = fread(buffer, 1, (size_t)remain, in_file); - if (rlen <= 0) { - return writeLen; - } else { - fwrite(buffer, 1, (size_t)remain, out_file); - writeLen += remain; - } - } - - return writeLen; -} - -int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t count) { - if (offset != NULL) lseek(sfd, (int32_t)(*offset), 0); - - int64_t writeLen = 0; - uint8_t buffer[_SEND_FILE_STEP_] = {0}; - - for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { - int32_t rlen = (int32_t)read(sfd, buffer, _SEND_FILE_STEP_); - if (rlen <= 0) { - return writeLen; - } else if (rlen < _SEND_FILE_STEP_) { - taosWriteSocket(dfd, buffer, rlen); - return (int64_t)(writeLen + rlen); - } else { - taosWriteSocket(dfd, buffer, _SEND_FILE_STEP_); - writeLen += _SEND_FILE_STEP_; - } - } - - int64_t remain = count - writeLen; - if (remain > 0) { - int32_t rlen = read(sfd, buffer, (int32_t)remain); - if (rlen <= 0) { - return writeLen; - } else { - taosWriteSocket(sfd, buffer, (int32_t)remain); - writeLen += remain; - } - } - - return writeLen; -} - -int32_t taosFtruncate(int32_t fd, int64_t l_size) { - if (fd < 0) { - errno = EBADF; - uError("%s\n", "fd arg was negative"); - return -1; - } - - HANDLE h = (HANDLE)_get_osfhandle(fd); - - LARGE_INTEGER li_0; - li_0.QuadPart = (int64_t)0; - BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT); - if (!cur) { - uError("SetFilePointerEx Error getting current position in file.\n"); - return -1; - } - - LARGE_INTEGER li_size; - li_size.QuadPart = l_size; - BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN); - if (cur2 == 0) { - int error = GetLastError(); - uError("SetFilePointerEx GetLastError is: %d\n", error); - switch (error) { - case ERROR_INVALID_HANDLE: - errno = EBADF; - break; - default: - errno = EIO; - break; - } - return -1; - } - - if (!SetEndOfFile(h)) { - int error = GetLastError(); - uError("SetEndOfFile GetLastError is:%d", error); - switch (error) { - case ERROR_INVALID_HANDLE: - errno = EBADF; - break; - default: - errno = EIO; - break; - } - return -1; - } - - return 0; -} - -int fsync(int filedes) { - if (filedes < 0) { - errno = EBADF; - uError("%s\n", "fd arg was negative"); - return -1; - } - - HANDLE h = (HANDLE)_get_osfhandle(filedes); - - return FlushFileBuffers(h); -} - -int32_t taosRename(char* oldName, char *newName) { - int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); - if (code < 0) { - uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); - } else { - uTrace("successfully to rename file %s to %s", oldName, newName); - } - - return code; -} \ No newline at end of file diff --git a/src/os/src/windows/wTimer.c b/src/os/src/windows/wTimer.c index 32e04746f1..c5984f915a 100644 --- a/src/os/src/windows/wTimer.c +++ b/src/os/src/windows/wTimer.c @@ -43,7 +43,3 @@ int taosInitTimer(win_timer_f callback, int ms) { void taosUninitTimer() { timeKillEvent(timerId); } - -void taosMsleep(int mseconds) { - Sleep(mseconds); -} diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index 1f43c5b33c..5d599ff08a 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -484,7 +484,7 @@ void tsBufFlush(STSBuf* pTSBuf) { .magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder}; STSBufUpdateHeader(pTSBuf, &header); - fsync(fileno(pTSBuf->f)); + taosFsync(fileno(pTSBuf->f)); } static int32_t tsBufFindGroupById(STSGroupBlockInfoEx* pGroupInfoEx, int32_t numOfGroups, int32_t id) { @@ -868,7 +868,7 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_ .magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder}; STSBufUpdateHeader(pTSBuf, &header); - fsync(fileno(pTSBuf->f)); + taosFsync(fileno(pTSBuf->f)); return pTSBuf; } diff --git a/src/rpc/test/rserver.c b/src/rpc/test/rserver.c index 44c5cd6ab4..64960db044 100644 --- a/src/rpc/test/rserver.c +++ b/src/rpc/test/rserver.c @@ -52,7 +52,7 @@ void processShellMsg() { if (commit >=2) { num += numOfMsgs; - if ( fsync(dataFd) < 0 ) { + if ( taosFsync(dataFd) < 0 ) { tInfo("failed to flush data to file, reason:%s", strerror(errno)); } diff --git a/src/tsdb/inc/tsdbFile.h b/src/tsdb/inc/tsdbFile.h index 792efcdb2e..dcb5eadfab 100644 --- a/src/tsdb/inc/tsdbFile.h +++ b/src/tsdb/inc/tsdbFile.h @@ -32,7 +32,7 @@ #define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_FD(f) = -1) #define TSDB_FILE_LEVEL(tf) TFILE_LEVEL(TSDB_FILE_F(tf)) #define TSDB_FILE_ID(tf) TFILE_ID(TSDB_FILE_F(tf)) -#define TSDB_FILE_FSYNC(tf) fsync(TSDB_FILE_FD(tf)) +#define TSDB_FILE_FSYNC(tf) taosFsync(TSDB_FILE_FD(tf)) #define TSDB_FILE_STATE(tf) ((tf)->state) #define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s)) #define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index c9f087a5cf..f6e721e3d3 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -390,7 +390,7 @@ static int tsdbSaveFSStatus(SFSStatus *pStatus, int vid) { } // fsync, close and rename - if (fsync(fd) < 0) { + if (taosFsync(fd) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); close(fd); remove(tfname); diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index c0cc8ce339..57d45cc8c0 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -661,11 +661,7 @@ void* taosCacheTimedRefresh(void *handle) { int64_t count = 0; while(1) { -#if defined LINUX - usleep(500*1000); -#else taosMsleep(500); -#endif // check if current cache object will be deleted every 500ms. if (pCacheObj->deleting) { diff --git a/src/util/src/tfile.c b/src/util/src/tfile.c index dd621b3199..455c885e75 100644 --- a/src/util/src/tfile.c +++ b/src/util/src/tfile.c @@ -98,7 +98,7 @@ int32_t tfFsync(int64_t tfd) { if (p == NULL) return -1; int32_t fd = (int32_t)(uintptr_t)p; - int32_t code = fsync(fd); + int32_t code = taosFsync(fd); taosReleaseRef(tsFileRsetId, tfd); return code; diff --git a/src/vnode/src/vnodeCfg.c b/src/vnode/src/vnodeCfg.c index c9cd366c64..2e1d761fcf 100644 --- a/src/vnode/src/vnodeCfg.c +++ b/src/vnode/src/vnodeCfg.c @@ -362,7 +362,7 @@ int32_t vnodeWriteCfg(SCreateVnodeMsg *pMsg) { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fsync(fileno(fp)); + taosFsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/vnode/src/vnodeVersion.c b/src/vnode/src/vnodeVersion.c index d22bc17cbe..d1aee5a3d3 100644 --- a/src/vnode/src/vnodeVersion.c +++ b/src/vnode/src/vnodeVersion.c @@ -90,7 +90,7 @@ int32_t vnodeSaveVersion(SVnodeObj *pVnode) { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fsync(fileno(fp)); + taosFsync(fileno(fp)); fclose(fp); free(content); terrno = 0; From 18fdb96a0a85bcd76188e8fa1b31e8db6e839dae Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 13:18:47 +0800 Subject: [PATCH 2/9] TD-4088 --- src/os/inc/os.h | 1 - src/os/inc/osCommon.h | 31 ------------------------ src/os/inc/osDef.h | 4 ++++ src/os/inc/osDir.h | 11 ++++----- src/os/inc/osLinux32.h | 6 ----- src/os/inc/osLz4.h | 17 ++++++++++++- src/os/inc/osMath.h | 44 +++++++++++++++++++++------------- src/os/inc/osWindows.h | 19 --------------- src/os/src/darwin/darwinFile.c | 21 ---------------- src/os/src/detail/osDir.c | 20 ++-------------- src/os/src/windows/wFile.c | 26 -------------------- 11 files changed, 54 insertions(+), 146 deletions(-) delete mode 100644 src/os/inc/osCommon.h delete mode 100644 src/os/src/darwin/darwinFile.c delete mode 100644 src/os/src/windows/wFile.c diff --git a/src/os/inc/os.h b/src/os/inc/os.h index b71b382176..6006f1b969 100644 --- a/src/os/inc/os.h +++ b/src/os/inc/os.h @@ -58,7 +58,6 @@ extern "C" { #include "osDef.h" #include "osAtomic.h" -#include "osCommon.h" #include "osDir.h" #include "osFile.h" #include "osLz4.h" diff --git a/src/os/inc/osCommon.h b/src/os/inc/osCommon.h deleted file mode 100644 index 70d2b2c0c2..0000000000 --- a/src/os/inc/osCommon.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TDENGINE_OS_COMMON_H -#define TDENGINE_OS_COMMON_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef TAOS_OS_DEF_ZU - #define PRIzu "zu" -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index 64ad7e55c4..ac7aac0afa 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -111,6 +111,10 @@ extern "C" { #define threadlocal __declspec( thread ) #endif +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #define PRIzu "ld" +#endif + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osDir.h b/src/os/inc/osDir.h index 540efc310c..bdc65e4520 100644 --- a/src/os/inc/osDir.h +++ b/src/os/inc/osDir.h @@ -20,13 +20,10 @@ extern "C" { #endif -#include - -// TAOS_OS_FUNC_DIR -void taosRemoveDir(char *rootDir); -int taosMkDir(const char *pathname, mode_t mode); -void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays); -int32_t taosRename(char* oldName, char *newName); +void taosRemoveDir(char *rootDir); +int32_t taosMkDir(const char *pathname, mode_t mode); +void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays); +int32_t taosRename(char *oldName, char *newName); int32_t taosCompressFile(char *srcFileName, char *destFileName); #ifdef __cplusplus diff --git a/src/os/inc/osLinux32.h b/src/os/inc/osLinux32.h index eee4999399..6d9a01a9a8 100644 --- a/src/os/inc/osLinux32.h +++ b/src/os/inc/osLinux32.h @@ -79,12 +79,6 @@ extern "C" { #include #include -#define TAOS_OS_FUNC_LZ4 -#define BUILDIN_CLZL(val) __builtin_clzll(val) -#define BUILDIN_CTZL(val) __builtin_ctzll(val) -#define BUILDIN_CLZ(val) __builtin_clz(val) -#define BUILDIN_CTZ(val) __builtin_ctz(val) - #ifdef __cplusplus } #endif diff --git a/src/os/inc/osLz4.h b/src/os/inc/osLz4.h index a944892c48..8363861e03 100644 --- a/src/os/inc/osLz4.h +++ b/src/os/inc/osLz4.h @@ -20,7 +20,22 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_LZ4 +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + int32_t BUILDIN_CLZL(uint64_t val); + int32_t BUILDIN_CLZ(uint32_t val); + int32_t BUILDIN_CTZL(uint64_t val); + int32_t BUILDIN_CTZ(uint32_t val); +#elif defined (_TD_LINUX_32) + #define BUILDIN_CLZL(val) __builtin_clzll(val) + #define BUILDIN_CTZL(val) __builtin_ctzll(val) + #define BUILDIN_CLZ(val) __builtin_clz(val) + #define BUILDIN_CTZ(val) __builtin_ctz(val) +#elif defined (_TD_ARM_32) + #define BUILDIN_CLZL(val) __builtin_clzll(val) + #define BUILDIN_CTZL(val) __builtin_ctzll(val) + #define BUILDIN_CLZ(val) __builtin_clz(val) + #define BUILDIN_CTZ(val) __builtin_ctz(val) +#else #define BUILDIN_CLZL(val) __builtin_clzl(val) #define BUILDIN_CTZL(val) __builtin_ctzl(val) #define BUILDIN_CLZ(val) __builtin_clz(val) diff --git a/src/os/inc/osMath.h b/src/os/inc/osMath.h index 9935f94d39..65e8a1f6fe 100644 --- a/src/os/inc/osMath.h +++ b/src/os/inc/osMath.h @@ -23,26 +23,38 @@ extern "C" { #define POW2(x) ((x) * (x)) #define ABS(x) ((x) > 0 ? (x) : -(x)) -#ifndef TAOS_OS_FUNC_MATH - #define SWAP(a, b, c) \ - do { \ - typeof(a) __tmp = (a); \ - (a) = (b); \ - (b) = __tmp; \ +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + + #define SWAP(a, b, c) \ + do { \ + c __tmp = (c)(a); \ + (a) = (c)(b); \ + (b) = __tmp; \ + } while (0) + #define MAX(a, b) (((a) > (b)) ? (a) : (b)) + #define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +#else + + #define SWAP(a, b, c) \ + do { \ + typeof(a) __tmp = (a); \ + (a) = (b); \ + (b) = __tmp; \ } while (0) - #define MAX(a, b) \ - ({ \ - typeof(a) __a = (a); \ - typeof(b) __b = (b); \ - (__a > __b) ? __a : __b; \ + #define MAX(a, b) \ + ({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + (__a > __b) ? __a : __b; \ }) - #define MIN(a, b) \ - ({ \ - typeof(a) __a = (a); \ - typeof(b) __b = (b); \ - (__a < __b) ? __a : __b; \ + #define MIN(a, b) \ + ({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + (__a < __b) ? __a : __b; \ }) #endif diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index 68b6834def..5fd32711f9 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -55,11 +55,6 @@ extern "C" { #endif -#define TAOS_OS_FUNC_LZ4 - int32_t BUILDIN_CLZL(uint64_t val); - int32_t BUILDIN_CLZ(uint32_t val); - int32_t BUILDIN_CTZL(uint64_t val); - int32_t BUILDIN_CTZ(uint32_t val); #define TAOS_OS_FUNC_FILE #define TAOS_OS_FUNC_FILE_ISREG @@ -69,17 +64,6 @@ extern "C" { #define TAOS_OS_FUNC_FILE_GETTMPFILEPATH #define TAOS_OS_FUNC_FILE_FTRUNCATE -#define TAOS_OS_FUNC_DIR - -#define TAOS_OS_FUNC_MATH - #define SWAP(a, b, c) \ - do { \ - c __tmp = (c)(a); \ - (a) = (c)(b); \ - (b) = __tmp; \ - } while (0) - #define MAX(a,b) (((a)>(b))?(a):(b)) - #define MIN(a,b) (((a)<(b))?(a):(b)) #define TAOS_OS_FUNC_SEMPHONE_PTHREAD @@ -104,9 +88,6 @@ typedef SOCKET eventfd_t; #define EPOLLWAKEUP (1u << 29) #endif -#define TAOS_OS_DEF_ZU - #define PRIzu "ld" - #define TAOS_OS_FUNC_STRING_WCHAR int twcslen(const wchar_t *wcs); #define TAOS_OS_FUNC_STRING_GETLINE diff --git a/src/os/src/darwin/darwinFile.c b/src/os/src/darwin/darwinFile.c deleted file mode 100644 index bcca3fa53d..0000000000 --- a/src/os/src/darwin/darwinFile.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "tulog.h" - - - diff --git a/src/os/src/detail/osDir.c b/src/os/src/detail/osDir.c index 144c59fa2d..2a2e2519b5 100644 --- a/src/os/src/detail/osDir.c +++ b/src/os/src/detail/osDir.c @@ -28,7 +28,7 @@ void taosRemoveDir(char *rootDir) { struct dirent *de = NULL; while ((de = readdir(dir)) != NULL) { if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; - + char filename[1024]; snprintf(filename, 1023, "%s/%s", rootDir, de->d_name); if (de->d_type & DT_DIR) { @@ -51,27 +51,11 @@ int taosMkDir(const char *path, mode_t mode) { return code; } - -#ifndef TAOS_OS_FUNC_DIR - -int32_t taosRename(char* oldName, char *newName) { - int32_t code = rename(oldName, newName); - if (code < 0) { - uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); - } else { - uTrace("successfully to rename file %s to %s", oldName, newName); - } - - return code; -} - -#endif - void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) { DIR *dir = opendir(rootDir); if (dir == NULL) return; - int64_t sec = taosGetTimestampSec(); + int64_t sec = taosGetTimestampSec(); struct dirent *de = NULL; while ((de = readdir(dir)) != NULL) { diff --git a/src/os/src/windows/wFile.c b/src/os/src/windows/wFile.c deleted file mode 100644 index ee97062b38..0000000000 --- a/src/os/src/windows/wFile.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "osSocket.h" -#include "tglobal.h" -#include "tulog.h" - - - - - - From ac3d6440c839c0fada3204702b2b7737bf3d8044 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 14:58:57 +0800 Subject: [PATCH 3/9] TD-4088 --- src/client/src/tscParseInsert.c | 2 +- src/os/inc/osDarwin.h | 4 ---- src/os/inc/osDef.h | 2 +- src/os/inc/osMemory.h | 12 +--------- src/os/inc/osRand.h | 3 +-- src/os/inc/osSocket.h | 10 ++++++++ src/os/inc/osString.h | 39 ++++++++++++++------------------ src/os/inc/osWindows.h | 14 ------------ src/os/src/darwin/darwinString.c | 22 ------------------ src/os/src/detail/osRand.c | 4 ---- src/os/src/detail/osString.c | 10 ++++---- src/os/src/windows/wGetline.c | 22 ++++++++---------- src/os/src/windows/wGodll.c | 33 --------------------------- src/os/src/windows/wSocket.c | 8 ++++++- src/os/src/windows/wString.c | 15 ++++++------ 15 files changed, 60 insertions(+), 140 deletions(-) delete mode 100644 src/os/src/darwin/darwinString.c delete mode 100644 src/os/src/windows/wGodll.c diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 6b88c90747..d8b40f397f 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -68,7 +68,7 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1 } else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) { // do nothing } else if (pToken->type == TK_INTEGER) { - useconds = tsosStr2int64(pToken->z); + useconds = taosStr2int64(pToken->z); } else { // strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm); if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) { diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index 7c206afe7a..f8e3c65d63 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -82,13 +82,11 @@ extern "C" { int tsem_destroy(tsem_t *sem); #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT -#define TAOS_OS_FUNC_STRING_STR2INT64 #define TAOS_OS_FUNC_SYSINFO #define TAOS_OS_FUNC_TIMER #define TAOS_OS_FUNC_SEMPHONE_PTHREAD // specific -#define htobe64 htonll typedef int(*__compar_fn_t)(const void *, const void *); // for send function in tsocket.c @@ -108,8 +106,6 @@ typedef int(*__compar_fn_t)(const void *, const void *); #define TAOS_OS_FUNC_PTHREAD_RWLOCK -int64_t tsosStr2int64(char *str); - #include "eok.h" void taos_block_sigalrm(void); diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index ac7aac0afa..7604100e0a 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -111,7 +111,7 @@ extern "C" { #define threadlocal __declspec( thread ) #endif -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) #define PRIzu "ld" #endif diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h index 2cf7e14d2f..27efd9f505 100644 --- a/src/os/inc/osMemory.h +++ b/src/os/inc/osMemory.h @@ -43,9 +43,6 @@ void taosTMemset(void *ptr, int c); #define tmalloc(size) malloc(size) #define tcalloc(num, size) calloc(num, size) #define trealloc(ptr, size) realloc(ptr, size) -#define tstrdup(str) taosStrdupImp(str) -#define tstrndup(str, size) taosStrndupImp(str, size) -#define tgetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream) #define tfree(x) \ do { \ if (x) { \ @@ -71,15 +68,8 @@ void taosTMemset(void *ptr, int c); #define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__) #define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__) #define tfree(ptr) taosFreeMem(ptr, __FILE__, __LINE__) - - // #undef tstrdup - // #undef tstrndup - // #undef tgetline - // #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) - // #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) - // #define tgetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) #endif -#endif +#endif #ifdef __cplusplus } diff --git a/src/os/inc/osRand.h b/src/os/inc/osRand.h index 803c0688bb..e08768c2cc 100644 --- a/src/os/inc/osRand.h +++ b/src/os/inc/osRand.h @@ -20,9 +20,8 @@ extern "C" { #endif -// TAOS_OS_FUNC_RAND uint32_t taosRand(void); -void taosRandStr(char* str, int32_t size); +void taosRandStr(char* str, int32_t size); uint32_t taosSafeRand(void); #ifdef __cplusplus diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index cf75b74a9a..e60028337f 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -74,6 +74,16 @@ int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op uint32_t taosInetAddr(char *ipAddr); const char *taosInetNtoa(struct in_addr ipInt); + +#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) + #define htobe64 htonll + #if defined(_TD_GO_DLL_) + uint64_t htonll(uint64_t val); + #endif +#elif defined(_TD_DARWIN_64) + #define htobe64 htonll +#endif + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osString.h b/src/os/inc/osString.h index 97966ed412..f2e8b381fe 100644 --- a/src/os/inc/osString.h +++ b/src/os/inc/osString.h @@ -20,35 +20,30 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_STRING_STRDUP - #define taosStrdupImp(str) strdup(str) - #define taosStrndupImp(str, size) strndup(str, size) -#endif - -#ifndef TAOS_OS_FUNC_STRING_GETLINE - #define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream) -#else - int taosGetlineImp(char **lineptr, size_t *n, FILE *stream); -#endif - -#ifndef TAOS_OS_FUNC_STRING_WCHAR +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #define tstrdup(str) _strdup(str) + #define tstrndup(str, size) _strndup(str, size) + int32_t tgetline(char **lineptr, size_t *n, FILE *stream); + int32_t twcslen(const wchar_t *wcs); +#else + #define tstrdup(str) strdup(str) + #define tstrndup(str, size) strndup(str, size) + #define tgetline(lineptr, n, stream) getline(lineptr, n , stream) #define twcslen wcslen -#endif +#endif -#define tstrncpy(dst, src, size) \ - do { \ - strncpy((dst), (src), (size)); \ - (dst)[(size)-1] = 0; \ +#define tstrncpy(dst, src, size) \ + do { \ + strncpy((dst), (src), (size)); \ + (dst)[(size)-1] = 0; \ } while (0) -#ifndef TAOS_OS_FUNC_STRING_STR2INT64 - int64_t tsosStr2int64(char *str); -#endif +int64_t taosStr2int64(char *str); // USE_LIBICONV int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); -bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int *len); -int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes); +bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len); +int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes); bool taosValidateEncodec(const char *encodec); char * taosCharsetReplace(char *charsetstr); diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index 5fd32711f9..f90ae6f059 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -88,19 +88,6 @@ typedef SOCKET eventfd_t; #define EPOLLWAKEUP (1u << 29) #endif -#define TAOS_OS_FUNC_STRING_WCHAR - int twcslen(const wchar_t *wcs); -#define TAOS_OS_FUNC_STRING_GETLINE -#define TAOS_OS_FUNC_STRING_STR2INT64 - #ifdef _TD_GO_DLL_ - int64_t tsosStr2int64(char *str); - uint64_t htonll(uint64_t val); - #else - #define tsosStr2int64 _atoi64 - #endif -#define TAOS_OS_FUNC_STRING_STRDUP - #define taosStrdupImp(str) _strdup(str) - #define taosStrndupImp(str, size) _strndup(str, size) char *stpcpy (char *dest, const char *src); char *stpncpy (char *dest, const char *src, size_t n); @@ -127,7 +114,6 @@ typedef int (*__compar_fn_t)(const void *, const void *); #define snprintf _snprintf #define in_addr_t unsigned long #define socklen_t int -#define htobe64 htonll struct tm *localtime_r(const time_t *timep, struct tm *result); char * strptime(const char *buf, const char *fmt, struct tm *tm); diff --git a/src/os/src/darwin/darwinString.c b/src/os/src/darwin/darwinString.c deleted file mode 100644 index 3042e78666..0000000000 --- a/src/os/src/darwin/darwinString.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" - -int64_t tsosStr2int64(char *str) { - char *endptr = NULL; - return strtoll(str, &endptr, 10); -} diff --git a/src/os/src/detail/osRand.c b/src/os/src/detail/osRand.c index b322a88684..0dda908bb3 100644 --- a/src/os/src/detail/osRand.c +++ b/src/os/src/detail/osRand.c @@ -16,8 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" -#ifndef TAOS_OS_FUNC_RAND - uint32_t taosRand(void) { return rand(); } uint32_t taosSafeRand(void) { @@ -38,8 +36,6 @@ uint32_t taosSafeRand(void) { return (uint32_t)seed; } -#endif - void taosRandStr(char* str, int32_t size) { const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_."; int32_t len = 39; diff --git a/src/os/src/detail/osString.c b/src/os/src/detail/osString.c index 59f47b4815..2c49797d83 100644 --- a/src/os/src/detail/osString.c +++ b/src/os/src/detail/osString.c @@ -17,17 +17,17 @@ #include "os.h" #include "tglobal.h" -#ifndef TAOS_OS_FUNC_STRING_STR2INT64 -int64_t tsosStr2int64(char *str) { +int64_t taosStr2int64(char *str) { char *endptr = NULL; return strtoll(str, &endptr, 10); } -#endif -#ifndef TAOS_OS_FUNC_STRING_WCHAR -int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) + +int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) { return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / TSDB_NCHAR_SIZE); } + #endif #ifdef USE_LIBICONV diff --git a/src/os/src/windows/wGetline.c b/src/os/src/windows/wGetline.c index 3e8701e19b..b9d8ccf928 100644 --- a/src/os/src/windows/wGetline.c +++ b/src/os/src/windows/wGetline.c @@ -40,10 +40,10 @@ null terminator), or -1 on error or EOF. On a -1 return, the caller should check feof(), if not then errno has been set to indicate the error. */ -int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) { - int nchars_avail; /* Allocated but unused chars in *LINEPTR. */ - char *read_pos; /* Where we're reading into *LINEPTR. */ - int ret; +int32_t getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int32_t offset) { + int32_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */ + char * read_pos; /* Where we're reading into *LINEPTR. */ + int32_t ret; if (!lineptr || !n || !stream) { errno = EINVAL; @@ -59,12 +59,12 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) } } - nchars_avail = (int)(*n - offset); + nchars_avail = (int32_t)(*n - offset); read_pos = *lineptr + offset; for (;;) { - int save_errno; - register int c = getc(stream); + int32_t save_errno; + register int32_t c = getc(stream); save_errno = errno; @@ -79,7 +79,7 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) else *n += MIN_CHUNK; - nchars_avail = (int)(*n + *lineptr - read_pos); + nchars_avail = (int32_t)(*n + *lineptr - read_pos); *lineptr = realloc(*lineptr, *n); if (!*lineptr) { errno = ENOMEM; @@ -115,10 +115,8 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) /* Done - NUL terminate and return the number of chars read. */ *read_pos = '\0'; - ret = (int)(read_pos - (*lineptr + offset)); + ret = (int32_t)(read_pos - (*lineptr + offset)); return ret; } -int taosGetlineImp(char **lineptr, size_t *n, FILE *stream) { - return getstr(lineptr, n, stream, '\n', 0); -} \ No newline at end of file +int32_t tgetline(char **lineptr, size_t *n, FILE *stream) { return getstr(lineptr, n, stream, '\n', 0); } \ No newline at end of file diff --git a/src/os/src/windows/wGodll.c b/src/os/src/windows/wGodll.c deleted file mode 100644 index b270dab2f4..0000000000 --- a/src/os/src/windows/wGodll.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "taosdef.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#ifdef _TD_GO_DLL_ -int64_t tsosStr2int64(char *str) { - char *endptr = NULL; - return strtoll(str, &endptr, 10); -} - -uint64_t htonll(uint64_t val) { - return (((uint64_t) htonl(val)) << 32) + htonl(val >> 32); -} -#endif diff --git a/src/os/src/windows/wSocket.c b/src/os/src/windows/wSocket.c index 4e6ee15e77..e152f40f03 100644 --- a/src/os/src/windows/wSocket.c +++ b/src/os/src/windows/wSocket.c @@ -88,4 +88,10 @@ const char *taosInetNtoa(struct in_addr ipInt) { return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); } -#endif \ No newline at end of file +#endif + +#if defined(_TD_GO_DLL_) + +uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); } + +#endif diff --git a/src/os/src/windows/wString.c b/src/os/src/windows/wString.c index 67237e655c..96a604ae6e 100644 --- a/src/os/src/windows/wString.c +++ b/src/os/src/windows/wString.c @@ -33,9 +33,9 @@ * If *stringp is NULL, strsep returns NULL. */ char *strsep(char **stringp, const char *delim) { - char *s; + char * s; const char *spanp; - int c, sc; + int32_t c, sc; char *tok; if ((s = *stringp) == NULL) return (NULL); @@ -75,13 +75,13 @@ char *getpass(const char *prefix) { return passwd; } -int twcslen(const wchar_t *wcs) { - int *wstr = (int *)wcs; +int32_t twcslen(const wchar_t *wcs) { + int32_t *wstr = (int32_t *)wcs; if (NULL == wstr) { return 0; } - int n = 0; + int32_t n = 0; while (1) { if (0 == *wstr++) { break; @@ -92,8 +92,8 @@ int twcslen(const wchar_t *wcs) { return n; } -int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { - for (int i = 0; i < bytes; ++i) { +int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) { + for (int32_t i = 0; i < bytes; ++i) { int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4); int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4); @@ -127,7 +127,6 @@ int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes) { #endif } - /* Copy memory to memory until the specified number of bytes has been copied, return pointer to following byte. Overlap is NOT handled correctly. */ From a4f75510d7f4b3dc10a1587e6f1055afae32ed8c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 15:19:15 +0800 Subject: [PATCH 4/9] TD-4088 --- src/os/inc/osDarwin.h | 12 +----------- src/os/inc/osSemphone.h | 13 +++++++++---- src/os/inc/osString.h | 2 +- src/os/inc/osWindows.h | 1 - src/os/src/darwin/darwinSemphone.c | 24 ++++++++++++------------ src/os/src/detail/osSemphone.c | 8 ++++---- src/os/src/windows/wGetline.c | 1 + 7 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index f8e3c65d63..c90f604f6e 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -74,17 +74,9 @@ extern "C" { #define TAOS_OS_FUNC_FILE_SENDIFLE -#define TAOS_OS_FUNC_SEMPHONE - typedef struct tsem_s *tsem_t; - int tsem_init(tsem_t *sem, int pshared, unsigned int value); - int tsem_wait(tsem_t *sem); - int tsem_post(tsem_t *sem); - int tsem_destroy(tsem_t *sem); - #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT #define TAOS_OS_FUNC_SYSINFO -#define TAOS_OS_FUNC_TIMER -#define TAOS_OS_FUNC_SEMPHONE_PTHREAD +#define TAOS_OS_FUNC_TIMERD // specific typedef int(*__compar_fn_t)(const void *, const void *); @@ -104,8 +96,6 @@ typedef int(*__compar_fn_t)(const void *, const void *); #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE #endif -#define TAOS_OS_FUNC_PTHREAD_RWLOCK - #include "eok.h" void taos_block_sigalrm(void); diff --git a/src/os/inc/osSemphone.h b/src/os/inc/osSemphone.h index 3332a9234b..2e2d432607 100644 --- a/src/os/inc/osSemphone.h +++ b/src/os/inc/osSemphone.h @@ -20,15 +20,21 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_SEMPHONE +#if defined (_TD_DARWIN_64) + typedef struct tsem_s *tsem_t; + int tsem_init(tsem_t *sem, int pshared, unsigned int value); + int tsem_wait(tsem_t *sem); + int tsem_post(tsem_t *sem); + int tsem_destroy(tsem_t *sem); +#else #define tsem_t sem_t #define tsem_init sem_init - int tsem_wait(tsem_t* sem); + int32_t tsem_wait(tsem_t* sem); #define tsem_post sem_post #define tsem_destroy sem_destroy #endif -#ifdef TAOS_OS_FUNC_PTHREAD_RWLOCK +#if defined (_TD_DARWIN_64) #define pthread_rwlock_t pthread_mutex_t #define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL) #define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock) @@ -43,7 +49,6 @@ extern "C" { #define pthread_spin_unlock(lock) pthread_mutex_unlock(lock) #endif -// TAOS_OS_FUNC_SEMPHONE_PTHREAD bool taosCheckPthreadValid(pthread_t thread); int64_t taosGetSelfPthreadId(); int64_t taosGetPthreadId(pthread_t thread); diff --git a/src/os/inc/osString.h b/src/os/inc/osString.h index f2e8b381fe..33f858485c 100644 --- a/src/os/inc/osString.h +++ b/src/os/inc/osString.h @@ -28,7 +28,7 @@ extern "C" { #else #define tstrdup(str) strdup(str) #define tstrndup(str, size) strndup(str, size) - #define tgetline(lineptr, n, stream) getline(lineptr, n , stream) + #define tgetline(lineptr, n, stream) getline(lineptr, n, stream) #define twcslen wcslen #endif diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index f90ae6f059..bfb3811176 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -65,7 +65,6 @@ extern "C" { #define TAOS_OS_FUNC_FILE_FTRUNCATE -#define TAOS_OS_FUNC_SEMPHONE_PTHREAD #define TAOS_OS_FUNC_SOCKET #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT diff --git a/src/os/src/darwin/darwinSemphone.c b/src/os/src/darwin/darwinSemphone.c index 5bb926732a..1805fd176f 100644 --- a/src/os/src/darwin/darwinSemphone.c +++ b/src/os/src/darwin/darwinSemphone.c @@ -37,7 +37,7 @@ static pthread_t sem_thread; static pthread_once_t sem_once; static task_t sem_port; -static volatile int sem_inited = 0; +static volatile int32_t sem_inited = 0; static semaphore_t sem_exit; static void* sem_thread_routine(void *arg) { @@ -55,7 +55,7 @@ static void* sem_thread_routine(void *arg) { } static void once_init(void) { - int r = 0; + int32_t r = 0; r = pthread_create(&sem_thread, NULL, sem_thread_routine, NULL); if (r) { fprintf(stderr, "==%s[%d]%s()==failed to create thread\n", basename(__FILE__), __LINE__, __func__); @@ -81,10 +81,10 @@ struct tsem_s { dispatch_semaphore_t sem; #endif // SEM_USE_PTHREAD - volatile unsigned int valid:1; + volatile unsigned int32_t valid:1; }; -int tsem_init(tsem_t *sem, int pshared, unsigned int value) { +int32_t tsem_init(tsem_t *sem, int32_t pshared, unsigned int32_t value) { // fprintf(stderr, "==%s[%d]%s():[%p]==creating\n", basename(__FILE__), __LINE__, __func__, sem); if (*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==already initialized\n", basename(__FILE__), __LINE__, __func__, sem); @@ -97,7 +97,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) { } #ifdef SEM_USE_PTHREAD - int r = pthread_mutex_init(&p->lock, NULL); + int32_t r = pthread_mutex_init(&p->lock, NULL); do { if (r) break; r = pthread_cond_init(&p->cond, NULL); @@ -124,7 +124,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) { p->sem = sem_open(name, O_CREAT|O_EXCL, pshared, value); p->id = id; if (p->sem!=SEM_FAILED) break; - int e = errno; + int32_t e = errno; if (e==EEXIST) continue; if (e==EINTR) continue; fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e)); @@ -158,7 +158,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) { return 0; } -int tsem_wait(tsem_t *sem) { +int32_t tsem_wait(tsem_t *sem) { if (!*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); abort(); @@ -194,7 +194,7 @@ int tsem_wait(tsem_t *sem) { #endif // SEM_USE_PTHREAD } -int tsem_post(tsem_t *sem) { +int32_t tsem_post(tsem_t *sem) { if (!*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); abort(); @@ -230,7 +230,7 @@ int tsem_post(tsem_t *sem) { #endif // SEM_USE_PTHREAD } -int tsem_destroy(tsem_t *sem) { +int32_t tsem_destroy(tsem_t *sem) { // fprintf(stderr, "==%s[%d]%s():[%p]==destroying\n", basename(__FILE__), __LINE__, __func__, sem); if (!*sem) { // fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); @@ -264,9 +264,9 @@ int tsem_destroy(tsem_t *sem) { #elif defined(SEM_USE_POSIX) char name[NAME_MAX-4]; snprintf(name, sizeof(name), "/t%ld", p->id); - int r = sem_unlink(name); + int32_t r = sem_unlink(name); if (r) { - int e = errno; + int32_t e = errno; fprintf(stderr, "==%s[%d]%s():[%p]==unlink failed[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e)); abort(); } @@ -284,7 +284,7 @@ int tsem_destroy(tsem_t *sem) { bool taosCheckPthreadValid(pthread_t thread) { uint64_t id = 0; - int r = pthread_threadid_np(thread, &id); + int32_t r = pthread_threadid_np(thread, &id); return r ? false : true; } diff --git a/src/os/src/detail/osSemphone.c b/src/os/src/detail/osSemphone.c index 2bf2f24487..06907d5258 100644 --- a/src/os/src/detail/osSemphone.c +++ b/src/os/src/detail/osSemphone.c @@ -16,9 +16,9 @@ #define _DEFAULT_SOURCE #include "os.h" -#ifndef TAOS_OS_FUNC_SEMPHONE +#if !defined (_TD_DARWIN_64) -int tsem_wait(tsem_t* sem) { +int32_t tsem_wait(tsem_t* sem) { int ret = 0; do { ret = sem_wait(sem); @@ -28,9 +28,9 @@ int tsem_wait(tsem_t* sem) { #endif -#ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64)) -bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } +bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } int64_t taosGetSelfPthreadId() { static __thread int id = 0; diff --git a/src/os/src/windows/wGetline.c b/src/os/src/windows/wGetline.c index b9d8ccf928..553aecaf0a 100644 --- a/src/os/src/windows/wGetline.c +++ b/src/os/src/windows/wGetline.c @@ -22,6 +22,7 @@ General Public License for more details. */ #include #include #include +#include #if STDC_HEADERS #include From eda9995add5a1e7e293ffcc2e3f792379130edd3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 16:02:38 +0800 Subject: [PATCH 5/9] TD-4088 --- src/os/inc/osDarwin.h | 2 +- src/os/inc/osDef.h | 4 ++- src/os/inc/osSignal.h | 4 +-- src/os/inc/osSysinfo.h | 26 +++++++++---------- src/os/inc/osTime.h | 11 ++++++-- src/os/inc/osTimer.h | 1 - src/os/inc/osWindows.h | 13 ---------- src/os/src/darwin/{darwinEnv.c => dwEnv.c} | 0 .../darwin/{darwinSemphone.c => dwSemphone.c} | 0 .../src/darwin/{darwinSocket.c => dwSocket.c} | 0 .../darwin/{darwinSysInfo.c => dwSysInfo.c} | 0 .../src/darwin/{darwinTimer.c => dwTimer.c} | 0 src/os/src/detail/osSignal.c | 4 ++- src/os/src/detail/osSysinfo.c | 2 +- src/os/src/detail/osTimer.c | 2 +- 15 files changed, 31 insertions(+), 38 deletions(-) rename src/os/src/darwin/{darwinEnv.c => dwEnv.c} (100%) rename src/os/src/darwin/{darwinSemphone.c => dwSemphone.c} (100%) rename src/os/src/darwin/{darwinSocket.c => dwSocket.c} (100%) rename src/os/src/darwin/{darwinSysInfo.c => dwSysInfo.c} (100%) rename src/os/src/darwin/{darwinTimer.c => dwTimer.c} (100%) diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index c90f604f6e..cfbb80fcd4 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -75,7 +75,7 @@ extern "C" { #define TAOS_OS_FUNC_FILE_SENDIFLE #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT -#define TAOS_OS_FUNC_SYSINFO + #define TAOS_OS_FUNC_TIMERD // specific diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index 7604100e0a..def4a72751 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -111,8 +111,10 @@ extern "C" { #define threadlocal __declspec( thread ) #endif -#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #define PRIzu "ld" +#else + #define PRIzu "zu" #endif #ifdef __cplusplus diff --git a/src/os/inc/osSignal.h b/src/os/inc/osSignal.h index c13cd83178..eca1d3b3f6 100644 --- a/src/os/inc/osSignal.h +++ b/src/os/inc/osSignal.h @@ -20,8 +20,6 @@ extern "C" { #endif -#include "os.h" -#include "taosdef.h" #include #ifndef SIGALRM @@ -57,4 +55,4 @@ void taosDflSignal(int32_t signum); } #endif -#endif // TDENGINE_TTIME_H +#endif // TDENGINE_OS_SIGNAL_H diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h index 895b5dd499..d136f9664c 100644 --- a/src/os/inc/osSysinfo.h +++ b/src/os/inc/osSysinfo.h @@ -20,7 +20,6 @@ extern "C" { #endif -// TAOS_OS_FUNC_SYSINFO typedef struct { int64_t tsize; int64_t used; @@ -28,20 +27,19 @@ typedef struct { } SysDiskSize; int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize); -void taosGetSystemInfo(); -bool taosGetProcIO(float *readKB, float *writeKB); -bool taosGetBandSpeed(float *bandSpeedKb); -void taosGetDisk(); -bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ; -bool taosGetProcMemory(float *memoryUsedMB) ; -bool taosGetSysMemory(float *memoryUsedMB); -void taosPrintOsInfo(); -int taosSystem(const char * cmd) ; -void taosKillSystem(); -bool taosGetSystemUid(char *uid); -char *taosGetCmdlineByPID(int pid); +void taosGetSystemInfo(); +bool taosGetProcIO(float *readKB, float *writeKB); +bool taosGetBandSpeed(float *bandSpeedKb); +void taosGetDisk(); +bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage); +bool taosGetProcMemory(float *memoryUsedMB); +bool taosGetSysMemory(float *memoryUsedMB); +void taosPrintOsInfo(); +int taosSystem(const char *cmd); +void taosKillSystem(); +bool taosGetSystemUid(char *uid); +char * taosGetCmdlineByPID(int pid); -// TAOS_OS_FUNC_SYSINFO_CORE void taosSetCoreDump(); #ifdef __cplusplus diff --git a/src/os/inc/osTime.h b/src/os/inc/osTime.h index 2c50e7eeab..4743a8c160 100644 --- a/src/os/inc/osTime.h +++ b/src/os/inc/osTime.h @@ -23,9 +23,16 @@ extern "C" { #include "os.h" #include "taosdef.h" -#ifndef TAOS_OS_FUNC_TIME_DEF +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #ifdef _TD_GO_DLL_ + #define MILLISECOND_PER_SECOND (1000LL) + #else + #define MILLISECOND_PER_SECOND (1000i64) + #endif +#else #define MILLISECOND_PER_SECOND ((int64_t)1000L) #endif + #define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60) #define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60) #define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24) @@ -85,7 +92,7 @@ int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts); int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit); int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth); -void deltaToUtcInitOnce(); +void deltaToUtcInitOnce(); #ifdef __cplusplus } diff --git a/src/os/inc/osTimer.h b/src/os/inc/osTimer.h index 413db51c31..72da19cd89 100644 --- a/src/os/inc/osTimer.h +++ b/src/os/inc/osTimer.h @@ -20,7 +20,6 @@ extern "C" { #endif -// TAOS_OS_FUNC_TIMER int taosInitTimer(void (*callback)(int), int ms); void taosUninitTimer(); diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index bfb3811176..47c22f2568 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -91,17 +91,6 @@ typedef SOCKET eventfd_t; char *stpcpy (char *dest, const char *src); char *stpncpy (char *dest, const char *src, size_t n); -#define TAOS_OS_FUNC_SYSINFO - -#define TAOS_OS_FUNC_TIME_DEF - #ifdef _TD_GO_DLL_ - #define MILLISECOND_PER_SECOND (1000LL) - #else - #define MILLISECOND_PER_SECOND (1000i64) - #endif - -#define TAOS_OS_FUNC_TIMER - // specific typedef int (*__compar_fn_t)(const void *, const void *); #define ssize_t int @@ -157,8 +146,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone); #define PATH_MAX 256 #endif -#define TAOS_OS_FUNC_SIGNAL - typedef struct { int we_wordc; char *we_wordv[1]; diff --git a/src/os/src/darwin/darwinEnv.c b/src/os/src/darwin/dwEnv.c similarity index 100% rename from src/os/src/darwin/darwinEnv.c rename to src/os/src/darwin/dwEnv.c diff --git a/src/os/src/darwin/darwinSemphone.c b/src/os/src/darwin/dwSemphone.c similarity index 100% rename from src/os/src/darwin/darwinSemphone.c rename to src/os/src/darwin/dwSemphone.c diff --git a/src/os/src/darwin/darwinSocket.c b/src/os/src/darwin/dwSocket.c similarity index 100% rename from src/os/src/darwin/darwinSocket.c rename to src/os/src/darwin/dwSocket.c diff --git a/src/os/src/darwin/darwinSysInfo.c b/src/os/src/darwin/dwSysInfo.c similarity index 100% rename from src/os/src/darwin/darwinSysInfo.c rename to src/os/src/darwin/dwSysInfo.c diff --git a/src/os/src/darwin/darwinTimer.c b/src/os/src/darwin/dwTimer.c similarity index 100% rename from src/os/src/darwin/darwinTimer.c rename to src/os/src/darwin/dwTimer.c diff --git a/src/os/src/detail/osSignal.c b/src/os/src/detail/osSignal.c index e1a0e84e7f..4467a607b2 100644 --- a/src/os/src/detail/osSignal.c +++ b/src/os/src/detail/osSignal.c @@ -15,11 +15,13 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "taosdef.h" #include "tconfig.h" #include "tglobal.h" #include "tulog.h" -#ifndef TAOS_OS_FUNC_SIGNAL +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) + typedef void (*FLinuxSignalHandler)(int32_t signum, siginfo_t *sigInfo, void *context); void taosSetSignal(int32_t signum, FSignalHandler sigfp) { diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index bbda08aa25..d0b284e1ca 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -20,7 +20,7 @@ #include "tulog.h" #include "taoserror.h" -#ifndef TAOS_OS_FUNC_SYSINFO +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64)) #define PROCESS_ITEM 12 diff --git a/src/os/src/detail/osTimer.c b/src/os/src/detail/osTimer.c index 387daab3e6..6ce1b73703 100644 --- a/src/os/src/detail/osTimer.c +++ b/src/os/src/detail/osTimer.c @@ -18,7 +18,7 @@ #include "ttimer.h" #include "tulog.h" -#ifndef TAOS_OS_FUNC_TIMER +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) static void taosDeleteTimer(void *tharg) { timer_t *pTimer = tharg; From 0fb150b1267da8bacb25e6650d38cc7069abfeaf Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 17:36:53 +0800 Subject: [PATCH 6/9] TD-4088 --- src/os/inc/osAtomic.h | 247 ++++++++++++++++++++++++++- src/os/inc/osDarwin.h | 16 +- src/os/inc/osDef.h | 3 - src/os/inc/{eok.h => osEok.h} | 0 src/os/inc/osNingsi.h | 136 --------------- src/os/inc/osSocket.h | 31 +++- src/os/inc/osWindows.h | 175 ------------------- src/os/src/darwin/{eok.c => dwEok.c} | 4 +- src/os/src/darwin/dwSemphone.c | 1 + src/os/src/detail/osSleep.c | 3 - src/os/src/detail/osSocket.c | 7 +- src/os/src/windows/wSocket.c | 4 +- src/rpc/src/rpcTcp.c | 3 - tests/examples/c/epoll.c | 2 +- 14 files changed, 280 insertions(+), 352 deletions(-) rename src/os/inc/{eok.h => osEok.h} (100%) delete mode 100644 src/os/inc/osNingsi.h rename src/os/src/darwin/{eok.c => dwEok.c} (99%) diff --git a/src/os/inc/osAtomic.h b/src/os/inc/osAtomic.h index 803c351400..7affa444ee 100644 --- a/src/os/inc/osAtomic.h +++ b/src/os/inc/osAtomic.h @@ -20,7 +20,252 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_ATOMIC +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #define atomic_load_8(ptr) (*(char volatile*)(ptr)) + #define atomic_load_16(ptr) (*(short volatile*)(ptr)) + #define atomic_load_32(ptr) (*(long volatile*)(ptr)) + #define atomic_load_64(ptr) (*(__int64 volatile*)(ptr)) + #define atomic_load_ptr(ptr) (*(void* volatile*)(ptr)) + + #define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val)) + #define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val)) + #define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val)) + #define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val)) + #define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val)) + + #define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val)) + #define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val)) + #define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val)) + #define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val)) + #ifdef _WIN64 + #define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) + #else + #define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) + #endif + + #ifdef _TD_GO_DLL_ + #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap + #else + #define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval)) + #endif + #define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval)) + #define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval)) + #define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval)) + #define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval)) + + char interlocked_add_fetch_8(char volatile *ptr, char val); + short interlocked_add_fetch_16(short volatile *ptr, short val); + long interlocked_add_fetch_32(long volatile *ptr, long val); + __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val); + + char interlocked_and_fetch_8(char volatile* ptr, char val); + short interlocked_and_fetch_16(short volatile* ptr, short val); + long interlocked_and_fetch_32(long volatile* ptr, long val); + __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); + + __int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val); + + char interlocked_or_fetch_8(char volatile* ptr, char val); + short interlocked_or_fetch_16(short volatile* ptr, short val); + long interlocked_or_fetch_32(long volatile* ptr, long val); + __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); + + char interlocked_xor_fetch_8(char volatile* ptr, char val); + short interlocked_xor_fetch_16(short volatile* ptr, short val); + long interlocked_xor_fetch_32(long volatile* ptr, long val); + __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); + + __int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val); + + #define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val)) + #define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val)) + #define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val)) + #define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) + #ifdef _TD_GO_DLL_ + #define atomic_fetch_add_8 __sync_fetch_and_ad + #define atomic_fetch_add_16 __sync_fetch_and_add + #else + #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val)) + #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val)) + #endif + #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val)) + #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val)) + #define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val)) + #define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val)) + + #define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val)) + #define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val)) + #define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val)) + #define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val)) + + #define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val)) + #define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val)) + #define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val)) + #define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val)) + + #define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val)) + #define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val)) + #define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val)) + #define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) + + #define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val)) + #define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val)) + #define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val)) + #define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val)) + + #define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val)) + #define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val)) + #define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val)) + #define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) + + #define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val)) + #define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val)) + #define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val)) + #define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val)) + + #define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val)) + #define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val)) + #define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val)) + #define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) + + #define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val)) + #define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val)) + #define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val)) + #define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val)) + + #ifdef _WIN64 + #define atomic_add_fetch_ptr atomic_add_fetch_64 + #define atomic_fetch_add_ptr atomic_fetch_add_64 + #define atomic_sub_fetch_ptr atomic_sub_fetch_64 + #define atomic_fetch_sub_ptr atomic_fetch_sub_64 + #define atomic_and_fetch_ptr atomic_and_fetch_64 + #define atomic_fetch_and_ptr atomic_fetch_and_64 + #define atomic_or_fetch_ptr atomic_or_fetch_64 + #define atomic_fetch_or_ptr atomic_fetch_or_64 + #define atomic_xor_fetch_ptr atomic_xor_fetch_64 + #define atomic_fetch_xor_ptr atomic_fetch_xor_64 + #else + #define atomic_add_fetch_ptr atomic_add_fetch_32 + #define atomic_fetch_add_ptr atomic_fetch_add_32 + #define atomic_sub_fetch_ptr atomic_sub_fetch_32 + #define atomic_fetch_sub_ptr atomic_fetch_sub_32 + #define atomic_and_fetch_ptr atomic_and_fetch_32 + #define atomic_fetch_and_ptr atomic_fetch_and_32 + #define atomic_or_fetch_ptr atomic_or_fetch_32 + #define atomic_fetch_or_ptr atomic_fetch_or_32 + #define atomic_xor_fetch_ptr atomic_xor_fetch_32 + #define atomic_fetch_xor_ptr atomic_fetch_xor_32 + #endif +#elif defined(_TD_NINGSI_60) + /* + * type __sync_fetch_and_add (type *ptr, type value); + * type __sync_fetch_and_sub (type *ptr, type value); + * type __sync_fetch_and_or (type *ptr, type value); + * type __sync_fetch_and_and (type *ptr, type value); + * type __sync_fetch_and_xor (type *ptr, type value); + * type __sync_fetch_and_nand (type *ptr, type value); + * type __sync_add_and_fetch (type *ptr, type value); + * type __sync_sub_and_fetch (type *ptr, type value); + * type __sync_or_and_fetch (type *ptr, type value); + * type __sync_and_and_fetch (type *ptr, type value); + * type __sync_xor_and_fetch (type *ptr, type value); + * type __sync_nand_and_fetch (type *ptr, type value); + * + * bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...) + * type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...) + * */ + + #define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0) + #define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0) + #define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0) + #define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0) + #define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0) + + #define atomic_store_8(ptr, val) (*(ptr)=(val)) + #define atomic_store_16(ptr, val) (*(ptr)=(val)) + #define atomic_store_32(ptr, val) (*(ptr)=(val)) + #define atomic_store_64(ptr, val) (*(ptr)=(val)) + #define atomic_store_ptr(ptr, val) (*(ptr)=(val)) + + int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val ); + int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val ); + int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val ); + int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val ); + void* atomic_exchange_ptr_impl( void **ptr, void *val ); + + #define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val) + #define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val) + #define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val) + #define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val) + #define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val) + + #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_16 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_32 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_64 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap + + #define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val)) + #define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val)) + #define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val)) + #define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val)) + #define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val)) + + #define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val)) + #define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val)) + #define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val)) + #define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val)) + #define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val)) + + #define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val)) + #define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val)) + #define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val)) + #define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val)) + #define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val)) + + #define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val)) + #define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val)) + #define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val)) + #define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val)) + #define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val)) + + #define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val)) + #define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val)) + #define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val)) + #define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val)) + #define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val)) + + #define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val)) + #define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val)) + #define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val)) + #define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val)) + #define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val)) + + #define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val)) + #define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val)) + #define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val)) + #define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val)) + #define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val)) + + #define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val)) + #define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val)) + #define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val)) + #define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val)) + #define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val)) + + #define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val)) + #define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val)) + #define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val)) + #define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val)) + #define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val)) + + #define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val)) + #define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val)) + #define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val)) + #define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val)) + #define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val)) + +#else #define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) #define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) #define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index cfbb80fcd4..5b8d27568d 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -71,12 +71,7 @@ extern "C" { #include #include #include - -#define TAOS_OS_FUNC_FILE_SENDIFLE - -#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT - -#define TAOS_OS_FUNC_TIMERD +#include "osEok.h" // specific typedef int(*__compar_fn_t)(const void *, const void *); @@ -96,15 +91,6 @@ typedef int(*__compar_fn_t)(const void *, const void *); #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE #endif -#include "eok.h" - -void taos_block_sigalrm(void); - -#define TAOS_OS_DEF_EPOLL - #define TAOS_EPOLL_WAIT_TIME 500 - typedef int32_t SOCKET; - typedef SOCKET EpollFd; - #define EpollClose(pollFd) epoll_close(pollFd) #ifdef __cplusplus } diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index def4a72751..74256e0091 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -26,9 +26,6 @@ extern "C" { #endif #endif - -// #define WCHAR wchar_t - #define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) #define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2)) diff --git a/src/os/inc/eok.h b/src/os/inc/osEok.h similarity index 100% rename from src/os/inc/eok.h rename to src/os/inc/osEok.h diff --git a/src/os/inc/osNingsi.h b/src/os/inc/osNingsi.h deleted file mode 100644 index d88d279745..0000000000 --- a/src/os/inc/osNingsi.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TDENGINE_OS_NINGSI_H -#define TDENGINE_OS_NINGSI_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define TAOS_OS_FUNC_ATOMIC -/* - * type __sync_fetch_and_add (type *ptr, type value); - * type __sync_fetch_and_sub (type *ptr, type value); - * type __sync_fetch_and_or (type *ptr, type value); - * type __sync_fetch_and_and (type *ptr, type value); - * type __sync_fetch_and_xor (type *ptr, type value); - * type __sync_fetch_and_nand (type *ptr, type value); - * type __sync_add_and_fetch (type *ptr, type value); - * type __sync_sub_and_fetch (type *ptr, type value); - * type __sync_or_and_fetch (type *ptr, type value); - * type __sync_and_and_fetch (type *ptr, type value); - * type __sync_xor_and_fetch (type *ptr, type value); - * type __sync_nand_and_fetch (type *ptr, type value); - * - * bool __sync_bool_compare_and_swap (type*ptr, type oldval, type newval, ...) - * type __sync_val_compare_and_swap (type *ptr, type oldval, ?type newval, ...) - * */ - -#define atomic_load_8(ptr) __sync_fetch_and_add((ptr), 0) -#define atomic_load_16(ptr) __sync_fetch_and_add((ptr), 0) -#define atomic_load_32(ptr) __sync_fetch_and_add((ptr), 0) -#define atomic_load_64(ptr) __sync_fetch_and_add((ptr), 0) -#define atomic_load_ptr(ptr) __sync_fetch_and_add((ptr), 0) - -#define atomic_store_8(ptr, val) (*(ptr)=(val)) -#define atomic_store_16(ptr, val) (*(ptr)=(val)) -#define atomic_store_32(ptr, val) (*(ptr)=(val)) -#define atomic_store_64(ptr, val) (*(ptr)=(val)) -#define atomic_store_ptr(ptr, val) (*(ptr)=(val)) - -int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val ); -int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val ); -int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val ); -int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val ); -void* atomic_exchange_ptr_impl( void **ptr, void *val ); - -#define atomic_exchange_8(ptr, val) atomic_exchange_8_impl((int8_t*)ptr, (int8_t)val) -#define atomic_exchange_16(ptr, val) atomic_exchange_16_impl((int16_t*)ptr, (int16_t)val) -#define atomic_exchange_32(ptr, val) atomic_exchange_32_impl((int32_t*)ptr, (int32_t)val) -#define atomic_exchange_64(ptr, val) atomic_exchange_64_impl((int64_t*)ptr, (int64_t)val) -#define atomic_exchange_ptr(ptr, val) atomic_exchange_ptr_impl((void **)ptr, (void*)val) - -#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap -#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap -#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap -#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap -#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap - -#define atomic_add_fetch_8(ptr, val) __sync_add_and_fetch((ptr), (val)) -#define atomic_add_fetch_16(ptr, val) __sync_add_and_fetch((ptr), (val)) -#define atomic_add_fetch_32(ptr, val) __sync_add_and_fetch((ptr), (val)) -#define atomic_add_fetch_64(ptr, val) __sync_add_and_fetch((ptr), (val)) -#define atomic_add_fetch_ptr(ptr, val) __sync_add_and_fetch((ptr), (val)) - -#define atomic_fetch_add_8(ptr, val) __sync_fetch_and_add((ptr), (val)) -#define atomic_fetch_add_16(ptr, val) __sync_fetch_and_add((ptr), (val)) -#define atomic_fetch_add_32(ptr, val) __sync_fetch_and_add((ptr), (val)) -#define atomic_fetch_add_64(ptr, val) __sync_fetch_and_add((ptr), (val)) -#define atomic_fetch_add_ptr(ptr, val) __sync_fetch_and_add((ptr), (val)) - -#define atomic_sub_fetch_8(ptr, val) __sync_sub_and_fetch((ptr), (val)) -#define atomic_sub_fetch_16(ptr, val) __sync_sub_and_fetch((ptr), (val)) -#define atomic_sub_fetch_32(ptr, val) __sync_sub_and_fetch((ptr), (val)) -#define atomic_sub_fetch_64(ptr, val) __sync_sub_and_fetch((ptr), (val)) -#define atomic_sub_fetch_ptr(ptr, val) __sync_sub_and_fetch((ptr), (val)) - -#define atomic_fetch_sub_8(ptr, val) __sync_fetch_and_sub((ptr), (val)) -#define atomic_fetch_sub_16(ptr, val) __sync_fetch_and_sub((ptr), (val)) -#define atomic_fetch_sub_32(ptr, val) __sync_fetch_and_sub((ptr), (val)) -#define atomic_fetch_sub_64(ptr, val) __sync_fetch_and_sub((ptr), (val)) -#define atomic_fetch_sub_ptr(ptr, val) __sync_fetch_and_sub((ptr), (val)) - -#define atomic_and_fetch_8(ptr, val) __sync_and_and_fetch((ptr), (val)) -#define atomic_and_fetch_16(ptr, val) __sync_and_and_fetch((ptr), (val)) -#define atomic_and_fetch_32(ptr, val) __sync_and_and_fetch((ptr), (val)) -#define atomic_and_fetch_64(ptr, val) __sync_and_and_fetch((ptr), (val)) -#define atomic_and_fetch_ptr(ptr, val) __sync_and_and_fetch((ptr), (val)) - -#define atomic_fetch_and_8(ptr, val) __sync_fetch_and_and((ptr), (val)) -#define atomic_fetch_and_16(ptr, val) __sync_fetch_and_and((ptr), (val)) -#define atomic_fetch_and_32(ptr, val) __sync_fetch_and_and((ptr), (val)) -#define atomic_fetch_and_64(ptr, val) __sync_fetch_and_and((ptr), (val)) -#define atomic_fetch_and_ptr(ptr, val) __sync_fetch_and_and((ptr), (val)) - -#define atomic_or_fetch_8(ptr, val) __sync_or_and_fetch((ptr), (val)) -#define atomic_or_fetch_16(ptr, val) __sync_or_and_fetch((ptr), (val)) -#define atomic_or_fetch_32(ptr, val) __sync_or_and_fetch((ptr), (val)) -#define atomic_or_fetch_64(ptr, val) __sync_or_and_fetch((ptr), (val)) -#define atomic_or_fetch_ptr(ptr, val) __sync_or_and_fetch((ptr), (val)) - -#define atomic_fetch_or_8(ptr, val) __sync_fetch_and_or((ptr), (val)) -#define atomic_fetch_or_16(ptr, val) __sync_fetch_and_or((ptr), (val)) -#define atomic_fetch_or_32(ptr, val) __sync_fetch_and_or((ptr), (val)) -#define atomic_fetch_or_64(ptr, val) __sync_fetch_and_or((ptr), (val)) -#define atomic_fetch_or_ptr(ptr, val) __sync_fetch_and_or((ptr), (val)) - -#define atomic_xor_fetch_8(ptr, val) __sync_xor_and_fetch((ptr), (val)) -#define atomic_xor_fetch_16(ptr, val) __sync_xor_and_fetch((ptr), (val)) -#define atomic_xor_fetch_32(ptr, val) __sync_xor_and_fetch((ptr), (val)) -#define atomic_xor_fetch_64(ptr, val) __sync_xor_and_fetch((ptr), (val)) -#define atomic_xor_fetch_ptr(ptr, val) __sync_xor_and_fetch((ptr), (val)) - -#define atomic_fetch_xor_8(ptr, val) __sync_fetch_and_xor((ptr), (val)) -#define atomic_fetch_xor_16(ptr, val) __sync_fetch_and_xor((ptr), (val)) -#define atomic_fetch_xor_32(ptr, val) __sync_fetch_and_xor((ptr), (val)) -#define atomic_fetch_xor_64(ptr, val) __sync_fetch_and_xor((ptr), (val)) -#define atomic_fetch_xor_ptr(ptr, val) __sync_fetch_and_xor((ptr), (val)) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index e60028337f..69b8eb1b42 100644 --- a/src/os/inc/osSocket.h +++ b/src/os/inc/osSocket.h @@ -20,7 +20,14 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_SOCKET_OP +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags) + #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen) + #define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0) + #define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0) + #define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd) + #define taosCloseSocket(fd) closesocket((SOCKET)fd) +#else #define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags) #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen) #define taosReadSocket(fd, buf, len) read(fd, buf, len) @@ -35,7 +42,21 @@ extern "C" { } #endif -#ifndef TAOS_OS_DEF_EPOLL +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #define TAOS_EPOLL_WAIT_TIME 100 + typedef SOCKET eventfd_t; + #define eventfd(a, b) -1 + typedef SOCKET EpollFd; + #define EpollClose(pollFd) epoll_close(pollFd) + #ifndef EPOLLWAKEUP + #define EPOLLWAKEUP (1u << 29) + #endif +#elif defined(_TD_DARWIN_64) + #define TAOS_EPOLL_WAIT_TIME 500 + typedef int32_t SOCKET; + typedef SOCKET EpollFd; + #define EpollClose(pollFd) epoll_close(pollFd) +#else #define TAOS_EPOLL_WAIT_TIME 500 typedef int32_t SOCKET; typedef SOCKET EpollFd; @@ -59,22 +80,16 @@ extern "C" { #endif #endif -// TAOS_OS_FUNC_SOCKET int32_t taosSetNonblocking(SOCKET sock, int32_t on); void taosIgnSIGPIPE(); void taosBlockSIGPIPE(); void taosSetMaskSIGPIPE(); - -// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen); - int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t* optlen); -// TAOS_OS_FUNC_SOCKET_INET uint32_t taosInetAddr(char *ipAddr); const char *taosInetNtoa(struct in_addr ipInt); - #if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) #define htobe64 htonll #if defined(_TD_GO_DLL_) diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index 47c22f2568..5a29471034 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -55,39 +55,6 @@ extern "C" { #endif - -#define TAOS_OS_FUNC_FILE -#define TAOS_OS_FUNC_FILE_ISREG -#define TAOS_OS_FUNC_FILE_ISDIR -#define TAOS_OS_FUNC_FILE_ISLNK -#define TAOS_OS_FUNC_FILE_SENDIFLE -#define TAOS_OS_FUNC_FILE_GETTMPFILEPATH -#define TAOS_OS_FUNC_FILE_FTRUNCATE - - - -#define TAOS_OS_FUNC_SOCKET -#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT -#define TAOS_OS_FUNC_SOCKET_OP - #define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags) - #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen) - #define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0) - #define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0) - #define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd) - #define taosCloseSocket(fd) closesocket((SOCKET)fd) -typedef SOCKET eventfd_t; -#define eventfd(a, b) -1 - -#define TAOS_OS_DEF_EPOLL - #define TAOS_EPOLL_WAIT_TIME 100 - typedef SOCKET EpollFd; - #define EpollClose(pollFd) epoll_close(pollFd) - -#ifndef EPOLLWAKEUP - #define EPOLLWAKEUP (1u << 29) -#endif - - char *stpcpy (char *dest, const char *src); char *stpncpy (char *dest, const char *src, size_t n); @@ -128,12 +95,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone); #define TCP_KEEPINTVL 0x1234 #endif -#ifdef _MSC_VER -//#if _MSC_VER >= 1900 - #define TAOS_OS_FUNC_SOCKET_INET -//#endif -#endif - #define SHUT_RDWR SD_BOTH #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND @@ -161,142 +122,6 @@ void wordfree(wordexp_t *pwordexp); #define LOG_INFO 1 void syslog(int unused, const char *format, ...); -#define TAOS_OS_FUNC_ATOMIC - #define atomic_load_8(ptr) (*(char volatile*)(ptr)) - #define atomic_load_16(ptr) (*(short volatile*)(ptr)) - #define atomic_load_32(ptr) (*(long volatile*)(ptr)) - #define atomic_load_64(ptr) (*(__int64 volatile*)(ptr)) - #define atomic_load_ptr(ptr) (*(void* volatile*)(ptr)) - - #define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val)) - #define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val)) - #define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val)) - #define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val)) - #define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val)) - - #define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val)) - #define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val)) - #define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val)) - #define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val)) - #ifdef _WIN64 - #define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) - #else - #define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) - #endif - - #ifdef _TD_GO_DLL_ - #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap - #else - #define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval)) - #endif - #define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval)) - #define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval)) - #define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval)) - #define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval)) - - char interlocked_add_fetch_8(char volatile *ptr, char val); - short interlocked_add_fetch_16(short volatile *ptr, short val); - long interlocked_add_fetch_32(long volatile *ptr, long val); - __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val); - - char interlocked_and_fetch_8(char volatile* ptr, char val); - short interlocked_and_fetch_16(short volatile* ptr, short val); - long interlocked_and_fetch_32(long volatile* ptr, long val); - __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); - - __int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val); - - char interlocked_or_fetch_8(char volatile* ptr, char val); - short interlocked_or_fetch_16(short volatile* ptr, short val); - long interlocked_or_fetch_32(long volatile* ptr, long val); - __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); - - char interlocked_xor_fetch_8(char volatile* ptr, char val); - short interlocked_xor_fetch_16(short volatile* ptr, short val); - long interlocked_xor_fetch_32(long volatile* ptr, long val); - __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); - - __int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val); - - #define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - #ifdef _TD_GO_DLL_ - #define atomic_fetch_add_8 __sync_fetch_and_ad - #define atomic_fetch_add_16 __sync_fetch_and_add - #else - #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val)) - #endif - #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val)) - #define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val)) - #define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val)) - #define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val)) - - #define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val)) - #define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val)) - #define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val)) - #define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val)) - - #define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val)) - - #ifdef _WIN64 - #define atomic_add_fetch_ptr atomic_add_fetch_64 - #define atomic_fetch_add_ptr atomic_fetch_add_64 - #define atomic_sub_fetch_ptr atomic_sub_fetch_64 - #define atomic_fetch_sub_ptr atomic_fetch_sub_64 - #define atomic_and_fetch_ptr atomic_and_fetch_64 - #define atomic_fetch_and_ptr atomic_fetch_and_64 - #define atomic_or_fetch_ptr atomic_or_fetch_64 - #define atomic_fetch_or_ptr atomic_fetch_or_64 - #define atomic_xor_fetch_ptr atomic_xor_fetch_64 - #define atomic_fetch_xor_ptr atomic_fetch_xor_64 - #else - #define atomic_add_fetch_ptr atomic_add_fetch_32 - #define atomic_fetch_add_ptr atomic_fetch_add_32 - #define atomic_sub_fetch_ptr atomic_sub_fetch_32 - #define atomic_fetch_sub_ptr atomic_fetch_sub_32 - #define atomic_and_fetch_ptr atomic_and_fetch_32 - #define atomic_fetch_and_ptr atomic_fetch_and_32 - #define atomic_or_fetch_ptr atomic_or_fetch_32 - #define atomic_fetch_or_ptr atomic_fetch_or_32 - #define atomic_xor_fetch_ptr atomic_xor_fetch_32 - #define atomic_fetch_xor_ptr atomic_fetch_xor_32 - #endif #ifdef __cplusplus } #endif diff --git a/src/os/src/darwin/eok.c b/src/os/src/darwin/dwEok.c similarity index 99% rename from src/os/src/darwin/eok.c rename to src/os/src/darwin/dwEok.c index f731aaf330..c8e270214f 100644 --- a/src/os/src/darwin/eok.c +++ b/src/os/src/darwin/dwEok.c @@ -18,7 +18,7 @@ // https://stackoverflow.com/questions/4393197/erlangs-let-it-crash-philosophy-applicable-elsewhere // experimentally, we follow log-and-crash here -#include "eok.h" +#include "osEok.h" #include "os.h" @@ -415,8 +415,6 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) { static struct timespec do_timespec_diff(struct timespec *from, struct timespec *to); int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) { - taos_block_sigalrm(); - int e = 0; if (!events) { errno = EINVAL; diff --git a/src/os/src/darwin/dwSemphone.c b/src/os/src/darwin/dwSemphone.c index 1805fd176f..a2d669fa7f 100644 --- a/src/os/src/darwin/dwSemphone.c +++ b/src/os/src/darwin/dwSemphone.c @@ -20,6 +20,7 @@ #define _DEFAULT_SOURCE #include "os.h" +#include > #include diff --git a/src/os/src/detail/osSleep.c b/src/os/src/detail/osSleep.c index e5d469f9a1..9c3231fd13 100644 --- a/src/os/src/detail/osSleep.c +++ b/src/os/src/detail/osSleep.c @@ -32,9 +32,6 @@ void taosMsleep(int32_t ms) { Sleep(ms); } pthread_sigmask(SIG_BLOCK, &set, NULL); */ void taosMsleep(int32_t mseconds) { -#ifdef _TD_DARWIN_64 - taos_block_sigalrm(); -#endif #if 1 usleep(mseconds * 1000); #else diff --git a/src/os/src/detail/osSocket.c b/src/os/src/detail/osSocket.c index db976acccd..7ce9d6eb06 100644 --- a/src/os/src/detail/osSocket.c +++ b/src/os/src/detail/osSocket.c @@ -17,7 +17,7 @@ #include "os.h" #include "tulog.h" -#ifndef TAOS_OS_FUNC_SOCKET +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) int32_t taosSetNonblocking(SOCKET sock, int32_t on) { int32_t flags = 0; @@ -65,7 +65,7 @@ void taosSetMaskSIGPIPE() { #endif -#ifndef TAOS_OS_FUNC_SOCKET_SETSOCKETOPT +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_32)) int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen) { return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen); @@ -74,9 +74,10 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t* optlen) { return getsockopt(socketfd, level, optname, optval, (socklen_t *)optlen); } + #endif -#ifndef TAOS_OS_FUNC_SOCKET_INET +#if !( (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) && defined(_MSC_VER) ) uint32_t taosInetAddr(char *ipAddr) { return inet_addr(ipAddr); diff --git a/src/os/src/windows/wSocket.c b/src/os/src/windows/wSocket.c index e152f40f03..ad0d87418d 100644 --- a/src/os/src/windows/wSocket.c +++ b/src/os/src/windows/wSocket.c @@ -70,7 +70,8 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op return setsockopt(socketfd, level, optname, optval, optlen); } -#ifdef TAOS_OS_FUNC_SOCKET_INET +#ifdef _MSC_VER +//#if _MSC_VER >= 1900 uint32_t taosInetAddr(char *ipAddr) { uint32_t value; @@ -88,6 +89,7 @@ const char *taosInetNtoa(struct in_addr ipInt) { return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); } +//#endif #endif #if defined(_TD_GO_DLL_) diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 3162ab2e4c..09857610d2 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -529,9 +529,6 @@ static void *taosProcessTcpData(void *param) { struct epoll_event events[maxEvents]; SRecvInfo recvInfo; -#ifdef __APPLE__ - taos_block_sigalrm(); -#endif // __APPLE__ while (1) { int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, TAOS_EPOLL_WAIT_TIME); if (pThreadObj->stop) { diff --git a/tests/examples/c/epoll.c b/tests/examples/c/epoll.c index de7c5989d1..284268ac43 100644 --- a/tests/examples/c/epoll.c +++ b/tests/examples/c/epoll.c @@ -20,7 +20,7 @@ // monitor and compare : glances #ifdef __APPLE__ -#include "eok.h" +#include "osEok.h" #else // __APPLE__ #include #endif // __APPLE__ From b4fa11df75ac2601691ad5fff82b2c88c0808a5b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 20:28:51 +0800 Subject: [PATCH 7/9] TD-4088 --- src/os/src/darwin/dwSemphone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/src/darwin/dwSemphone.c b/src/os/src/darwin/dwSemphone.c index a2d669fa7f..317611fa30 100644 --- a/src/os/src/darwin/dwSemphone.c +++ b/src/os/src/darwin/dwSemphone.c @@ -20,7 +20,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include > +#include #include From ce6aa6d036b9962f6beeb92443b7a60ef03245b2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 9 May 2021 10:04:03 +0800 Subject: [PATCH 8/9] TD-4088 --- cmake/define.inc | 2 +- src/os/inc/osSemphone.h | 2 +- src/os/src/darwin/dwEok.c | 4 ++-- src/os/src/darwin/dwSemphone.c | 26 ++++++++++++-------------- src/os/src/darwin/dwSysInfo.c | 1 - src/os/src/detail/osTimer.c | 2 +- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cmake/define.inc b/cmake/define.inc index 4115dd0c41..52b0ead1a5 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -138,7 +138,7 @@ IF (TD_DARWIN_64) ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "darwin64 is defined") - SET(COMMON_FLAGS "-Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -Wno-missing-braces -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) diff --git a/src/os/inc/osSemphone.h b/src/os/inc/osSemphone.h index 2e2d432607..fe59095205 100644 --- a/src/os/inc/osSemphone.h +++ b/src/os/inc/osSemphone.h @@ -29,7 +29,7 @@ extern "C" { #else #define tsem_t sem_t #define tsem_init sem_init - int32_t tsem_wait(tsem_t* sem); + int tsem_wait(tsem_t* sem); #define tsem_post sem_post #define tsem_destroy sem_destroy #endif diff --git a/src/os/src/darwin/dwEok.c b/src/os/src/darwin/dwEok.c index c8e270214f..22d9260763 100644 --- a/src/os/src/darwin/dwEok.c +++ b/src/os/src/darwin/dwEok.c @@ -18,9 +18,9 @@ // https://stackoverflow.com/questions/4393197/erlangs-let-it-crash-philosophy-applicable-elsewhere // experimentally, we follow log-and-crash here -#include "osEok.h" - +#define _DEFAULT_SOURCE #include "os.h" +#include "osEok.h" #include diff --git a/src/os/src/darwin/dwSemphone.c b/src/os/src/darwin/dwSemphone.c index 317611fa30..898410647a 100644 --- a/src/os/src/darwin/dwSemphone.c +++ b/src/os/src/darwin/dwSemphone.c @@ -20,8 +20,6 @@ #define _DEFAULT_SOURCE #include "os.h" -#include - #include // #define SEM_USE_PTHREAD @@ -38,7 +36,7 @@ static pthread_t sem_thread; static pthread_once_t sem_once; static task_t sem_port; -static volatile int32_t sem_inited = 0; +static volatile int sem_inited = 0; static semaphore_t sem_exit; static void* sem_thread_routine(void *arg) { @@ -56,7 +54,7 @@ static void* sem_thread_routine(void *arg) { } static void once_init(void) { - int32_t r = 0; + int r = 0; r = pthread_create(&sem_thread, NULL, sem_thread_routine, NULL); if (r) { fprintf(stderr, "==%s[%d]%s()==failed to create thread\n", basename(__FILE__), __LINE__, __func__); @@ -82,10 +80,10 @@ struct tsem_s { dispatch_semaphore_t sem; #endif // SEM_USE_PTHREAD - volatile unsigned int32_t valid:1; + volatile unsigned int valid:1; }; -int32_t tsem_init(tsem_t *sem, int32_t pshared, unsigned int32_t value) { +int tsem_init(tsem_t *sem, int pshared, unsigned int value) { // fprintf(stderr, "==%s[%d]%s():[%p]==creating\n", basename(__FILE__), __LINE__, __func__, sem); if (*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==already initialized\n", basename(__FILE__), __LINE__, __func__, sem); @@ -98,7 +96,7 @@ int32_t tsem_init(tsem_t *sem, int32_t pshared, unsigned int32_t value) { } #ifdef SEM_USE_PTHREAD - int32_t r = pthread_mutex_init(&p->lock, NULL); + int r = pthread_mutex_init(&p->lock, NULL); do { if (r) break; r = pthread_cond_init(&p->cond, NULL); @@ -125,7 +123,7 @@ int32_t tsem_init(tsem_t *sem, int32_t pshared, unsigned int32_t value) { p->sem = sem_open(name, O_CREAT|O_EXCL, pshared, value); p->id = id; if (p->sem!=SEM_FAILED) break; - int32_t e = errno; + int e = errno; if (e==EEXIST) continue; if (e==EINTR) continue; fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e)); @@ -159,7 +157,7 @@ int32_t tsem_init(tsem_t *sem, int32_t pshared, unsigned int32_t value) { return 0; } -int32_t tsem_wait(tsem_t *sem) { +int tsem_wait(tsem_t *sem) { if (!*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); abort(); @@ -195,7 +193,7 @@ int32_t tsem_wait(tsem_t *sem) { #endif // SEM_USE_PTHREAD } -int32_t tsem_post(tsem_t *sem) { +int tsem_post(tsem_t *sem) { if (!*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); abort(); @@ -231,7 +229,7 @@ int32_t tsem_post(tsem_t *sem) { #endif // SEM_USE_PTHREAD } -int32_t tsem_destroy(tsem_t *sem) { +int tsem_destroy(tsem_t *sem) { // fprintf(stderr, "==%s[%d]%s():[%p]==destroying\n", basename(__FILE__), __LINE__, __func__, sem); if (!*sem) { // fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); @@ -265,9 +263,9 @@ int32_t tsem_destroy(tsem_t *sem) { #elif defined(SEM_USE_POSIX) char name[NAME_MAX-4]; snprintf(name, sizeof(name), "/t%ld", p->id); - int32_t r = sem_unlink(name); + int r = sem_unlink(name); if (r) { - int32_t e = errno; + int e = errno; fprintf(stderr, "==%s[%d]%s():[%p]==unlink failed[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e)); abort(); } @@ -285,7 +283,7 @@ int32_t tsem_destroy(tsem_t *sem) { bool taosCheckPthreadValid(pthread_t thread) { uint64_t id = 0; - int32_t r = pthread_threadid_np(thread, &id); + int r = pthread_threadid_np(thread, &id); return r ? false : true; } diff --git a/src/os/src/darwin/dwSysInfo.c b/src/os/src/darwin/dwSysInfo.c index 6e70043779..b3c9bd528e 100644 --- a/src/os/src/darwin/dwSysInfo.c +++ b/src/os/src/darwin/dwSysInfo.c @@ -22,7 +22,6 @@ #include #include - static void taosGetSystemTimezone() { SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); if (cfg_timezone == NULL) return; diff --git a/src/os/src/detail/osTimer.c b/src/os/src/detail/osTimer.c index 6ce1b73703..b054f08c78 100644 --- a/src/os/src/detail/osTimer.c +++ b/src/os/src/detail/osTimer.c @@ -18,7 +18,7 @@ #include "ttimer.h" #include "tulog.h" -#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_64)) static void taosDeleteTimer(void *tharg) { timer_t *pTimer = tharg; From 619a77ccadbfce3415560711f85c4342c8a3742b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 9 May 2021 10:25:11 +0800 Subject: [PATCH 9/9] TD-4088 --- cmake/define.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/define.inc b/cmake/define.inc index 52b0ead1a5..4115dd0c41 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -138,7 +138,7 @@ IF (TD_DARWIN_64) ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "darwin64 is defined") - SET(COMMON_FLAGS "-Wall -Werror -Wno-missing-braces -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)