diff --git a/cmake/define.inc b/cmake/define.inc index e825dce024f388e0a376ad0713abca7dd94c5e2a..4115dd0c4143535130b1bf8a132ee400d828d87d 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 efcc9961767aec8555897e7a96fec91356017659..3989993953f8cd0608a2bf7adfe9fd349f9e9a03 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/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 6b88c9074738204d99f2dc536100a68a1656ea77..d8b40f397fae8d66ffd0c489744bfee0a010de43 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/dnode/src/dnodeCfg.c b/src/dnode/src/dnodeCfg.c index c573d709f5ba250177aac41cefad74132d7797c8..586adacc98712e63aa8d83367cb5d2ec5f9157ec 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 9554651776ad0e9c961a3d15955491b224d869bf..9b1535364744613f92f8f690d4d6fd5893e191cc 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 0dca116d84a8267231acba686018cf6c07ae15e0..611c30b84344eac4306b73eb49e1405cc83289b6 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 b88244ea018291fbdc98165a8665949f618e3291..8f7f47553657056623671c7616459cf18fcc9d4a 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 55ee39b6bceb7a3d5ebc8838e1a9a2151ccb6c3d..e77c1b3e59ca9a75a2a8f97f024320ee1c61d7d0 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 c3e02b14db31a8d5687de2e3b7368d2d5e1626eb..6006f1b9690373158300734728a2a21e472a8776 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" @@ -67,6 +66,7 @@ extern "C" { #include "osRand.h" #include "osSemphone.h" #include "osSignal.h" +#include "osSleep.h" #include "osSocket.h" #include "osString.h" #include "osSysinfo.h" diff --git a/src/os/inc/osAtomic.h b/src/os/inc/osAtomic.h index 803c351400905971ff7343b255bd1873bb0c5d94..7affa444ee44c8c7e6de209f2b4ea23238c26d3b 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 7c206afe7a12e9be17ad997ee50625a0cce438e9..5b8d27568db325026feec2d79d66bcf09bc3bc97 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -71,24 +71,9 @@ extern "C" { #include #include #include - -#define TAOS_OS_FUNC_FILE_SENDIFLE - -#define TAOS_OS_FUNC_SEMPHONE - typedef struct tsem_s *tsem_t; - int tsem_init(tsem_t *sem, int pshared, unsigned int value); - int tsem_wait(tsem_t *sem); - int tsem_post(tsem_t *sem); - int tsem_destroy(tsem_t *sem); - -#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT -#define TAOS_OS_FUNC_STRING_STR2INT64 -#define TAOS_OS_FUNC_SYSINFO -#define TAOS_OS_FUNC_TIMER -#define TAOS_OS_FUNC_SEMPHONE_PTHREAD +#include "osEok.h" // specific -#define htobe64 htonll typedef int(*__compar_fn_t)(const void *, const void *); // for send function in tsocket.c @@ -106,19 +91,6 @@ typedef int(*__compar_fn_t)(const void *, const void *); #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE #endif -#define TAOS_OS_FUNC_PTHREAD_RWLOCK - -int64_t tsosStr2int64(char *str); - -#include "eok.h" - -void taos_block_sigalrm(void); - -#define TAOS_OS_DEF_EPOLL - #define TAOS_EPOLL_WAIT_TIME 500 - typedef int32_t SOCKET; - typedef SOCKET EpollFd; - #define EpollClose(pollFd) epoll_close(pollFd) #ifdef __cplusplus } diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index bbe0f98ec0b632deb39691f74350bced6d2a6515..74256e009165d16854225d9c4d40d17e5b378359 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -26,11 +26,6 @@ extern "C" { #endif #endif -#define FD_VALID(x) ((x) > STDERR_FILENO) -#define FD_INITIALIZER ((int32_t)-1) - -// #define WCHAR wchar_t - #define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) #define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2)) @@ -113,6 +108,12 @@ extern "C" { #define threadlocal __declspec( thread ) #endif +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + #define PRIzu "ld" +#else + #define PRIzu "zu" +#endif + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osDir.h b/src/os/inc/osDir.h index 540efc310c1d89530d6e41733ce2419ad79b1e36..bdc65e452068cf34fd3969ada6ac69fbf5035217 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/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/osFile.h b/src/os/inc/osFile.h index c117ae4039d05b6a063726ec9052fe5f5562365e..262f19ad22c603f02c8e4277761a0ac038a31c7d 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); -int64_t taosCopy(char *from, char *to); +#define FD_VALID(x) ((x) > STDERR_FILENO) +#define FD_INITIALIZER ((int32_t)-1) -#define taosRead(fd, buf, count) taosReadImp(fd, buf, count) -#define taosWrite(fd, buf, count) taosWriteImp(fd, buf, count) -#define taosLSeek(fd, offset, whence) taosLSeekImp(fd, offset, whence) -#define taosClose(fd) \ - { \ - if (FD_VALID(fd)) { \ - close(fd); \ - fd = FD_INITIALIZER; \ - } \ - } +#ifndef PATH_MAX + #define PATH_MAX 256 +#endif -// TAOS_OS_FUNC_FILE_SENDIFLE -int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t size); -int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size); +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +typedef int32_t FileFd; +typedef SOCKET SocketFd; +#else +typedef int32_t FileFd; +typedef int32_t SocketFd; +#endif + +int64_t taosRead(FileFd fd, void *buf, int64_t count); +int64_t taosWrite(FileFd fd, void *buf, int64_t count); -#ifdef TAOS_RANDOM_FILE_FAIL - void taosSetRandomFileFailFactor(int32_t factor); - void taosSetRandomFileFailOutput(const char *path); - #ifdef TAOS_RANDOM_FILE_FAIL_TEST - int64_t taosReadFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line); - int64_t taosWriteFileRandomFail(int32_t fd, void *buf, int32_t count, const char *file, uint32_t line); - int64_t taosLSeekRandomFail(int32_t fd, int64_t offset, int32_t whence, const char *file, uint32_t line); - #undef taosRead - #undef taosWrite - #undef taosLSeek - #define taosRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) - #endif -#endif +int64_t taosLSeek(FileFd fd, int64_t offset, int32_t whence); +int32_t taosFtruncate(FileFd fd, int64_t length); +int32_t taosFsync(FileFd fd); + +int32_t taosRename(char* oldName, char *newName); +int64_t taosCopy(char *from, char *to); + +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size); +int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size); -// TAOS_OS_FUNC_FILE_GETTMPFILEPATH void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath); +void taosClose(FileFd fd); -// TAOS_OS_FUNC_FILE_FTRUNCATE -int32_t taosFtruncate(int32_t fd, int64_t length); #ifdef __cplusplus } #endif -#endif +#endif \ No newline at end of file diff --git a/src/os/inc/osLinux32.h b/src/os/inc/osLinux32.h index eee4999399ace745e6800f81cb09144e828f8cfc..6d9a01a9a899c60e9dcaa0b9691ae724548bb9a8 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 a944892c482470a60c17a13f693c19801bde2081..8363861e0348141243c49c9df72b4aac7b6c199d 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 9935f94d39ef0431b7c9b1a524b956e6fafe9f4f..65e8a1f6feaf32bff7f413b7085fc64835ba70fb 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/osMemory.h b/src/os/inc/osMemory.h index 2cf7e14d2f4bc9fc124cdf4de167c5b2cb93f4bb..27efd9f5051d9f87838980503ed60174de153ad4 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/osNingsi.h b/src/os/inc/osNingsi.h deleted file mode 100644 index d88d2797455e5c3357bee81cdf9414146a38cd08..0000000000000000000000000000000000000000 --- 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/osRand.h b/src/os/inc/osRand.h index 803c0688bb4a9c5fab117d8548206e70b5f152db..e08768c2cc6b379877fb8be7d3541c13bc431f98 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/osSemphone.h b/src/os/inc/osSemphone.h index 3332a9234b040aaa49c1d097e63f03a6c9bde25b..fe59095205010bef553413809706c62cd772a7e3 100644 --- a/src/os/inc/osSemphone.h +++ b/src/os/inc/osSemphone.h @@ -20,7 +20,13 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_SEMPHONE +#if defined (_TD_DARWIN_64) + typedef struct tsem_s *tsem_t; + int tsem_init(tsem_t *sem, int pshared, unsigned int value); + int tsem_wait(tsem_t *sem); + int tsem_post(tsem_t *sem); + int tsem_destroy(tsem_t *sem); +#else #define tsem_t sem_t #define tsem_init sem_init int tsem_wait(tsem_t* sem); @@ -28,7 +34,7 @@ extern "C" { #define tsem_destroy sem_destroy #endif -#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/osSignal.h b/src/os/inc/osSignal.h index c13cd83178691fa8c617369904cb37a20ab27479..eca1d3b3f6b78a773822e5f2acb652493b5d262f 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/osCommon.h b/src/os/inc/osSleep.h similarity index 85% rename from src/os/inc/osCommon.h rename to src/os/inc/osSleep.h index 70d2b2c0c243cd13d5309e4c5e25c4bed3bae277..e42da8d5a64bbc484b15beea19433a710578ff3f 100644 --- a/src/os/inc/osCommon.h +++ b/src/os/inc/osSleep.h @@ -13,19 +13,17 @@ * along with this program. If not, see . */ -#ifndef TDENGINE_OS_COMMON_H -#define TDENGINE_OS_COMMON_H +#ifndef TDENGINE_OS_SLEEP_H +#define TDENGINE_OS_SLEEP_H #ifdef __cplusplus extern "C" { #endif -#ifndef TAOS_OS_DEF_ZU - #define PRIzu "zu" -#endif +void taosMsleep(int32_t ms); #ifdef __cplusplus } #endif -#endif +#endif \ No newline at end of file diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h index cf75b74a9afa75caa15ec82e191d781159af944f..69b8eb1b427b518a516d32d42ea249d34959b79b 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,21 +80,25 @@ extern "C" { #endif #endif -// TAOS_OS_FUNC_SOCKET int32_t taosSetNonblocking(SOCKET sock, int32_t on); void taosIgnSIGPIPE(); void taosBlockSIGPIPE(); void taosSetMaskSIGPIPE(); - -// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen); - int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t* optlen); -// TAOS_OS_FUNC_SOCKET_INET uint32_t taosInetAddr(char *ipAddr); const char *taosInetNtoa(struct in_addr ipInt); +#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) + #define htobe64 htonll + #if defined(_TD_GO_DLL_) + uint64_t htonll(uint64_t val); + #endif +#elif defined(_TD_DARWIN_64) + #define htobe64 htonll +#endif + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osString.h b/src/os/inc/osString.h index 97966ed412d0ae4ef4970de4dbb6d48c82130671..33f858485c4291f7c7c9098685c8c70a02799fe6 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/osSysinfo.h b/src/os/inc/osSysinfo.h index 895b5dd499196703f954c5621241cd2d1e2fabec..d136f9664c9d5c00dc68382eaf3ebc6e97013cd0 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 2c50e7eeabd934a9d88f32d4b3bdc29d41d699b1..4743a8c160ce8228a2c564129f00ec2962038c56 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 d6deae2a6d1a7f6a76e4c04c53f8b6c3fa229192..72da19cd899a708dc36c91ac25159995fe0da51c 100644 --- a/src/os/inc/osTimer.h +++ b/src/os/inc/osTimer.h @@ -20,8 +20,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 a058f2cc99029e311168428ce6e91f88212a4c73..5a29471034ccf7c6b1548cfb9ebfba7481b60b7f 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -55,87 +55,9 @@ extern "C" { #endif -#define TAOS_OS_FUNC_LZ4 - int32_t BUILDIN_CLZL(uint64_t val); - int32_t BUILDIN_CLZ(uint32_t val); - int32_t BUILDIN_CTZL(uint64_t val); - int32_t BUILDIN_CTZ(uint32_t val); - -#define TAOS_OS_FUNC_FILE -#define TAOS_OS_FUNC_FILE_ISREG -#define TAOS_OS_FUNC_FILE_ISDIR -#define TAOS_OS_FUNC_FILE_ISLNK -#define TAOS_OS_FUNC_FILE_SENDIFLE -#define TAOS_OS_FUNC_FILE_GETTMPFILEPATH -#define TAOS_OS_FUNC_FILE_FTRUNCATE - -#define TAOS_OS_FUNC_DIR - -#define TAOS_OS_FUNC_MATH - #define SWAP(a, b, c) \ - do { \ - c __tmp = (c)(a); \ - (a) = (c)(b); \ - (b) = __tmp; \ - } while (0) - #define MAX(a,b) (((a)>(b))?(a):(b)) - #define MIN(a,b) (((a)<(b))?(a):(b)) - -#define TAOS_OS_FUNC_SEMPHONE_PTHREAD - -#define TAOS_OS_FUNC_SOCKET -#define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT -#define TAOS_OS_FUNC_SOCKET_OP - #define taosSend(sockfd, buf, len, flags) send((SOCKET)sockfd, buf, len, flags) - #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto((SOCKET)sockfd, buf, len, flags, dest_addr, addrlen) - #define taosWriteSocket(fd, buf, len) send((SOCKET)fd, buf, len, 0) - #define taosReadSocket(fd, buf, len) recv((SOCKET)fd, buf, len, 0) - #define taosCloseSocketNoCheck(fd) closesocket((SOCKET)fd) - #define taosCloseSocket(fd) closesocket((SOCKET)fd) -typedef SOCKET eventfd_t; -#define eventfd(a, b) -1 - -#define TAOS_OS_DEF_EPOLL - #define TAOS_EPOLL_WAIT_TIME 100 - typedef SOCKET EpollFd; - #define EpollClose(pollFd) epoll_close(pollFd) - -#ifndef EPOLLWAKEUP - #define EPOLLWAKEUP (1u << 29) -#endif - -#define TAOS_OS_DEF_ZU - #define PRIzu "ld" - -#define TAOS_OS_FUNC_STRING_WCHAR - int twcslen(const wchar_t *wcs); -#define TAOS_OS_FUNC_STRING_GETLINE -#define TAOS_OS_FUNC_STRING_STR2INT64 - #ifdef _TD_GO_DLL_ - int64_t tsosStr2int64(char *str); - uint64_t htonll(uint64_t val); - #else - #define tsosStr2int64 _atoi64 - #endif -#define TAOS_OS_FUNC_STRING_STRDUP - #define taosStrdupImp(str) _strdup(str) - #define taosStrndupImp(str, size) _strndup(str, size) - char *stpcpy (char *dest, const char *src); char *stpncpy (char *dest, const char *src, size_t n); -#define TAOS_OS_FUNC_SYSINFO - -#define TAOS_OS_FUNC_TIME_DEF - #ifdef _TD_GO_DLL_ - #define MILLISECOND_PER_SECOND (1000LL) - #else - #define MILLISECOND_PER_SECOND (1000i64) - #endif - -#define TAOS_OS_FUNC_TIMER_SLEEP -#define TAOS_OS_FUNC_TIMER - // specific typedef int (*__compar_fn_t)(const void *, const void *); #define ssize_t int @@ -147,14 +69,12 @@ typedef int (*__compar_fn_t)(const void *, const void *); #define snprintf _snprintf #define in_addr_t unsigned long #define socklen_t int -#define htobe64 htonll struct tm *localtime_r(const time_t *timep, struct tm *result); char * strptime(const char *buf, const char *fmt, struct tm *tm); char * strsep(char **stringp, const char *delim); char * getpass(const char *prefix); int flock(int fd, int option); -int fsync(int filedes); char * strndup(const char *s, size_t n); int gettimeofday(struct timeval *ptv, void *pTimeZone); @@ -175,12 +95,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone); #define TCP_KEEPINTVL 0x1234 #endif -#ifdef _MSC_VER -//#if _MSC_VER >= 1900 - #define TAOS_OS_FUNC_SOCKET_INET -//#endif -#endif - #define SHUT_RDWR SD_BOTH #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND @@ -193,8 +107,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone); #define PATH_MAX 256 #endif -#define TAOS_OS_FUNC_SIGNAL - typedef struct { int we_wordc; char *we_wordv[1]; @@ -210,142 +122,6 @@ void wordfree(wordexp_t *pwordexp); #define LOG_INFO 1 void syslog(int unused, const char *format, ...); -#define TAOS_OS_FUNC_ATOMIC - #define atomic_load_8(ptr) (*(char volatile*)(ptr)) - #define atomic_load_16(ptr) (*(short volatile*)(ptr)) - #define atomic_load_32(ptr) (*(long volatile*)(ptr)) - #define atomic_load_64(ptr) (*(__int64 volatile*)(ptr)) - #define atomic_load_ptr(ptr) (*(void* volatile*)(ptr)) - - #define atomic_store_8(ptr, val) ((*(char volatile*)(ptr)) = (char)(val)) - #define atomic_store_16(ptr, val) ((*(short volatile*)(ptr)) = (short)(val)) - #define atomic_store_32(ptr, val) ((*(long volatile*)(ptr)) = (long)(val)) - #define atomic_store_64(ptr, val) ((*(__int64 volatile*)(ptr)) = (__int64)(val)) - #define atomic_store_ptr(ptr, val) ((*(void* volatile*)(ptr)) = (void*)(val)) - - #define atomic_exchange_8(ptr, val) _InterlockedExchange8((char volatile*)(ptr), (char)(val)) - #define atomic_exchange_16(ptr, val) _InterlockedExchange16((short volatile*)(ptr), (short)(val)) - #define atomic_exchange_32(ptr, val) _InterlockedExchange((long volatile*)(ptr), (long)(val)) - #define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val)) - #ifdef _WIN64 - #define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) - #else - #define atomic_exchange_ptr(ptr, val) _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) - #endif - - #ifdef _TD_GO_DLL_ - #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap - #else - #define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval)) - #endif - #define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval)) - #define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval)) - #define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval)) - #define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval)) - - char interlocked_add_fetch_8(char volatile *ptr, char val); - short interlocked_add_fetch_16(short volatile *ptr, short val); - long interlocked_add_fetch_32(long volatile *ptr, long val); - __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val); - - char interlocked_and_fetch_8(char volatile* ptr, char val); - short interlocked_and_fetch_16(short volatile* ptr, short val); - long interlocked_and_fetch_32(long volatile* ptr, long val); - __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); - - __int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val); - - char interlocked_or_fetch_8(char volatile* ptr, char val); - short interlocked_or_fetch_16(short volatile* ptr, short val); - long interlocked_or_fetch_32(long volatile* ptr, long val); - __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); - - char interlocked_xor_fetch_8(char volatile* ptr, char val); - short interlocked_xor_fetch_16(short volatile* ptr, short val); - long interlocked_xor_fetch_32(long volatile* ptr, long val); - __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); - - __int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val); - - #define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - #ifdef _TD_GO_DLL_ - #define atomic_fetch_add_8 __sync_fetch_and_ad - #define atomic_fetch_add_16 __sync_fetch_and_add - #else - #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val)) - #endif - #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val)) - #define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val)) - #define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val)) - #define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val)) - - #define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val)) - #define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val)) - #define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val)) - #define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val)) - - #define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val)) - #define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val)) - #define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val)) - #define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val)) - - #define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val)) - #define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val)) - #define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val)) - #define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val)) - - #ifdef _WIN64 - #define atomic_add_fetch_ptr atomic_add_fetch_64 - #define atomic_fetch_add_ptr atomic_fetch_add_64 - #define atomic_sub_fetch_ptr atomic_sub_fetch_64 - #define atomic_fetch_sub_ptr atomic_fetch_sub_64 - #define atomic_and_fetch_ptr atomic_and_fetch_64 - #define atomic_fetch_and_ptr atomic_fetch_and_64 - #define atomic_or_fetch_ptr atomic_or_fetch_64 - #define atomic_fetch_or_ptr atomic_fetch_or_64 - #define atomic_xor_fetch_ptr atomic_xor_fetch_64 - #define atomic_fetch_xor_ptr atomic_fetch_xor_64 - #else - #define atomic_add_fetch_ptr atomic_add_fetch_32 - #define atomic_fetch_add_ptr atomic_fetch_add_32 - #define atomic_sub_fetch_ptr atomic_sub_fetch_32 - #define atomic_fetch_sub_ptr atomic_fetch_sub_32 - #define atomic_and_fetch_ptr atomic_and_fetch_32 - #define atomic_fetch_and_ptr atomic_fetch_and_32 - #define atomic_or_fetch_ptr atomic_or_fetch_32 - #define atomic_fetch_or_ptr atomic_fetch_or_32 - #define atomic_xor_fetch_ptr atomic_xor_fetch_32 - #define atomic_fetch_xor_ptr atomic_fetch_xor_32 - #endif #ifdef __cplusplus } #endif diff --git a/src/os/src/darwin/darwinFile.c b/src/os/src/darwin/darwinFile.c deleted file mode 100644 index 4236ea1c5f08c8b8a8a81ae10c7b442ad3b5ce6a..0000000000000000000000000000000000000000 --- a/src/os/src/darwin/darwinFile.c +++ /dev/null @@ -1,65 +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" - -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 - * - * 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/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/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 f731aaf330cb8618aa8a2dc51401ac45ecdc5440..22d92607635ab81793dd7c7d7e2303a8a9d76477 100644 --- a/src/os/src/darwin/eok.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 "eok.h" - +#define _DEFAULT_SOURCE #include "os.h" +#include "osEok.h" #include @@ -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/darwinSemphone.c b/src/os/src/darwin/dwSemphone.c similarity index 99% rename from src/os/src/darwin/darwinSemphone.c rename to src/os/src/darwin/dwSemphone.c index 5bb926732a99a1c2094366624b2a0577c85528d2..898410647ad6e23428656f6f820504126268af07 100644 --- a/src/os/src/darwin/darwinSemphone.c +++ b/src/os/src/darwin/dwSemphone.c @@ -20,7 +20,6 @@ #define _DEFAULT_SOURCE #include "os.h" - #include // #define SEM_USE_PTHREAD 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 99% rename from src/os/src/darwin/darwinSysInfo.c rename to src/os/src/darwin/dwSysInfo.c index 6e70043779d01be361f66a67b16608b56a9285ed..b3c9bd528e9459a8d5798a2ff6ca4a1664503a90 100644 --- a/src/os/src/darwin/darwinSysInfo.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/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/osDir.c b/src/os/src/detail/osDir.c index 144c59fa2db3ae24a81679de16116812fddbccc5..2a2e2519b5dadf94ee8641064735e92267394a87 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/detail/osFile.c b/src/os/src/detail/osFile.c index 538ed378798f53c09c8cb8ada2f2a1a066d8b6bf..cc12968c72eef5b3970ca68cf660de502b402e1e 100644 --- a/src/os/src/detail/osFile.c +++ b/src/os/src/detail/osFile.c @@ -16,65 +16,68 @@ #define _DEFAULT_SOURCE #include "os.h" #include "tglobal.h" +#include "tulog.h" -#ifndef TAOS_OS_FUNC_FILE_GETTMPFILEPATH +void taosClose(FileFd fd) { + close(fd); + fd = FD_INITIALIZER; +} + +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { const char *tdengineTmpFileNamePrefix = "tdengine-"; + char tmpPath[PATH_MAX]; - char tmpPath[PATH_MAX]; - int32_t len = strlen(tsTempDir); + int32_t len = (int32_t)strlen(tsTempDir); memcpy(tmpPath, tsTempDir, len); - static uint64_t seqId = 0; - - if (tmpPath[len - 1] != '/') { - tmpPath[len++] = '/'; + + if (tmpPath[len - 1] != '/' && tmpPath[len - 1] != '\\') { + tmpPath[len++] = '\\'; } strcpy(tmpPath + len, tdengineTmpFileNamePrefix); + strcat(tmpPath, tdengineTmpFileNamePrefix); if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { strcat(tmpPath, fileNamePrefix); strcat(tmpPath, "-%d-%s"); } - char rand[32] = {0}; - - sprintf(rand, "%"PRIu64, atomic_add_fetch_64(&seqId, 1)); - + char rand[8] = {0}; + taosRandStr(rand, tListLen(rand) - 1); snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); } -#endif - -int32_t taosRenameFile(char *fullPath, char *suffix, char delimiter, char **dstPath) { - int32_t ts = taosGetTimestampSec(); +#else - char fname[PATH_MAX] = {0}; // max file name length must be less than 255 +void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { + const char *tdengineTmpFileNamePrefix = "tdengine-"; - char *delimiterPos = strrchr(fullPath, delimiter); - if (delimiterPos == NULL) return -1; + char tmpPath[PATH_MAX]; + int32_t len = strlen(tsTempDir); + memcpy(tmpPath, tsTempDir, len); + static uint64_t seqId = 0; - int32_t fileNameLen = 0; - if (suffix) { - fileNameLen = snprintf(fname, PATH_MAX, "%s.%d.%s", delimiterPos + 1, ts, suffix); - } else { - fileNameLen = snprintf(fname, PATH_MAX, "%s.%d", delimiterPos + 1, ts); + if (tmpPath[len - 1] != '/') { + tmpPath[len++] = '/'; } - int32_t len = (int32_t)((delimiterPos - fullPath) + fileNameLen + 1); - if (*dstPath == NULL) { - *dstPath = calloc(1, len + 1); - if (*dstPath == NULL) return -1; + strcpy(tmpPath + len, tdengineTmpFileNamePrefix); + if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { + strcat(tmpPath, fileNamePrefix); + strcat(tmpPath, "-%d-%s"); } - strncpy(*dstPath, fullPath, (size_t)(delimiterPos - fullPath + 1)); - strncat(*dstPath, fname, (size_t)fileNameLen); - (*dstPath)[len] = 0; + char rand[32] = {0}; + + sprintf(rand, "%" PRIu64, atomic_add_fetch_64(&seqId, 1)); - return rename(fullPath, *dstPath); + snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); } -int64_t taosReadImp(int32_t fd, void *buf, int64_t count) { +#endif + +int64_t taosRead(FileFd fd, void *buf, int64_t count) { int64_t leftbytes = count; int64_t readbytes; char * tbuf = (char *)buf; @@ -98,7 +101,7 @@ int64_t taosReadImp(int32_t fd, void *buf, int64_t count) { return count; } -int64_t taosWriteImp(int32_t fd, void *buf, int64_t n) { +int64_t taosWrite(FileFd fd, void *buf, int64_t n) { int64_t nleft = n; int64_t nwritten = 0; char * tbuf = (char *)buf; @@ -118,9 +121,7 @@ int64_t taosWriteImp(int32_t fd, void *buf, int64_t n) { return n; } -int64_t taosLSeekImp(int32_t fd, int64_t offset, int32_t whence) { - return (int64_t)lseek(fd, (long)offset, whence); -} +int64_t taosLSeek(FileFd fd, int64_t offset, int32_t whence) { return (int64_t)lseek(fd, (long)offset, whence); } int64_t taosCopy(char *from, char *to) { char buffer[4096]; @@ -145,22 +146,139 @@ int64_t taosCopy(char *from, char *to) { if (bytes < sizeof(buffer)) break; } - fsync(fidto); + taosFsync(fidto); - close(fidfrom); - close(fidto); + taosClose(fidfrom); + taosClose(fidto); return size; _err: - if (fidfrom >= 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) + +#define _SEND_FILE_STEP_ 1000 + +int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) { + fseek(in_file, (int32_t)(*offset), 0); + int64_t writeLen = 0; + uint8_t buffer[_SEND_FILE_STEP_] = {0}; + + for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { + size_t rlen = fread(buffer, 1, _SEND_FILE_STEP_, in_file); + if (rlen <= 0) { + return writeLen; + } else if (rlen < _SEND_FILE_STEP_) { + fwrite(buffer, 1, rlen, out_file); + return (int64_t)(writeLen + rlen); + } else { + fwrite(buffer, 1, _SEND_FILE_STEP_, in_file); + writeLen += _SEND_FILE_STEP_; + } + } + + int64_t remain = count - writeLen; + if (remain > 0) { + size_t rlen = fread(buffer, 1, (size_t)remain, in_file); + if (rlen <= 0) { + return writeLen; + } else { + fwrite(buffer, 1, (size_t)remain, out_file); + writeLen += remain; + } + } + + return writeLen; +} + +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) { + if (offset != NULL) lseek(sfd, (int32_t)(*offset), 0); + + int64_t writeLen = 0; + uint8_t buffer[_SEND_FILE_STEP_] = {0}; + + for (int64_t len = 0; len < (count - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { + int32_t rlen = (int32_t)read(sfd, buffer, _SEND_FILE_STEP_); + if (rlen <= 0) { + return writeLen; + } else if (rlen < _SEND_FILE_STEP_) { + taosWriteSocket(dfd, buffer, rlen); + return (int64_t)(writeLen + rlen); + } else { + taosWriteSocket(dfd, buffer, _SEND_FILE_STEP_); + writeLen += _SEND_FILE_STEP_; + } + } + + int64_t remain = count - writeLen; + if (remain > 0) { + int32_t rlen = read(sfd, buffer, (int32_t)remain); + if (rlen <= 0) { + return writeLen; + } else { + taosWriteSocket(sfd, buffer, (int32_t)remain); + writeLen += remain; + } + } + + return writeLen; +} + +#elif defined(_TD_DARWIN_64) -int64_t taosSendFile(SOCKET dfd, int32_t sfd, int64_t *offset, int64_t size) { +int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t count) { + int r = 0; + if (offset) { + r = fseek(in_file, *offset, SEEK_SET); + if (r == -1) return -1; + } + off_t len = count; + while (len > 0) { + char buf[1024 * 16]; + off_t n = sizeof(buf); + if (len < n) n = len; + size_t m = fread(buf, 1, n, in_file); + if (m < n) { + int e = ferror(in_file); + if (e) return -1; + } + if (m == 0) break; + if (m != fwrite(buf, 1, m, out_file)) { + return -1; + } + len -= m; + } + return count - len; +} + +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) { + int r = 0; + if (offset) { + r = lseek(sfd, *offset, SEEK_SET); + if (r == -1) return -1; + } + off_t len = count; + while (len > 0) { + char buf[1024 * 16]; + off_t n = sizeof(buf); + if (len < n) n = len; + size_t m = read(sfd, buf, n); + if (m == -1) return -1; + if (m == 0) break; + size_t l = write(dfd, buf, m); + if (l == -1) return -1; + len -= l; + } + return count - len; +} + +#else + +int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size) { int64_t leftbytes = size; int64_t sentbytes; @@ -188,10 +306,96 @@ int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size #endif -#ifndef TAOS_OS_FUNC_FILE_FTRUNCATE +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + +int32_t taosFtruncate(int32_t fd, int64_t l_size) { + if (fd < 0) { + errno = EBADF; + uError("%s\n", "fd arg was negative"); + return -1; + } + + HANDLE h = (HANDLE)_get_osfhandle(fd); + + LARGE_INTEGER li_0; + li_0.QuadPart = (int64_t)0; + BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT); + if (!cur) { + uError("SetFilePointerEx Error getting current position in file.\n"); + return -1; + } -int32_t taosFtruncate(int32_t fd, int64_t length) { - return ftruncate(fd, length); + LARGE_INTEGER li_size; + li_size.QuadPart = l_size; + BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN); + if (cur2 == 0) { + int error = GetLastError(); + uError("SetFilePointerEx GetLastError is: %d\n", error); + switch (error) { + case ERROR_INVALID_HANDLE: + errno = EBADF; + break; + default: + errno = EIO; + break; + } + return -1; + } + + if (!SetEndOfFile(h)) { + int error = GetLastError(); + uError("SetEndOfFile GetLastError is:%d", error); + switch (error) { + case ERROR_INVALID_HANDLE: + errno = EBADF; + break; + default: + errno = EIO; + break; + } + return -1; + } + + return 0; +} + +int32_t taosFsync(FileFd fd) { + if (fd < 0) { + errno = EBADF; + uError("%s\n", "fd arg was negative"); + return -1; + } + + HANDLE h = (HANDLE)_get_osfhandle(fd); + + return FlushFileBuffers(h); +} + +int32_t taosRename(char *oldName, char *newName) { + int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); + if (code < 0) { + uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); + } else { + uTrace("successfully to rename file %s to %s", oldName, newName); + } + + return code; +} + +#else + +int32_t taosFtruncate(FileFd fd, int64_t length) { return ftruncate(fd, length); } +int32_t taosFsync(FileFd fd) { return fsync(fd); } + +int32_t taosRename(char *oldName, char *newName) { + int32_t code = rename(oldName, newName); + if (code < 0) { + uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); + } else { + uTrace("successfully to rename file %s to %s", oldName, newName); + } + + return code; } -#endif \ No newline at end of file +#endif diff --git a/src/os/src/detail/osRand.c b/src/os/src/detail/osRand.c index b322a88684e63776b432d2f4025b3d16fc614861..0dda908bb35c68513dba150e8380846c36aa2893 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/osSemphone.c b/src/os/src/detail/osSemphone.c index 2bf2f2448752bf468497fc48a8871c5f0120b9ab..06907d52582e8cdb5cfdbe6da4724c4cf2bc8151 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/detail/osSignal.c b/src/os/src/detail/osSignal.c index e1a0e84e7fe689bdf92a9a7bafbddb80ccd03a4b..4467a607b2c9b235d925d2dca2f06e7875fcd0dc 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/osSleep.c b/src/os/src/detail/osSleep.c new file mode 100644 index 0000000000000000000000000000000000000000..9c3231fd13064fc1d3d072d1a20d205b48e56ec6 --- /dev/null +++ b/src/os/src/detail/osSleep.c @@ -0,0 +1,57 @@ +/* + * 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) { +#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/osSocket.c b/src/os/src/detail/osSocket.c index db976acccd7d61223fc742b7dcdb736bea6a5f57..7ce9d6eb06621f0a691699020cff13b9c15a9a88 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/detail/osString.c b/src/os/src/detail/osString.c index 59f47b4815badd8411b54ea997bf6b46f3a18a27..2c49797d83dd4bb53b2fef69091e28be7194461e 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/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index bbda08aa25cdf6adb91a53157d8cd6be291d9381..d0b284e1cab6717ab7b589557e4545ea744efa33 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 c1135ce292c4ef0a5ae968525ca2685a97b6f62e..b054f08c7842ed405f818b26be6040c543fa7644 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) || defined(_TD_DARWIN_64)) static void taosDeleteTimer(void *tharg) { timer_t *pTimer = tharg; @@ -104,42 +104,3 @@ void taosUninitTimer() { } #endif - -#ifndef TAOS_OS_FUNC_TIMER_SLEEP -/* - to make taosMsleep work, - signal SIGALRM shall be blocked in the calling thread, - - sigset_t set; - sigemptyset(&set); - sigaddset(&set, SIGALRM); - pthread_sigmask(SIG_BLOCK, &set, NULL); -*/ -void taosMsleep(int mseconds) { -#ifdef __APPLE__ - taos_block_sigalrm(); -#endif // __APPLE__ -#if 1 - usleep(mseconds * 1000); -#else - struct timeval timeout; - int seconds, useconds; - - seconds = mseconds / 1000; - useconds = (mseconds % 1000) * 1000; - timeout.tv_sec = seconds; - timeout.tv_usec = useconds; - - /* sigset_t set; */ - /* sigemptyset(&set); */ - /* sigaddset(&set, SIGALRM); */ - /* pthread_sigmask(SIG_BLOCK, &set, NULL); */ - - select(0, NULL, NULL, NULL, &timeout); - -/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */ -#endif - -} - -#endif diff --git a/src/os/src/windows/wFile.c b/src/os/src/windows/wFile.c deleted file mode 100644 index 3bfe1c1b5dd24185407b2e2cd1b94ff621089b0b..0000000000000000000000000000000000000000 --- a/src/os/src/windows/wFile.c +++ /dev/null @@ -1,184 +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" - -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/wGetline.c b/src/os/src/windows/wGetline.c index 3e8701e19b3ee420648bec984874416410cd14f1..553aecaf0a9be65fb5d532668d28ee1a77fbbd39 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 @@ -40,10 +41,10 @@ null terminator), or -1 on error or EOF. On a -1 return, the caller should check feof(), if not then errno has been set to indicate the error. */ -int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, 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 +60,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 +80,7 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) else *n += MIN_CHUNK; - nchars_avail = (int)(*n + *lineptr - read_pos); + nchars_avail = (int32_t)(*n + *lineptr - read_pos); *lineptr = realloc(*lineptr, *n); if (!*lineptr) { errno = ENOMEM; @@ -115,10 +116,8 @@ int getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int offset) /* Done - NUL terminate and return the number of chars read. */ *read_pos = '\0'; - ret = (int)(read_pos - (*lineptr + offset)); + ret = (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 b270dab2f4364c014c0a0b8b28993d0299d11847..0000000000000000000000000000000000000000 --- 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 4e6ee15e772c5af56b4ebd11e74fc44dd57946f5..ad0d87418dba082735a0e7bd25b8ae15660f9c7a 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,4 +89,11 @@ const char *taosInetNtoa(struct in_addr ipInt) { return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); } -#endif \ No newline at end of file +//#endif +#endif + +#if defined(_TD_GO_DLL_) + +uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); } + +#endif diff --git a/src/os/src/windows/wString.c b/src/os/src/windows/wString.c index 67237e655cd2916ec2ec80daa01e7a0f9ae0d3e3..96a604ae6e3bfb2088a376894c7083a9514ae67f 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. */ diff --git a/src/os/src/windows/wTimer.c b/src/os/src/windows/wTimer.c index 32e04746f190b835d3cbc1837d5cd110a8709983..c5984f915a1baeb33a64f9eb46359b324c5df6e6 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 1f43c5b33cca044744a2783a251f76bcb827d34a..5d599ff08a5a42bb22407c57620cfc542405d348 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/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 3162ab2e4cbabc2a1ce9ed863589e3be0e92f75f..09857610d20b5bb219c86035941d53bc8d0a987b 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/src/rpc/test/rserver.c b/src/rpc/test/rserver.c index 44c5cd6ab48810496c1c141ba8563e1dead1de15..64960db0446413ebce1978b7fe310b6a34c34f1c 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 792efcdb2e0cc0245203d91e80369205cab74d56..dcb5eadfab6c909ddd169fb3372799f7088c1903 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 c9f087a5cfe25967786b07c03217c89f1e1dd249..f6e721e3d3a5df205d3abfa908e7678e27e121d1 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 c0cc8ce33942d1e6784db0f7f4b86757f8f7f593..57d45cc8c00dab5b760f8e915b967e37217f9b64 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 dd621b3199189bc30f851c9a9289e4b10f6510f3..455c885e753e35724d27ec223f86ebf04751286f 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 c9cd366c6406cb3212fc271f924e1c7b4c42995d..2e1d761fcf8d3f51a2dff067a6020f125a3df5c9 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 d22bc17cbeda570f119a5a6e67637382f3a25bf8..d1aee5a3d39ffbdcbd72aa5459e4bd64858c4bf4 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; diff --git a/tests/examples/c/epoll.c b/tests/examples/c/epoll.c index de7c5989d1ecdaec578e4322ac49491587ad851b..284268ac4328b5bc814ab8d30931ec92c5c11523 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__