/* * 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_PLATFORM_WINDOWS_H #define TDENGINE_PLATFORM_WINDOWS_H #include #include #include #include #include #include #include #include "winsock2.h" #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif // for function open in stat.h #define S_IRWXU _S_IREAD #define S_IRWXG _S_IWRITE #define S_IRWXO _S_IWRITE // for access function in io.h #define F_OK 00 //Existence only #define W_OK 02 //Write - only #define R_OK 04 //Read - only #define X_OK 06 //Read and write // for send function in tsocket.c #define MSG_NOSIGNAL 0 #define SO_NO_CHECK 0x1234 #define SOL_TCP 0x1234 #define TCP_KEEPCNT 0x1234 #define TCP_KEEPIDLE 0x1234 #define TCP_KEEPINTVL 0x1234 #define LOCK_EX 1 #define LOCK_NB 2 #define LOCK_UN 3 #define bzero(ptr, size) memset((ptr), 0, (size)) #define mkdir(pathname, mode) _mkdir(pathname) #define strcasecmp _stricmp #define strncasecmp _strnicmp #define wcsncasecmp _wcsnicmp #define strtok_r strtok_s #define str2int64 _atoi64 #define snprintf _snprintf #define in_addr_t unsigned long #define socklen_t int #define htobe64 htonll #define twrite write #ifndef PATH_MAX #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) #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)) #define __sync_val_compare_and_swap_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval)) #define __sync_val_compare_and_swap_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval)) #define __sync_val_compare_and_swap_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval)) #define __sync_val_compare_and_swap_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval)) #define __sync_val_compare_and_swap_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval)) char interlocked_add_8(char volatile *ptr, char val); short interlocked_add_16(short volatile *ptr, short val); long interlocked_add_32(long volatile *ptr, long val); __int64 interlocked_add_64(__int64 volatile *ptr, __int64 val); #define __sync_add_and_fetch_8(ptr, val) interlocked_add_8((char volatile*)(ptr), (char)(val)) #define __sync_add_and_fetch_16(ptr, val) interlocked_add_16((short volatile*)(ptr), (short)(val)) #define __sync_add_and_fetch_32(ptr, val) interlocked_add_32((long volatile*)(ptr), (long)(val)) #define __sync_add_and_fetch_64(ptr, val) interlocked_add_64((__int64 volatile*)(ptr), (__int64)(val)) #ifdef _WIN64 #define __sync_add_and_fetch_ptr __sync_add_and_fetch_64 #else #define __sync_add_and_fetch_ptr __sync_add_and_fetch_32 #endif #define __sync_sub_and_fetch_8(ptr, val) __sync_add_and_fetch_8((ptr), -(val)) #define __sync_sub_and_fetch_16(ptr, val) __sync_add_and_fetch_16((ptr), -(val)) #define __sync_sub_and_fetch_32(ptr, val) __sync_add_and_fetch_32((ptr), -(val)) #define __sync_sub_and_fetch_64(ptr, val) __sync_add_and_fetch_64((ptr), -(val)) #define __sync_sub_and_fetch_ptr(ptr, val) __sync_add_and_fetch_ptr((ptr), -(val)) int32_t __sync_val_load_32(int32_t *ptr); void __sync_val_restore_32(int32_t *ptr, int32_t newval); #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 MILLISECOND_PER_SECOND (1000i64) #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 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); char *taosCharsetReplace(char *charsetstr); void tsPrintOsInfo(); 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); }; typedef struct { int we_wordc; char **we_wordv; int we_offs; char wordPos[20]; } wordexp_t; 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); #ifdef __cplusplus } #endif #endif