From ee82eb602c6398f5fcd25f9b9c6ce428fac38bc7 Mon Sep 17 00:00:00 2001 From: slguan Date: Fri, 31 Jul 2020 10:17:15 +0800 Subject: [PATCH] TD-992 cmake file for w64 --- src/client/src/tscSubquery.c | 6 +- src/os/inc/osSpec.h | 2 +- src/os/inc/osWindows64.h | 571 ++++++++---------- src/os/src/detail/osFile.c | 6 +- src/os/src/detail/osTimer.c | 5 +- src/os/src/windows64/twindows.c | 410 ------------- src/os/src/windows64/twinsocket.c | 117 ---- src/os/src/windows64/twintcpclient.c | 39 -- src/os/src/windows64/w64Atomic.c | 172 ++++++ src/os/src/windows64/w64Coredump.c | 23 + src/os/src/windows64/{twinenv.c => w64Env.c} | 0 src/os/src/windows64/w64File.c | 2 +- src/os/src/windows64/w64FileOp.c | 59 ++ .../windows64/{twingetline.c => w64Getline.c} | 0 src/os/src/windows64/w64Godll.c | 34 ++ src/os/src/windows64/w64Lz4.c | 46 ++ .../windows64/{twinmsghdr.c => w64Msghdr.c} | 49 +- src/os/src/windows64/w64PThread.c | 34 ++ src/os/src/windows64/w64Socket.c | 64 ++ src/os/src/windows64/w64String.c | 92 +++ .../{twinstrptime.c => w64Strptime.c} | 0 src/os/src/windows64/w64Sysinfo.c | 116 ++++ .../src/windows64/{twintime.c => w64Time.c} | 0 .../src/windows64/{twintimer.c => w64Timer.c} | 7 +- src/os/src/windows64/w64Util.c | 117 ++++ .../{twintcpserver.c => w64Wordexp.c} | 27 +- src/query/src/qExtbuffer.c | 2 +- src/query/src/qResultbuf.c | 2 +- src/query/src/qTsbuf.c | 2 +- src/query/tests/unitTest.cpp | 2 +- 30 files changed, 1067 insertions(+), 939 deletions(-) delete mode 100644 src/os/src/windows64/twindows.c delete mode 100644 src/os/src/windows64/twinsocket.c delete mode 100644 src/os/src/windows64/twintcpclient.c create mode 100644 src/os/src/windows64/w64Atomic.c create mode 100644 src/os/src/windows64/w64Coredump.c rename src/os/src/windows64/{twinenv.c => w64Env.c} (100%) create mode 100644 src/os/src/windows64/w64FileOp.c rename src/os/src/windows64/{twingetline.c => w64Getline.c} (100%) create mode 100644 src/os/src/windows64/w64Godll.c create mode 100644 src/os/src/windows64/w64Lz4.c rename src/os/src/windows64/{twinmsghdr.c => w64Msghdr.c} (50%) create mode 100644 src/os/src/windows64/w64PThread.c create mode 100644 src/os/src/windows64/w64Socket.c create mode 100644 src/os/src/windows64/w64String.c rename src/os/src/windows64/{twinstrptime.c => w64Strptime.c} (100%) create mode 100644 src/os/src/windows64/w64Sysinfo.c rename src/os/src/windows64/{twintime.c => w64Time.c} (100%) rename src/os/src/windows64/{twintimer.c => w64Timer.c} (93%) create mode 100644 src/os/src/windows64/w64Util.c rename src/os/src/windows64/{twintcpserver.c => w64Wordexp.c} (55%) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 15e02799aa..79c45daa20 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -183,7 +183,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in pSupporter->uid = pTableMetaInfo->pTableMeta->id.uid; assert (pSupporter->uid != 0); - getTmpfilePath("join-", pSupporter->path); + taosGetTmpfilePath("join-", pSupporter->path); pSupporter->f = fopen(pSupporter->path, "w"); // todo handle error @@ -773,7 +773,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow // continue to retrieve ts-comp data from vnode if (!pRes->completed) { - getTmpfilePath("ts-join", pSupporter->path); + taosGetTmpfilePath("ts-join", pSupporter->path); pSupporter->f = fopen(pSupporter->path, "w"); pRes->row = pRes->numOfRows; @@ -797,7 +797,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow tscResetForNextRetrieve(&pSql->res); assert(pSupporter->f == NULL); - getTmpfilePath("ts-join", pSupporter->path); + taosGetTmpfilePath("ts-join", pSupporter->path); // TODO check for failure pSupporter->f = fopen(pSupporter->path, "w"); diff --git a/src/os/inc/osSpec.h b/src/os/inc/osSpec.h index 18dd8b75d8..f0223c3ac5 100644 --- a/src/os/inc/osSpec.h +++ b/src/os/inc/osSpec.h @@ -318,7 +318,7 @@ void taosRandStr(char* str, int32_t size); uint32_t trand(void); // TAOS_OS_FUNC_FILE -void getTmpfilePath(const char *fileNamePrefix, char *dstPath); +void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath); int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath); // USE_LIBICONV diff --git a/src/os/inc/osWindows64.h b/src/os/inc/osWindows64.h index b4687afb82..75685744aa 100644 --- a/src/os/inc/osWindows64.h +++ b/src/os/inc/osWindows64.h @@ -49,6 +49,68 @@ extern "C" { #endif #define TAOS_OS_FUNC_WCHAR +#define TAOS_OS_FUNC_FILE +#define TAOS_OS_FUNC_SLEEP +#define TAOS_OS_FUNC_TIMER +#define TAOS_OS_FUNC_SOCKET +#define TAOS_OS_FUNC_PTHREAD + +#define TAOS_OS_FUNC_FILEOP + #define taosFSendFile(outfile, infile, offset, count) taosFSendFileImp(outfile, infile, offset, size) + #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) + +#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_UTIL + #ifdef _TD_GO_DLL_ + int64_t tsosStr2int64(char *str); + uint64_t htonll(uint64_t val); + #else + #define tsosStr2int64 _atoi64 + #endif + +#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_NETWORK + #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 taosWriteSocket(fd, buf, len) send(fd, buf, len, 0) + #define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0) + #define taosCloseSocket(fd) closesocket(fd) + +#define TAOS_OS_DEF_TIME + #ifdef _TD_GO_DLL_ + #define MILLISECOND_PER_SECOND (1000LL) + #else + #define MILLISECOND_PER_SECOND (1000i64) + #endif + +typedef int (*__compar_fn_t)(const void *, const void *); +int getline(char **lineptr, size_t *n, FILE *stream); +int gettimeofday(struct timeval *tv, struct timezone *tz); +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); + +#define strdup _strdup +#define ssize_t int // for function open in stat.h #define S_IRWXU _S_IREAD @@ -79,12 +141,6 @@ extern "C" { #define strncasecmp _strnicmp #define wcsncasecmp _wcsnicmp #define strtok_r strtok_s -#ifdef _TD_GO_DLL_ - int64_t tsosStr2int64(char *str); - uint64_t htonll(uint64_t val); -#else - #define tsosStr2int64 _atoi64 -#endif #define snprintf _snprintf #define in_addr_t unsigned long @@ -96,327 +152,212 @@ extern "C" { #define PATH_MAX 256 #endif -#define taosCloseSocket(fd) closesocket(fd) -#define taosWriteSocket(fd, buf, len) send(fd, buf, len, 0) -#define taosReadSocket(fd, buf, len) recv(fd, buf, len, 0) - -#if defined(_M_ARM) || defined(_M_ARM64) - -/* the '__iso_volatile' functions does not use a memory fence, so these - * definitions are incorrect, comment out as we don't support Windows on - * ARM at present. - -#define atomic_load_8(ptr) __iso_volatile_load8((const volatile __int8*)(ptr)) -#define atomic_load_16(ptr) __iso_volatile_load16((const volatile __int16*)(ptr)) -#define atomic_load_32(ptr) __iso_volatile_load32((const volatile __int32*)(ptr)) -#define atomic_load_64(ptr) __iso_volatile_load64((const volatile __int64*)(ptr)) - -#define atomic_store_8(ptr, val) __iso_volatile_store8((volatile __int8*)(ptr), (__int8)(val)) -#define atomic_store_16(ptr, val) __iso_volatile_store16((volatile __int16*)(ptr), (__int16)(val)) -#define atomic_store_32(ptr, val) __iso_volatile_store32((volatile __int32*)(ptr), (__int32)(val)) -#define atomic_store_64(ptr, val) __iso_volatile_store64((volatile __int64*)(ptr), (__int64)(val)) - -#ifdef _M_ARM64 -#define atomic_load_ptr atomic_load_64 -#define atomic_store_ptr atomic_store_64 -#else -#define atomic_load_ptr atomic_load_32 -#define atomic_store_ptr atomic_store_32 -#endif -*/ -#else - -#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)) - -#endif - -#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)) -#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) - -#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); - -#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 _WIN64 - #define atomic_add_fetch_ptr atomic_add_fetch_64 -#else - #define atomic_add_fetch_ptr atomic_add_fetch_32 -#endif -#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_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val)) -#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val)) -#ifdef _WIN64 - #define atomic_fetch_add_ptr atomic_fetch_add_64 -#else - #define atomic_fetch_add_ptr atomic_fetch_add_32 -#endif - -#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)) -#ifdef _WIN64 - #define atomic_sub_fetch_ptr atomic_sub_fetch_64 -#else - #define atomic_sub_fetch_ptr atomic_sub_fetch_32 -#endif - -#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)) -#ifdef _WIN64 - #define atomic_fetch_sub_ptr atomic_fetch_sub_64 -#else - #define atomic_fetch_sub_ptr atomic_fetch_sub_32 -#endif -#ifndef _TD_GO_DLL_ - char interlocked_and_fetch_8(char volatile* ptr, char val); - short interlocked_and_fetch_16(short volatile* ptr, short val); -#endif -long interlocked_and_fetch_32(long volatile* ptr, long val); -__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); - -#ifndef _TD_GO_DLL_ - #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)) -#endif -#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)) -#ifdef _WIN64 - #define atomic_and_fetch_ptr atomic_and_fetch_64 -#else - #define atomic_and_fetch_ptr atomic_and_fetch_32 -#endif -#ifndef _TD_GO_DLL_ - #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)) -#endif -#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val)) - -#ifdef _M_IX86 - __int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val); - #define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val)) -#else - #define atomic_fetch_and_64(ptr, val) _InterlockedAnd64((__int64 volatile*)(ptr), (__int64)(val)) -#endif - -#ifdef _WIN64 - #define atomic_fetch_and_ptr atomic_fetch_and_64 -#else - #define atomic_fetch_and_ptr atomic_fetch_and_32 -#endif -#ifndef _TD_GO_DLL_ - char interlocked_or_fetch_8(char volatile* ptr, char val); - short interlocked_or_fetch_16(short volatile* ptr, short val); -#endif -long interlocked_or_fetch_32(long volatile* ptr, long val); -__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); - -#ifndef _TD_GO_DLL_ - #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)) -#endif -#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)) -#ifdef _WIN64 - #define atomic_or_fetch_ptr atomic_or_fetch_64 -#else - #define atomic_or_fetch_ptr atomic_or_fetch_32 -#endif -#ifndef _TD_GO_DLL_ - #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)) -#endif -#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val)) - -#ifdef _M_IX86 - __int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val); - #define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val)) -#else - #define atomic_fetch_or_64(ptr, val) _InterlockedOr64((__int64 volatile*)(ptr), (__int64)(val)) -#endif - -#ifdef _WIN64 - #define atomic_fetch_or_ptr atomic_fetch_or_64 -#else - #define atomic_fetch_or_ptr atomic_fetch_or_32 -#endif - -#ifndef _TD_GO_DLL_ - char interlocked_xor_fetch_8(char volatile* ptr, char val); - short interlocked_xor_fetch_16(short volatile* ptr, short val); -#endif -long interlocked_xor_fetch_32(long volatile* ptr, long val); -__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); - -#ifndef _TD_GO_DLL_ - #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)) -#endif -#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)) -#ifdef _WIN64 - #define atomic_xor_fetch_ptr atomic_xor_fetch_64 -#else - #define atomic_xor_fetch_ptr atomic_xor_fetch_32 -#endif - -#ifndef _TD_GO_DLL_ - #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)) -#endif -#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val)) - -#ifdef _M_IX86 - __int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val); - #define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val)) -#else - #define atomic_fetch_xor_64(ptr, val) _InterlockedXor64((__int64 volatile*)(ptr), (__int64)(val)) -#endif - -#ifdef _WIN64 - #define atomic_fetch_xor_ptr atomic_fetch_xor_64 -#else - #define atomic_fetch_xor_ptr atomic_fetch_xor_32 -#endif - -#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)) - -#ifdef _TD_GO_DLL_ - #define MILLISECOND_PER_SECOND (1000LL) -#else - #define MILLISECOND_PER_SECOND (1000i64) -#endif - -#define tsem_t sem_t -#define tsem_init sem_init -#define tsem_wait sem_wait -#define tsem_post sem_post -#define tsem_destroy sem_destroy - -void osInit(); - -int getline(char **lineptr, size_t *n, FILE *stream); - -int taosWinSetTimer(int ms, void(*callback)(int)); - -int gettimeofday(struct timeval *tv, struct timezone *tz); - -struct tm *localtime_r(const time_t *timep, struct tm *result); - -char *strptime(const char *buf, const char *fmt, struct tm *tm); - -bool taosCheckPthreadValid(pthread_t thread); - -void taosResetPthread(pthread_t *thread); - -int64_t taosGetPthreadId(); - -int taosSetNonblocking(int sock, int on); - -int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen); - - -void taosPrintOsInfo(); - -void taosGetSystemInfo(); - -void taosKillSystem(); - -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); - //for signal, not dispose #define SIGALRM 1234 typedef int sigset_t; - struct sigaction { void (*sa_handler)(int); }; +int sigaction(int, struct sigaction *, void *); typedef struct { - int we_wordc; + int we_wordc; char **we_wordv; - int we_offs; - char wordPos[20]; + int we_offs; + char wordPos[20]; } wordexp_t; - -int wordexp(const char *words, wordexp_t *pwordexp, int flags); - +int wordexp(const char *words, wordexp_t *pwordexp, int flags); void wordfree(wordexp_t *pwordexp); -int flock(int fd, int option); - -int fsync(int filedes); - -char *getpass(const char *prefix); - -char *strsep(char **stringp, const char *delim); - -typedef int(*__compar_fn_t)(const void *, const void *); - -int sigaction(int, struct sigaction *, void *); - -void sleep(int mseconds); - -bool taosSkipSocketCheck(); - -int fsendfile(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count); - -#define ssize_t int - -#define strdup _strdup - -char *strndup(const char *s, size_t n); - -void taosSetCoreDump(); +#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)) + #define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) + + #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); + + #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 _WIN64 + #define atomic_add_fetch_ptr atomic_add_fetch_64 + #else + #define atomic_add_fetch_ptr atomic_add_fetch_32 + #endif + + #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_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val)) + #define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val)) + #ifdef _WIN64 + #define atomic_fetch_add_ptr atomic_fetch_add_64 + #else + #define atomic_fetch_add_ptr atomic_fetch_add_32 + #endif + + #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)) + #ifdef _WIN64 + #define atomic_sub_fetch_ptr atomic_sub_fetch_64 + #else + #define atomic_sub_fetch_ptr atomic_sub_fetch_32 + #endif + + #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)) + #ifdef _WIN64 + #define atomic_fetch_sub_ptr atomic_fetch_sub_64 + #else + #define atomic_fetch_sub_ptr atomic_fetch_sub_32 + #endif + + #ifndef _TD_GO_DLL_ + char interlocked_and_fetch_8(char volatile* ptr, char val); + short interlocked_and_fetch_16(short volatile* ptr, short val); + #endif + long interlocked_and_fetch_32(long volatile* ptr, long val); + __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); + + #ifndef _TD_GO_DLL_ + #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)) + #endif + #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)) + #ifdef _WIN64 + #define atomic_and_fetch_ptr atomic_and_fetch_64 + #else + #define atomic_and_fetch_ptr atomic_and_fetch_32 + #endif + #ifndef _TD_GO_DLL_ + #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)) + #endif + #define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val)) + + #ifdef _M_IX86 + __int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val); + #define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val)) + #else + #define atomic_fetch_and_64(ptr, val) _InterlockedAnd64((__int64 volatile*)(ptr), (__int64)(val)) + #endif + + #ifdef _WIN64 + #define atomic_fetch_and_ptr atomic_fetch_and_64 + #else + #define atomic_fetch_and_ptr atomic_fetch_and_32 + #endif + #ifndef _TD_GO_DLL_ + char interlocked_or_fetch_8(char volatile* ptr, char val); + short interlocked_or_fetch_16(short volatile* ptr, short val); + #endif + long interlocked_or_fetch_32(long volatile* ptr, long val); + __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); + + #ifndef _TD_GO_DLL_ + #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)) + #endif + #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)) + #ifdef _WIN64 + #define atomic_or_fetch_ptr atomic_or_fetch_64 + #else + #define atomic_or_fetch_ptr atomic_or_fetch_32 + #endif + #ifndef _TD_GO_DLL_ + #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)) + #endif + #define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val)) + + #ifdef _M_IX86 + __int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val); + #define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val)) + #else + #define atomic_fetch_or_64(ptr, val) _InterlockedOr64((__int64 volatile*)(ptr), (__int64)(val)) + #endif + + #ifdef _WIN64 + #define atomic_fetch_or_ptr atomic_fetch_or_64 + #else + #define atomic_fetch_or_ptr atomic_fetch_or_32 + #endif + + #ifndef _TD_GO_DLL_ + char interlocked_xor_fetch_8(char volatile* ptr, char val); + short interlocked_xor_fetch_16(short volatile* ptr, short val); + #endif + long interlocked_xor_fetch_32(long volatile* ptr, long val); + __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); + + #ifndef _TD_GO_DLL_ + #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)) + #endif + #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)) + #ifdef _WIN64 + #define atomic_xor_fetch_ptr atomic_xor_fetch_64 + #else + #define atomic_xor_fetch_ptr atomic_xor_fetch_32 + #endif + + #ifndef _TD_GO_DLL_ + #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)) + #endif + #define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val)) + + #ifdef _M_IX86 + __int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val); + #define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val)) + #else + #define atomic_fetch_xor_64(ptr, val) _InterlockedXor64((__int64 volatile*)(ptr), (__int64)(val)) + #endif + + #ifdef _WIN64 + #define atomic_fetch_xor_ptr atomic_fetch_xor_64 + #else + #define atomic_fetch_xor_ptr atomic_fetch_xor_32 + #endif #ifdef __cplusplus } diff --git a/src/os/src/detail/osFile.c b/src/os/src/detail/osFile.c index 5502dfb4a6..7b5d5fbfcc 100644 --- a/src/os/src/detail/osFile.c +++ b/src/os/src/detail/osFile.c @@ -19,7 +19,7 @@ #ifndef TAOS_OS_FUNC_FILE -void getTmpfilePath(const char *fileNamePrefix, char *dstPath) { +void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { const char* tdengineTmpFileNamePrefix = "tdengine-"; char tmpPath[PATH_MAX]; @@ -37,6 +37,8 @@ void getTmpfilePath(const char *fileNamePrefix, char *dstPath) { snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); } +#endif + // rename file name int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath) { int32_t ts = taosGetTimestampSec(); @@ -64,5 +66,3 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP return rename(fullPath, *dstPath); } - -#endif \ No newline at end of file diff --git a/src/os/src/detail/osTimer.c b/src/os/src/detail/osTimer.c index 7c6346205a..bea5a718de 100644 --- a/src/os/src/detail/osTimer.c +++ b/src/os/src/detail/osTimer.c @@ -102,6 +102,7 @@ void taosUninitTimer() { #endif +#ifndef TAOS_OS_FUNC_SLEEP /* to make taosMsleep work, signal SIGALRM shall be blocked in the calling thread, @@ -128,4 +129,6 @@ void taosMsleep(int mseconds) { select(0, NULL, NULL, NULL, &timeout); /* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */ -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/os/src/windows64/twindows.c b/src/os/src/windows64/twindows.c deleted file mode 100644 index 4284dcb14e..0000000000 --- a/src/os/src/windows64/twindows.c +++ /dev/null @@ -1,410 +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" - -bool taosCheckPthreadValid(pthread_t thread) { - return thread.p != NULL; -} - -void taosResetPthread(pthread_t *thread) { - thread->p = 0; -} - -int64_t taosGetPthreadId() { -#ifdef PTW32_VERSION - return pthread_getw32threadid_np(pthread_self()); -#else - return (int64_t)pthread_self(); -#endif -} - -int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) { - if (level == SOL_SOCKET && optname == TCP_KEEPCNT) { - return 0; - } - - if (level == SOL_TCP && optname == TCP_KEEPIDLE) { - return 0; - } - - if (level == SOL_TCP && optname == TCP_KEEPINTVL) { - return 0; - } - - return setsockopt(socketfd, level, optname, optval, optlen); -} - -// add -char interlocked_add_fetch_8(char volatile* ptr, char val) { - #ifdef _TD_GO_DLL_ - return __sync_fetch_and_add(ptr, val) + val; - #else - return _InterlockedExchangeAdd8(ptr, val) + val; - #endif -} - -short interlocked_add_fetch_16(short volatile* ptr, short val) { - #ifdef _TD_GO_DLL_ - return __sync_fetch_and_add(ptr, val) + val; - #else - return _InterlockedExchangeAdd16(ptr, val) + val; - #endif -} - -long interlocked_add_fetch_32(long volatile* ptr, long val) { - return _InterlockedExchangeAdd(ptr, val) + val; -} - -__int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) { - return _InterlockedExchangeAdd64(ptr, val) + val; -} - -// and -#ifndef _TD_GO_DLL_ -char interlocked_and_fetch_8(char volatile* ptr, char val) { - return _InterlockedAnd8(ptr, val) & val; -} - -short interlocked_and_fetch_16(short volatile* ptr, short val) { - return _InterlockedAnd16(ptr, val) & val; -} -#endif - -long interlocked_and_fetch_32(long volatile* ptr, long val) { - return _InterlockedAnd(ptr, val) & val; -} - -#ifndef _M_IX86 - -__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) { - return _InterlockedAnd64(ptr, val) & val; -} - -#else - -__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) { - __int64 old, res; - do { - old = *ptr; - res = old & val; - } while(_InterlockedCompareExchange64(ptr, res, old) != old); - return res; -} - -__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val) { - __int64 old; - do { - old = *ptr; - } while(_InterlockedCompareExchange64(ptr, old & val, old) != old); - return old; -} - -#endif - -// or -#ifndef _TD_GO_DLL_ -char interlocked_or_fetch_8(char volatile* ptr, char val) { - return _InterlockedOr8(ptr, val) | val; -} - -short interlocked_or_fetch_16(short volatile* ptr, short val) { - return _InterlockedOr16(ptr, val) | val; -} -#endif -long interlocked_or_fetch_32(long volatile* ptr, long val) { - return _InterlockedOr(ptr, val) | val; -} - -#ifndef _M_IX86 - -__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) { - return _InterlockedOr64(ptr, val) & val; -} - -#else - -__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) { - __int64 old, res; - do { - old = *ptr; - res = old | val; - } while(_InterlockedCompareExchange64(ptr, res, old) != old); - return res; -} - -__int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val) { - __int64 old; - do { - old = *ptr; - } while(_InterlockedCompareExchange64(ptr, old | val, old) != old); - return old; -} - -#endif - -// xor -#ifndef _TD_GO_DLL_ -char interlocked_xor_fetch_8(char volatile* ptr, char val) { - return _InterlockedXor8(ptr, val) ^ val; -} - -short interlocked_xor_fetch_16(short volatile* ptr, short val) { - return _InterlockedXor16(ptr, val) ^ val; -} -#endif -long interlocked_xor_fetch_32(long volatile* ptr, long val) { - return _InterlockedXor(ptr, val) ^ val; -} - -#ifndef _M_IX86 - -__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) { - return _InterlockedXor64(ptr, val) ^ val; -} - -#else - -__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) { - __int64 old, res; - do { - old = *ptr; - res = old ^ val; - } while(_InterlockedCompareExchange64(ptr, res, old) != old); - return res; -} - -__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val) { - __int64 old; - do { - old = *ptr; - } while(_InterlockedCompareExchange64(ptr, old ^ val, old) != old); - return old; -} - -#endif - -void taosPrintOsInfo() {} - -void taosGetSystemTimezone() { - // get and set default timezone - SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); - if (cfg_timezone && cfg_timezone->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { - char *tz = getenv("TZ"); - if (tz == NULL || strlen(tz) == 0) { - strcpy(tsTimezone, "not configured"); - } - else { - strcpy(tsTimezone, tz); - } - cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; - uInfo("timezone not configured, use default"); - } -} - -void taosGetSystemLocale() { - // get and set default locale - SGlobalCfg *cfg_locale = taosGetConfigOption("locale"); - if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { - char *locale = setlocale(LC_CTYPE, "chs"); - if (locale != NULL) { - tstrncpy(tsLocale, locale, sizeof(tsLocale)); - cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; - uInfo("locale not configured, set to default:%s", tsLocale); - } - } - - SGlobalCfg *cfg_charset = taosGetConfigOption("charset"); - if (cfg_charset && cfg_charset->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { - strcpy(tsCharset, "cp936"); - cfg_charset->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; - uInfo("charset not configured, set to default:%s", tsCharset); - } -} - -void taosGetSystemInfo() { - taosGetSystemTimezone(); - taosGetSystemLocale(); -} - -void taosKillSystem() { - exit(0); -} - -/* - * Get next token from string *stringp, where tokens are possibly-empty - * strings separated by characters from delim. - * - * Writes NULs into the string at *stringp to end tokens. - * delim need not remain constant from call to call. - * On return, *stringp points past the last NUL written (if there might - * be further tokens), or is NULL (if there are definitely no moretokens). - * - * If *stringp is NULL, strsep returns NULL. - */ -char *strsep(char **stringp, const char *delim) { - char *s; - const char *spanp; - int c, sc; - char *tok; - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} - -char *getpass(const char *prefix) { - static char passwd[TSDB_KEY_LEN] = {0}; - - printf("%s", prefix); - scanf("%s", passwd); - - char n = getchar(); - return passwd; -} - -int flock(int fd, int option) { - return 0; -} - -int fsync(int filedes) { - return 0; -} - -int sigaction(int sig, struct sigaction *d, void *p) { - return 0; -} - -int wordexp(const char *words, wordexp_t *pwordexp, int flags) { - pwordexp->we_offs = 0; - pwordexp->we_wordc = 1; - pwordexp->we_wordv = (char **)(pwordexp->wordPos); - pwordexp->we_wordv[0] = (char *)words; - return 0; -} - -void wordfree(wordexp_t *pwordexp) {} - -void taosGetDisk() {} - -bool taosSkipSocketCheck() { - return false; -} - -#define _SEND_FILE_STEP_ 1000 - -int fsendfile(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count) { - fseek(in_file, (int32_t)(*offset), 0); - int writeLen = 0; - uint8_t buffer[_SEND_FILE_STEP_] = { 0 }; - - for (int 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 (int)(writeLen + rlen); - } - else { - fwrite(buffer, 1, _SEND_FILE_STEP_, in_file); - writeLen += _SEND_FILE_STEP_; - } - } - - int remain = count - writeLen; - if (remain > 0) { - size_t rlen = fread(buffer, 1, remain, in_file); - if (rlen <= 0) { - return writeLen; - } - else { - fwrite(buffer, 1, remain, out_file); - writeLen += remain; - } - } - - return writeLen; -} - -int32_t BUILDIN_CLZL(uint64_t val) { - unsigned long r = 0; - _BitScanReverse64(&r, val); - return (int)(r >> 3); -} - -int32_t BUILDIN_CLZ(uint32_t val) { - unsigned long r = 0; - _BitScanReverse(&r, val); - return (int)(r >> 3); -} - -int32_t BUILDIN_CTZL(uint64_t val) { - unsigned long r = 0; - _BitScanForward64(&r, val); - return (int)(r >> 3); -} - -int32_t BUILDIN_CTZ(uint32_t val) { - unsigned long r = 0; - _BitScanForward(&r, val); - return (int)(r >> 3); -} - -char *strndup(const char *s, size_t n) { - int len = strlen(s); - if (len >= n) { - len = n; - } - - char *r = calloc(len + 1, 1); - memcpy(r, s, len); - r[len] = 0; - return r; -} - -void taosSetCoreDump() {} - -#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 \ No newline at end of file diff --git a/src/os/src/windows64/twinsocket.c b/src/os/src/windows64/twinsocket.c deleted file mode 100644 index 0690a4ceb1..0000000000 --- a/src/os/src/windows64/twinsocket.c +++ /dev/null @@ -1,117 +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 . - */ - -#include -#include -#include -#include -#include -#include -#include - -void taosWinSocketInit() { - static char flag = 0; - if (flag == 0) { - WORD wVersionRequested; - WSADATA wsaData; - wVersionRequested = MAKEWORD(1, 1); - if (WSAStartup(wVersionRequested, &wsaData) == 0) { - flag = 1; - } - } -} - -int taosSetNonblocking(SOCKET sock, int on) { - u_long mode; - if (on) { - mode = 1; - ioctlsocket(sock, FIONBIO, &mode); - } - else { - mode = 0; - ioctlsocket(sock, FIONBIO, &mode); - } - return 0; -} - -int taosGetPrivateIp(char *const ip) { - PIP_ADAPTER_ADDRESSES pAddresses = 0; - IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = 0; - ULONG outBufLen = 0; - DWORD dwRetVal = 0; - char buff[100]; - DWORD bufflen = 100; - int i; - int flag = -1; - - taosWinSocketInit(); - GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAddresses, &outBufLen); - pAddresses = (IP_ADAPTER_ADDRESSES *)malloc(outBufLen); - if ((dwRetVal = GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST, NULL, pAddresses, &outBufLen)) == NO_ERROR) { - while (pAddresses) { - if (wcsstr(pAddresses->FriendlyName, L"Loopback") != 0) { - pAddresses = pAddresses->Next; - continue; - } - if (pAddresses->OperStatus == IfOperStatusUp) { - //printf("%s, Status: active\n", pAddresses->FriendlyName); - } - else { - //printf("%s, Status: deactive\n", pAddresses->FriendlyName); - pAddresses = pAddresses->Next; - continue; - } - - PIP_ADAPTER_UNICAST_ADDRESS pUnicast = pAddresses->FirstUnicastAddress; - for (i = 0; pUnicast != NULL; i++) { - if (pUnicast->Address.lpSockaddr->sa_family == AF_INET) { - struct sockaddr_in *sa_in = (struct sockaddr_in *)pUnicast->Address.lpSockaddr; - strcpy(ip, inet_ntop(AF_INET, &(sa_in->sin_addr), buff, bufflen)); - flag = 0; - //printf("%s\n", ip); - } - else if (pUnicast->Address.lpSockaddr->sa_family == AF_INET6) { - struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)pUnicast->Address.lpSockaddr; - strcpy(ip, inet_ntop(AF_INET6, &(sa_in6->sin6_addr), buff, bufflen)); - flag = 0; - //printf("%s\n", ip); - } - else { - } - pUnicast = pUnicast->Next; - } - pAddresses = pAddresses->Next; - } - } - else { - LPVOID lpMsgBuf; - printf("Call to GetAdaptersAddresses failed.\n"); - if (FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dwRetVal, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) & lpMsgBuf, - 0, - NULL)) { - printf("\tError: %s", lpMsgBuf); - } - LocalFree(lpMsgBuf); - } - free(pAddresses); - return flag; -} diff --git a/src/os/src/windows64/twintcpclient.c b/src/os/src/windows64/twintcpclient.c deleted file mode 100644 index 4736042aba..0000000000 --- a/src/os/src/windows64/twintcpclient.c +++ /dev/null @@ -1,39 +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 . - */ - -#include "tulog.h" - -void *taosInitTcpClient(char *ip, uint16_t port, char *label, int num, void *fp, void *shandle) { - tError("InitTcpClient not support in windows"); - return 0; -} - -void taosCloseTcpClientConnection(void *chandle) { - tError("CloseTcpClientConnection not support in windows"); -} - -void *taosOpenTcpClientConnection(void *shandle, void *thandle, char *ip, uint16_t port) { - tError("OpenTcpClientConnection not support in windows"); - return 0; -} - -int taosSendTcpClientData(unsigned int ip, uint16_t port, char *data, int len, void *chandle) { - tError("SendTcpClientData not support in windows"); - return 0; -} - -void taosCleanUpTcpClient(void *chandle) { - tError("SendTcpClientData not support in windows"); -} diff --git a/src/os/src/windows64/w64Atomic.c b/src/os/src/windows64/w64Atomic.c new file mode 100644 index 0000000000..0425f4ed3f --- /dev/null +++ b/src/os/src/windows64/w64Atomic.c @@ -0,0 +1,172 @@ +/* + * 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" + +// add +char interlocked_add_fetch_8(char volatile* ptr, char val) { + #ifdef _TD_GO_DLL_ + return __sync_fetch_and_add(ptr, val) + val; + #else + return _InterlockedExchangeAdd8(ptr, val) + val; + #endif +} + +short interlocked_add_fetch_16(short volatile* ptr, short val) { + #ifdef _TD_GO_DLL_ + return __sync_fetch_and_add(ptr, val) + val; + #else + return _InterlockedExchangeAdd16(ptr, val) + val; + #endif +} + +long interlocked_add_fetch_32(long volatile* ptr, long val) { + return _InterlockedExchangeAdd(ptr, val) + val; +} + +__int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) { + return _InterlockedExchangeAdd64(ptr, val) + val; +} + +// and +#ifndef _TD_GO_DLL_ +char interlocked_and_fetch_8(char volatile* ptr, char val) { + return _InterlockedAnd8(ptr, val) & val; +} + +short interlocked_and_fetch_16(short volatile* ptr, short val) { + return _InterlockedAnd16(ptr, val) & val; +} +#endif + +long interlocked_and_fetch_32(long volatile* ptr, long val) { + return _InterlockedAnd(ptr, val) & val; +} + +#ifndef _M_IX86 + +__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) { + return _InterlockedAnd64(ptr, val) & val; +} + +#else + +__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) { + __int64 old, res; + do { + old = *ptr; + res = old & val; + } while(_InterlockedCompareExchange64(ptr, res, old) != old); + return res; +} + +__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val) { + __int64 old; + do { + old = *ptr; + } while(_InterlockedCompareExchange64(ptr, old & val, old) != old); + return old; +} + +#endif + +// or +#ifndef _TD_GO_DLL_ +char interlocked_or_fetch_8(char volatile* ptr, char val) { + return _InterlockedOr8(ptr, val) | val; +} + +short interlocked_or_fetch_16(short volatile* ptr, short val) { + return _InterlockedOr16(ptr, val) | val; +} +#endif +long interlocked_or_fetch_32(long volatile* ptr, long val) { + return _InterlockedOr(ptr, val) | val; +} + +#ifndef _M_IX86 + +__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) { + return _InterlockedOr64(ptr, val) & val; +} + +#else + +__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) { + __int64 old, res; + do { + old = *ptr; + res = old | val; + } while(_InterlockedCompareExchange64(ptr, res, old) != old); + return res; +} + +__int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val) { + __int64 old; + do { + old = *ptr; + } while(_InterlockedCompareExchange64(ptr, old | val, old) != old); + return old; +} + +#endif + +// xor +#ifndef _TD_GO_DLL_ +char interlocked_xor_fetch_8(char volatile* ptr, char val) { + return _InterlockedXor8(ptr, val) ^ val; +} + +short interlocked_xor_fetch_16(short volatile* ptr, short val) { + return _InterlockedXor16(ptr, val) ^ val; +} +#endif +long interlocked_xor_fetch_32(long volatile* ptr, long val) { + return _InterlockedXor(ptr, val) ^ val; +} + +#ifndef _M_IX86 + +__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) { + return _InterlockedXor64(ptr, val) ^ val; +} + +#else + +__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) { + __int64 old, res; + do { + old = *ptr; + res = old ^ val; + } while(_InterlockedCompareExchange64(ptr, res, old) != old); + return res; +} + +__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val) { + __int64 old; + do { + old = *ptr; + } while(_InterlockedCompareExchange64(ptr, old ^ val, old) != old); + return old; +} + +#endif + diff --git a/src/os/src/windows64/w64Coredump.c b/src/os/src/windows64/w64Coredump.c new file mode 100644 index 0000000000..95490e7ad0 --- /dev/null +++ b/src/os/src/windows64/w64Coredump.c @@ -0,0 +1,23 @@ +/* + * 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 "tconfig.h" +#include "tglobal.h" +#include "tulog.h" +#include "tsystem.h" + +void taosSetCoreDump() {} \ No newline at end of file diff --git a/src/os/src/windows64/twinenv.c b/src/os/src/windows64/w64Env.c similarity index 100% rename from src/os/src/windows64/twinenv.c rename to src/os/src/windows64/w64Env.c diff --git a/src/os/src/windows64/w64File.c b/src/os/src/windows64/w64File.c index 140277f990..5cfcc8f79c 100644 --- a/src/os/src/windows64/w64File.c +++ b/src/os/src/windows64/w64File.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "os.h" -void getTmpfilePath(const char *fileNamePrefix, char *dstPath) { +void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { const char* tdengineTmpFileNamePrefix = "tdengine-"; char tmpPath[PATH_MAX]; diff --git a/src/os/src/windows64/w64FileOp.c b/src/os/src/windows64/w64FileOp.c new file mode 100644 index 0000000000..54f7938dde --- /dev/null +++ b/src/os/src/windows64/w64FileOp.c @@ -0,0 +1,59 @@ +/* + * 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" + +#define _SEND_FILE_STEP_ 1000 + +int taosTSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count) { + fseek(in_file, (int32_t)(*offset), 0); + int writeLen = 0; + uint8_t buffer[_SEND_FILE_STEP_] = { 0 }; + + for (int 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 (int)(writeLen + rlen); + } + else { + fwrite(buffer, 1, _SEND_FILE_STEP_, in_file); + writeLen += _SEND_FILE_STEP_; + } + } + + int remain = count - writeLen; + if (remain > 0) { + size_t rlen = fread(buffer, 1, remain, in_file); + if (rlen <= 0) { + return writeLen; + } + else { + fwrite(buffer, 1, remain, out_file); + writeLen += remain; + } + } + + return writeLen; +} diff --git a/src/os/src/windows64/twingetline.c b/src/os/src/windows64/w64Getline.c similarity index 100% rename from src/os/src/windows64/twingetline.c rename to src/os/src/windows64/w64Getline.c diff --git a/src/os/src/windows64/w64Godll.c b/src/os/src/windows64/w64Godll.c new file mode 100644 index 0000000000..b0267c4aac --- /dev/null +++ b/src/os/src/windows64/w64Godll.c @@ -0,0 +1,34 @@ +/* + * 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 \ No newline at end of file diff --git a/src/os/src/windows64/w64Lz4.c b/src/os/src/windows64/w64Lz4.c new file mode 100644 index 0000000000..96556c1f1c --- /dev/null +++ b/src/os/src/windows64/w64Lz4.c @@ -0,0 +1,46 @@ +/* + * 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" + +int32_t BUILDIN_CLZL(uint64_t val) { + unsigned long r = 0; + _BitScanReverse64(&r, val); + return (int)(r >> 3); +} + +int32_t BUILDIN_CLZ(uint32_t val) { + unsigned long r = 0; + _BitScanReverse(&r, val); + return (int)(r >> 3); +} + +int32_t BUILDIN_CTZL(uint64_t val) { + unsigned long r = 0; + _BitScanForward64(&r, val); + return (int)(r >> 3); +} + +int32_t BUILDIN_CTZ(uint32_t val) { + unsigned long r = 0; + _BitScanForward(&r, val); + return (int)(r >> 3); +} diff --git a/src/os/src/windows64/twinmsghdr.c b/src/os/src/windows64/w64Msghdr.c similarity index 50% rename from src/os/src/windows64/twinmsghdr.c rename to src/os/src/windows64/w64Msghdr.c index 9f35d3ec62..9d1924f311 100644 --- a/src/os/src/windows64/twinmsghdr.c +++ b/src/os/src/windows64/w64Msghdr.c @@ -16,42 +16,41 @@ #include void taosFreeMsgHdr(void *hdr) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - free(msgHdr->lpBuffers); + WSAMSG *msgHdr = (WSAMSG *)hdr; + free(msgHdr->lpBuffers); } int taosMsgHdrSize(void *hdr) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - return msgHdr->dwBufferCount; + WSAMSG *msgHdr = (WSAMSG *)hdr; + return msgHdr->dwBufferCount; } void taosSendMsgHdr(void *hdr, int fd) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - DWORD len; + WSAMSG *msgHdr = (WSAMSG *)hdr; + DWORD len; - WSASendMsg(fd, msgHdr, 0, &len, 0, 0); - msgHdr->dwBufferCount = 0; + WSASendMsg(fd, msgHdr, 0, &len, 0, 0); + msgHdr->dwBufferCount = 0; } void taosInitMsgHdr(void **hdr, void *dest, int maxPkts) { - WSAMSG *msgHdr = (WSAMSG *)malloc(sizeof(WSAMSG)); - memset(msgHdr, 0, sizeof(WSAMSG)); - *hdr = msgHdr; - - // see ws2def.h - // the size of LPSOCKADDR and sockaddr_in * is same, so it's safe - msgHdr->name = (LPSOCKADDR)dest; - msgHdr->namelen = sizeof(struct sockaddr_in); - int size = sizeof(WSABUF) * maxPkts; - msgHdr->lpBuffers = (LPWSABUF)malloc(size); - memset(msgHdr->lpBuffers, 0, size); - msgHdr->dwBufferCount = 0; + WSAMSG *msgHdr = (WSAMSG *)malloc(sizeof(WSAMSG)); + memset(msgHdr, 0, sizeof(WSAMSG)); + *hdr = msgHdr; + + // see ws2def.h + // the size of LPSOCKADDR and sockaddr_in * is same, so it's safe + msgHdr->name = (LPSOCKADDR)dest; + msgHdr->namelen = sizeof(struct sockaddr_in); + int size = sizeof(WSABUF) * maxPkts; + msgHdr->lpBuffers = (LPWSABUF)malloc(size); + memset(msgHdr->lpBuffers, 0, size); + msgHdr->dwBufferCount = 0; } void taosSetMsgHdrData(void *hdr, char *data, int dataLen) { - WSAMSG *msgHdr = (WSAMSG *)hdr; - msgHdr->lpBuffers[msgHdr->dwBufferCount].buf = data; - msgHdr->lpBuffers[msgHdr->dwBufferCount].len = dataLen; - msgHdr->dwBufferCount++; + WSAMSG *msgHdr = (WSAMSG *)hdr; + msgHdr->lpBuffers[msgHdr->dwBufferCount].buf = data; + msgHdr->lpBuffers[msgHdr->dwBufferCount].len = dataLen; + msgHdr->dwBufferCount++; } - diff --git a/src/os/src/windows64/w64PThread.c b/src/os/src/windows64/w64PThread.c new file mode 100644 index 0000000000..7ed6228228 --- /dev/null +++ b/src/os/src/windows64/w64PThread.c @@ -0,0 +1,34 @@ +/* + * 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" + +bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; } + +void taosResetPthread(pthread_t *thread) { thread->p = 0; } + +int64_t taosGetPthreadId() { +#ifdef PTW32_VERSION + return pthread_getw32threadid_np(pthread_self()); +#else + return (int64_t)pthread_self(); +#endif +} diff --git a/src/os/src/windows64/w64Socket.c b/src/os/src/windows64/w64Socket.c new file mode 100644 index 0000000000..cdf46825e8 --- /dev/null +++ b/src/os/src/windows64/w64Socket.c @@ -0,0 +1,64 @@ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include + +void taosWinSocketInit() { + static char flag = 0; + if (flag == 0) { + WORD wVersionRequested; + WSADATA wsaData; + wVersionRequested = MAKEWORD(1, 1); + if (WSAStartup(wVersionRequested, &wsaData) == 0) { + flag = 1; + } + } +} + +int taosSetNonblocking(SOCKET sock, int on) { + u_long mode; + if (on) { + mode = 1; + ioctlsocket(sock, FIONBIO, &mode); + } else { + mode = 0; + ioctlsocket(sock, FIONBIO, &mode); + } + return 0; +} + +void taosBlockSIGPIPE() {} + +int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) { + if (level == SOL_SOCKET && optname == TCP_KEEPCNT) { + return 0; + } + + if (level == SOL_TCP && optname == TCP_KEEPIDLE) { + return 0; + } + + if (level == SOL_TCP && optname == TCP_KEEPINTVL) { + return 0; + } + + return setsockopt(socketfd, level, optname, optval, optlen); +} \ No newline at end of file diff --git a/src/os/src/windows64/w64String.c b/src/os/src/windows64/w64String.c new file mode 100644 index 0000000000..0b392466fa --- /dev/null +++ b/src/os/src/windows64/w64String.c @@ -0,0 +1,92 @@ +/* + * 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" + + +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no moretokens). + * + * If *stringp is NULL, strsep returns NULL. + */ +char *strsep(char **stringp, const char *delim) { + char *s; + const char *spanp; + int c, sc; + char *tok; + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +char *getpass(const char *prefix) { + static char passwd[TSDB_KEY_LEN] = {0}; + + printf("%s", prefix); + scanf("%s", passwd); + + char n = getchar(); + return passwd; +} + +char *strndup(const char *s, size_t n) { + int len = strlen(s); + if (len >= n) { + len = n; + } + + char *r = calloc(len + 1, 1); + memcpy(r, s, len); + r[len] = 0; + return r; +} + +#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 \ No newline at end of file diff --git a/src/os/src/windows64/twinstrptime.c b/src/os/src/windows64/w64Strptime.c similarity index 100% rename from src/os/src/windows64/twinstrptime.c rename to src/os/src/windows64/w64Strptime.c diff --git a/src/os/src/windows64/w64Sysinfo.c b/src/os/src/windows64/w64Sysinfo.c new file mode 100644 index 0000000000..950230e567 --- /dev/null +++ b/src/os/src/windows64/w64Sysinfo.c @@ -0,0 +1,116 @@ +/* + * 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 "tconfig.h" +#include "ttimer.h" +#include "tulog.h" +#include "tutil.h" + +static void taosGetSystemTimezone() { + // get and set default timezone + SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); + if (cfg_timezone && cfg_timezone->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { + char *tz = getenv("TZ"); + if (tz == NULL || strlen(tz) == 0) { + strcpy(tsTimezone, "not configured"); + } else { + strcpy(tsTimezone, tz); + } + cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uInfo("timezone not configured, use default"); + } +} + +static void taosGetSystemLocale() { + // get and set default locale + SGlobalCfg *cfg_locale = taosGetConfigOption("locale"); + if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { + char *locale = setlocale(LC_CTYPE, "chs"); + if (locale != NULL) { + tstrncpy(tsLocale, locale, sizeof(tsLocale)); + cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uInfo("locale not configured, set to default:%s", tsLocale); + } + } + + SGlobalCfg *cfg_charset = taosGetConfigOption("charset"); + if (cfg_charset && cfg_charset->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { + strcpy(tsCharset, "cp936"); + cfg_charset->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uInfo("charset not configured, set to default:%s", tsCharset); + } +} + +void taosPrintOsInfo() {} + +void taosKillSystem() { + uError("function taosKillSystem, exit!"); + exit(0); +} + +void taosGetSystemInfo() { + taosGetSystemTimezone(); + taosGetSystemLocale(); +} + +bool taosGetDisk() { return true; } + +bool taosGetProcIO(float *readKB, float *writeKB) { + *readKB = 0; + *writeKB = 0; + return true; +} + +bool taosGetBandSpeed(float *bandSpeedKb) { + *bandSpeedKb = 0; + return true; +} + +bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { + *sysCpuUsage = 0; + *procCpuUsage = 0; + return true; +} + +bool taosGetProcMemory(float *memoryUsedMB) { + *memoryUsedMB = 0; + return true; +} + +bool taosGetSysMemory(float *memoryUsedMB) { + *memoryUsedMB = 0; + return true; +} + +int taosSystem(const char *cmd) { + uError("taosSystem not support"); + return -1; +} + +int flock(int fd, int option) { + return 0; +} + +int fsync(int filedes) { + return 0; +} + +int sigaction(int sig, struct sigaction *d, void *p) { + return 0; +} \ No newline at end of file diff --git a/src/os/src/windows64/twintime.c b/src/os/src/windows64/w64Time.c similarity index 100% rename from src/os/src/windows64/twintime.c rename to src/os/src/windows64/w64Time.c diff --git a/src/os/src/windows64/twintimer.c b/src/os/src/windows64/w64Timer.c similarity index 93% rename from src/os/src/windows64/twintimer.c rename to src/os/src/windows64/w64Timer.c index 2bb8478f09..32e04746f1 100644 --- a/src/os/src/windows64/twintimer.c +++ b/src/os/src/windows64/w64Timer.c @@ -22,8 +22,7 @@ typedef void (*win_timer_f)(int signo); -void WINAPI taosWinOnTimer(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dwl, DWORD_PTR dw2) -{ +void WINAPI taosWinOnTimer(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dwl, DWORD_PTR dw2) { win_timer_f callback = *((win_timer_f *)&dwUser); if (callback != NULL) { callback(0); @@ -48,7 +47,3 @@ void taosUninitTimer() { void taosMsleep(int mseconds) { Sleep(mseconds); } - -void sleep(int mseconds) { - taosMsleep(mseconds); -} \ No newline at end of file diff --git a/src/os/src/windows64/w64Util.c b/src/os/src/windows64/w64Util.c new file mode 100644 index 0000000000..1a9f71b3c3 --- /dev/null +++ b/src/os/src/windows64/w64Util.c @@ -0,0 +1,117 @@ +/* + * 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" + + +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no moretokens). + * + * If *stringp is NULL, strsep returns NULL. + */ +char *strsep(char **stringp, const char *delim) { + char *s; + const char *spanp; + int c, sc; + char *tok; + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +char *getpass(const char *prefix) { + static char passwd[TSDB_KEY_LEN] = {0}; + + printf("%s", prefix); + scanf("%s", passwd); + + char n = getchar(); + return passwd; +} + +int flock(int fd, int option) { + return 0; +} + +int fsync(int filedes) { + return 0; +} + +int sigaction(int sig, struct sigaction *d, void *p) { + return 0; +} + +int wordexp(const char *words, wordexp_t *pwordexp, int flags) { + pwordexp->we_offs = 0; + pwordexp->we_wordc = 1; + pwordexp->we_wordv = (char **)(pwordexp->wordPos); + pwordexp->we_wordv[0] = (char *)words; + return 0; +} + +void wordfree(wordexp_t *pwordexp) {} + + +char *strndup(const char *s, size_t n) { + int len = strlen(s); + if (len >= n) { + len = n; + } + + char *r = calloc(len + 1, 1); + memcpy(r, s, len); + r[len] = 0; + return r; +} + +void taosSetCoreDump() {} + +#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 \ No newline at end of file diff --git a/src/os/src/windows64/twintcpserver.c b/src/os/src/windows64/w64Wordexp.c similarity index 55% rename from src/os/src/windows64/twintcpserver.c rename to src/os/src/windows64/w64Wordexp.c index 10c0348bef..bb9acde25a 100644 --- a/src/os/src/windows64/twintcpserver.c +++ b/src/os/src/windows64/w64Wordexp.c @@ -13,22 +13,21 @@ * 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" -void taosCloseTcpServerConnection(void *chandle) { - tError("CloseTcpServerConnection not support in windows"); -} - -void taosCleanUpTcpServer(void *handle) { - tError("CleanUpTcpServer not support in windows"); -} - -void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) { - tError("InitTcpServer not support in windows"); +int wordexp(const char *words, wordexp_t *pwordexp, int flags) { + pwordexp->we_offs = 0; + pwordexp->we_wordc = 1; + pwordexp->we_wordv = (char **)(pwordexp->wordPos); + pwordexp->we_wordv[0] = (char *)words; return 0; } -int taosSendTcpServerData(unsigned int ip, uint16_t port, char *data, int len, void *chandle) { - tError("SendTcpServerData not support in windows"); - return 0; -} +void wordfree(wordexp_t *pwordexp) {} + diff --git a/src/query/src/qExtbuffer.c b/src/query/src/qExtbuffer.c index fb57f71199..6f1c51a19e 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -38,7 +38,7 @@ tExtMemBuffer* createExtMemBuffer(int32_t inMemSize, int32_t elemSize, int32_t p pMemBuffer->numOfElemsPerPage = (pMemBuffer->pageSize - sizeof(tFilePage)) / pMemBuffer->nElemSize; char name[MAX_TMPFILE_PATH_LENGTH] = {0}; - getTmpfilePath("extbuf", name); + taosGetTmpfilePath("extbuf", name); pMemBuffer->path = strdup(name); uDebug("create tmp file:%s", pMemBuffer->path); diff --git a/src/query/src/qResultbuf.c b/src/query/src/qResultbuf.c index 93ccad8e27..363b590d80 100644 --- a/src/query/src/qResultbuf.c +++ b/src/query/src/qResultbuf.c @@ -39,7 +39,7 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t ro pResBuf->all = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false); char path[PATH_MAX] = {0}; - getTmpfilePath("qbuf", path); + taosGetTmpfilePath("qbuf", path); pResBuf->path = strdup(path); pResBuf->emptyDummyIdList = taosArrayInit(1, sizeof(int32_t)); diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index 037e85c88c..8ab45cc1a9 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -21,7 +21,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { return NULL; } - getTmpfilePath("join", pTSBuf->path); + taosGetTmpfilePath("join", pTSBuf->path); pTSBuf->f = fopen(pTSBuf->path, "w+"); if (pTSBuf->f == NULL) { free(pTSBuf); diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index 59fd326ef4..60c73b4fad 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -766,7 +766,7 @@ TEST(testCase, getTempFilePath_test) { char path[4096] = {0}; memset(path, 1, 4096); - getTmpfilePath("new_tmp", path); + taosGetTmpfilePath("new_tmp", path); printf("%s\n", path); } -- GitLab