未验证 提交 1828eec8 编写于 作者: F fangpanpan 提交者: GitHub

Merge pull request #1064 from taosdata/feature/cgodll

Feature/cgodll
...@@ -26,6 +26,13 @@ SET(CMAKE_VERBOSE_MAKEFILE ON) ...@@ -26,6 +26,13 @@ SET(CMAKE_VERBOSE_MAKEFILE ON)
# open the file named TDengine.sln # open the file named TDengine.sln
# #
SET(TD_GODLL FALSE)
IF (${DLLTYPE} MATCHES "go")
ADD_DEFINITIONS(-D_TD_GO_DLL_)
MESSAGE(STATUS "input dll type: " ${DLLTYPE})
SET(TD_GODLL TRUE)
ENDIF ()
IF (NOT DEFINED TD_CLUSTER) IF (NOT DEFINED TD_CLUSTER)
MESSAGE(STATUS "Build the Lite Version") MESSAGE(STATUS "Build the Lite Version")
SET(TD_CLUSTER FALSE) SET(TD_CLUSTER FALSE)
...@@ -183,9 +190,11 @@ IF (NOT DEFINED TD_CLUSTER) ...@@ -183,9 +190,11 @@ IF (NOT DEFINED TD_CLUSTER)
ENDIF () ENDIF ()
ELSEIF (TD_WINDOWS_64) ELSEIF (TD_WINDOWS_64)
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE) SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
IF (NOT TD_GODLL)
SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-") SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
SET(DEBUG_FLAGS "/Zi /W3 /GL") SET(DEBUG_FLAGS "/Zi /W3 /GL")
SET(RELEASE_FLAGS "/W0 /GL") SET(RELEASE_FLAGS "/W0 /GL")
ENDIF ()
ADD_DEFINITIONS(-DWINDOWS) ADD_DEFINITIONS(-DWINDOWS)
ADD_DEFINITIONS(-D__CLEANUP_C) ADD_DEFINITIONS(-D__CLEANUP_C)
ADD_DEFINITIONS(-DPTW32_STATIC_LIB) ADD_DEFINITIONS(-DPTW32_STATIC_LIB)
......
...@@ -175,7 +175,10 @@ static const struct alias sysdep_aliases[] = { ...@@ -175,7 +175,10 @@ static const struct alias sysdep_aliases[] = {
#ifdef __GNUC__ #ifdef __GNUC__
__inline __inline
#endif #endif
const struct alias * // gcc -o0 bug fix
// see http://git.savannah.gnu.org/gitweb/?p=libiconv.git;a=blobdiff;f=lib/iconv.c;h=31853a7f1c47871221189dbf597473a16d8a8da7;hp=5a1a32597fa3efc5f69624d37a2eb96f308cd241;hb=b29089d8b43abc8fba073da7e6dccaeba56b2b70;hpb=0a04404c90d6a725b8b6bbcd65e10c5fcf5993e9
static const struct alias *
aliases2_lookup (register const char *str) aliases2_lookup (register const char *str)
{ {
const struct alias * ptr; const struct alias * ptr;
......
...@@ -51,7 +51,9 @@ ELSEIF (TD_WINDOWS_64) ...@@ -51,7 +51,9 @@ ELSEIF (TD_WINDOWS_64)
# generate dynamic library (*.dll) # generate dynamic library (*.dll)
ADD_LIBRARY(taos SHARED ${SRC}) ADD_LIBRARY(taos SHARED ${SRC})
IF (NOT TD_GODLL)
SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_COMMUNITY_DIR}/src/client/src/taos.def) SET_TARGET_PROPERTIES(taos PROPERTIES LINK_FLAGS /DEF:${TD_COMMUNITY_DIR}/src/client/src/taos.def)
ENDIF ()
TARGET_LINK_LIBRARIES(taos trpc) TARGET_LINK_LIBRARIES(taos trpc)
ELSEIF (TD_DARWIN_64) ELSEIF (TD_DARWIN_64)
......
...@@ -57,10 +57,16 @@ typedef struct taosField { ...@@ -57,10 +57,16 @@ typedef struct taosField {
char type; char type;
} TAOS_FIELD; } TAOS_FIELD;
void taos_init(); #ifdef _TD_GO_DLL_
int taos_options(TSDB_OPTION option, const void *arg, ...); #define DLL_EXPORT __declspec(dllexport)
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); #else
void taos_close(TAOS *taos); #define DLL_EXPORT
#endif
DLL_EXPORT void taos_init();
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
DLL_EXPORT void taos_close(TAOS *taos);
typedef struct TAOS_BIND { typedef struct TAOS_BIND {
int buffer_type; int buffer_type;
...@@ -80,18 +86,18 @@ int taos_stmt_execute(TAOS_STMT *stmt); ...@@ -80,18 +86,18 @@ int taos_stmt_execute(TAOS_STMT *stmt);
TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt); TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt);
int taos_stmt_close(TAOS_STMT *stmt); int taos_stmt_close(TAOS_STMT *stmt);
int taos_query(TAOS *taos, const char *sql); DLL_EXPORT int taos_query(TAOS *taos, const char *sql);
TAOS_RES *taos_use_result(TAOS *taos); DLL_EXPORT TAOS_RES *taos_use_result(TAOS *taos);
TAOS_ROW taos_fetch_row(TAOS_RES *res); DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
int taos_result_precision(TAOS_RES *res); // get the time precision of result DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
void taos_free_result(TAOS_RES *res); DLL_EXPORT void taos_free_result(TAOS_RES *res);
int taos_field_count(TAOS *taos); DLL_EXPORT int taos_field_count(TAOS *taos);
int taos_num_fields(TAOS_RES *res); DLL_EXPORT int taos_num_fields(TAOS_RES *res);
int taos_affected_rows(TAOS *taos); DLL_EXPORT int taos_affected_rows(TAOS *taos);
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res); DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
int taos_select_db(TAOS *taos, const char *db); DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields); DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
void taos_stop_query(TAOS_RES *res); DLL_EXPORT void taos_stop_query(TAOS_RES *res);
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
int taos_validate_sql(TAOS *taos, const char *sql); int taos_validate_sql(TAOS *taos, const char *sql);
...@@ -100,27 +106,27 @@ int taos_validate_sql(TAOS *taos, const char *sql); ...@@ -100,27 +106,27 @@ int taos_validate_sql(TAOS *taos, const char *sql);
// TAOS_RES *taos_list_dbs(TAOS *mysql, const char *wild); // TAOS_RES *taos_list_dbs(TAOS *mysql, const char *wild);
// TODO: the return value should be `const` // TODO: the return value should be `const`
char *taos_get_server_info(TAOS *taos); DLL_EXPORT char *taos_get_server_info(TAOS *taos);
char *taos_get_client_info(); DLL_EXPORT char *taos_get_client_info();
char *taos_errstr(TAOS *taos); DLL_EXPORT char *taos_errstr(TAOS *taos);
int taos_errno(TAOS *taos); DLL_EXPORT int taos_errno(TAOS *taos);
void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param); DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param);
void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param); DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);
void taos_fetch_row_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), void *param); DLL_EXPORT void taos_fetch_row_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), void *param);
TAOS_SUB *taos_subscribe(const char *host, const char *user, const char *pass, const char *db, const char *table, int64_t time, int mseconds); DLL_EXPORT TAOS_SUB *taos_subscribe(const char *host, const char *user, const char *pass, const char *db, const char *table, int64_t time, int mseconds);
TAOS_ROW taos_consume(TAOS_SUB *tsub); DLL_EXPORT TAOS_ROW taos_consume(TAOS_SUB *tsub);
void taos_unsubscribe(TAOS_SUB *tsub); DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub);
int taos_subfields_count(TAOS_SUB *tsub); DLL_EXPORT int taos_subfields_count(TAOS_SUB *tsub);
TAOS_FIELD *taos_fetch_subfields(TAOS_SUB *tsub); DLL_EXPORT TAOS_FIELD *taos_fetch_subfields(TAOS_SUB *tsub);
TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
int64_t stime, void *param, void (*callback)(void *)); int64_t stime, void *param, void (*callback)(void *));
void taos_close_stream(TAOS_STREAM *tstr); DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
int taos_load_table_info(TAOS *taos, const char* tableNameList); DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "winsock2.h" #include "winsock2.h"
#include <WS2tcpip.h> #include <WS2tcpip.h>
#include <winbase.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -75,7 +77,13 @@ extern "C" { ...@@ -75,7 +77,13 @@ extern "C" {
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#define wcsncasecmp _wcsnicmp #define wcsncasecmp _wcsnicmp
#define strtok_r strtok_s #define strtok_r strtok_s
#define str2int64 _atoi64 #ifdef _TD_GO_DLL_
int64_t str2int64(char *str);
uint64_t htonll(uint64_t val);
#else
#define str2int64 _atoi64
#endif
#define snprintf _snprintf #define snprintf _snprintf
#define in_addr_t unsigned long #define in_addr_t unsigned long
#define socklen_t int #define socklen_t int
...@@ -136,7 +144,12 @@ extern "C" { ...@@ -136,7 +144,12 @@ extern "C" {
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(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 atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval)) #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_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_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_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
...@@ -156,9 +169,14 @@ __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val); ...@@ -156,9 +169,14 @@ __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
#else #else
#define atomic_add_fetch_ptr atomic_add_fetch_32 #define atomic_add_fetch_ptr atomic_add_fetch_32
#endif #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_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_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
#define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val)) #define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64 #ifdef _WIN64
...@@ -186,14 +204,17 @@ __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val); ...@@ -186,14 +204,17 @@ __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
#else #else
#define atomic_fetch_sub_ptr atomic_fetch_sub_32 #define atomic_fetch_sub_ptr atomic_fetch_sub_32
#endif #endif
#ifndef _TD_GO_DLL_
char interlocked_and_fetch_8(char volatile* ptr, char val); char interlocked_and_fetch_8(char volatile* ptr, char val);
short interlocked_and_fetch_16(short volatile* ptr, short val); short interlocked_and_fetch_16(short volatile* ptr, short val);
#endif
long interlocked_and_fetch_32(long volatile* ptr, long val); long interlocked_and_fetch_32(long volatile* ptr, long val);
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val)) #ifndef _TD_GO_DLL_
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(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))
#endif
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(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_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64 #ifdef _WIN64
...@@ -201,9 +222,10 @@ __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); ...@@ -201,9 +222,10 @@ __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
#else #else
#define atomic_and_fetch_ptr atomic_and_fetch_32 #define atomic_and_fetch_ptr atomic_and_fetch_32
#endif #endif
#ifndef _TD_GO_DLL_
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(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_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
#endif
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val)) #define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
#ifdef _M_IX86 #ifdef _M_IX86
...@@ -218,14 +240,17 @@ __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val); ...@@ -218,14 +240,17 @@ __int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
#else #else
#define atomic_fetch_and_ptr atomic_fetch_and_32 #define atomic_fetch_and_ptr atomic_fetch_and_32
#endif #endif
#ifndef _TD_GO_DLL_
char interlocked_or_fetch_8(char volatile* ptr, char val); char interlocked_or_fetch_8(char volatile* ptr, char val);
short interlocked_or_fetch_16(short volatile* ptr, short val); short interlocked_or_fetch_16(short volatile* ptr, short val);
#endif
long interlocked_or_fetch_32(long volatile* ptr, long val); long interlocked_or_fetch_32(long volatile* ptr, long val);
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val)) #ifndef _TD_GO_DLL_
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(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))
#endif
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(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_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64 #ifdef _WIN64
...@@ -233,9 +258,10 @@ __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); ...@@ -233,9 +258,10 @@ __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
#else #else
#define atomic_or_fetch_ptr atomic_or_fetch_32 #define atomic_or_fetch_ptr atomic_or_fetch_32
#endif #endif
#ifndef _TD_GO_DLL_
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(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_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
#endif
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val)) #define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
#ifdef _M_IX86 #ifdef _M_IX86
...@@ -251,13 +277,17 @@ __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val); ...@@ -251,13 +277,17 @@ __int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_fetch_or_ptr atomic_fetch_or_32 #define atomic_fetch_or_ptr atomic_fetch_or_32
#endif #endif
char interlocked_xor_fetch_8(char volatile* ptr, char val); #ifndef _TD_GO_DLL_
short interlocked_xor_fetch_16(short volatile* ptr, short val); 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); long interlocked_xor_fetch_32(long volatile* ptr, long val);
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val)) #ifndef _TD_GO_DLL_
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(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))
#endif
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(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_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64 #ifdef _WIN64
...@@ -266,8 +296,10 @@ __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); ...@@ -266,8 +296,10 @@ __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_xor_fetch_ptr atomic_xor_fetch_32 #define atomic_xor_fetch_ptr atomic_xor_fetch_32
#endif #endif
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val)) #ifndef _TD_GO_DLL_
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(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))
#endif
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val)) #define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
#ifdef _M_IX86 #ifdef _M_IX86
...@@ -293,7 +325,11 @@ __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); ...@@ -293,7 +325,11 @@ __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
#define MAX(a,b) (((a)>(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b))
#define MILLISECOND_PER_SECOND (1000i64) #ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL)
#else
#define MILLISECOND_PER_SECOND (1000i64)
#endif
#define tsem_t sem_t #define tsem_t sem_t
#define tsem_init sem_init #define tsem_init sem_init
......
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
#include "tsdb.h" #include "tsdb.h"
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include <intrin.h>
#include <winbase.h>
#include <Winsock2.h>
char configDir[TSDB_FILENAME_LEN] = "C:/TDengine/cfg"; char configDir[TSDB_FILENAME_LEN] = "C:/TDengine/cfg";
char tsDirectory[TSDB_FILENAME_LEN] = "C:/TDengine/data"; char tsDirectory[TSDB_FILENAME_LEN] = "C:/TDengine/data";
char logDir[TSDB_FILENAME_LEN] = "C:/TDengine/log"; char logDir[TSDB_FILENAME_LEN] = "C:/TDengine/log";
...@@ -68,11 +72,19 @@ int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optle ...@@ -68,11 +72,19 @@ int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optle
// add // add
char interlocked_add_fetch_8(char volatile* ptr, char val) { 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; return _InterlockedExchangeAdd8(ptr, val) + val;
#endif
} }
short interlocked_add_fetch_16(short volatile* ptr, short val) { 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; return _InterlockedExchangeAdd16(ptr, val) + val;
#endif
} }
long interlocked_add_fetch_32(long volatile* ptr, long val) { long interlocked_add_fetch_32(long volatile* ptr, long val) {
...@@ -84,6 +96,7 @@ __int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) { ...@@ -84,6 +96,7 @@ __int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) {
} }
// and // and
#ifndef _TD_GO_DLL_
char interlocked_and_fetch_8(char volatile* ptr, char val) { char interlocked_and_fetch_8(char volatile* ptr, char val) {
return _InterlockedAnd8(ptr, val) & val; return _InterlockedAnd8(ptr, val) & val;
} }
...@@ -91,6 +104,7 @@ char interlocked_and_fetch_8(char volatile* ptr, char val) { ...@@ -91,6 +104,7 @@ char interlocked_and_fetch_8(char volatile* ptr, char val) {
short interlocked_and_fetch_16(short volatile* ptr, short val) { short interlocked_and_fetch_16(short volatile* ptr, short val) {
return _InterlockedAnd16(ptr, val) & val; return _InterlockedAnd16(ptr, val) & val;
} }
#endif
long interlocked_and_fetch_32(long volatile* ptr, long val) { long interlocked_and_fetch_32(long volatile* ptr, long val) {
return _InterlockedAnd(ptr, val) & val; return _InterlockedAnd(ptr, val) & val;
...@@ -124,6 +138,7 @@ __int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val) { ...@@ -124,6 +138,7 @@ __int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val) {
#endif #endif
// or // or
#ifndef _TD_GO_DLL_
char interlocked_or_fetch_8(char volatile* ptr, char val) { char interlocked_or_fetch_8(char volatile* ptr, char val) {
return _InterlockedOr8(ptr, val) | val; return _InterlockedOr8(ptr, val) | val;
} }
...@@ -131,7 +146,7 @@ char interlocked_or_fetch_8(char volatile* ptr, char val) { ...@@ -131,7 +146,7 @@ char interlocked_or_fetch_8(char volatile* ptr, char val) {
short interlocked_or_fetch_16(short volatile* ptr, short val) { short interlocked_or_fetch_16(short volatile* ptr, short val) {
return _InterlockedOr16(ptr, val) | val; return _InterlockedOr16(ptr, val) | val;
} }
#endif
long interlocked_or_fetch_32(long volatile* ptr, long val) { long interlocked_or_fetch_32(long volatile* ptr, long val) {
return _InterlockedOr(ptr, val) | val; return _InterlockedOr(ptr, val) | val;
} }
...@@ -164,6 +179,7 @@ __int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val) { ...@@ -164,6 +179,7 @@ __int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val) {
#endif #endif
// xor // xor
#ifndef _TD_GO_DLL_
char interlocked_xor_fetch_8(char volatile* ptr, char val) { char interlocked_xor_fetch_8(char volatile* ptr, char val) {
return _InterlockedXor8(ptr, val) ^ val; return _InterlockedXor8(ptr, val) ^ val;
} }
...@@ -171,7 +187,7 @@ char interlocked_xor_fetch_8(char volatile* ptr, char val) { ...@@ -171,7 +187,7 @@ char interlocked_xor_fetch_8(char volatile* ptr, char val) {
short interlocked_xor_fetch_16(short volatile* ptr, short val) { short interlocked_xor_fetch_16(short volatile* ptr, short val) {
return _InterlockedXor16(ptr, val) ^ val; return _InterlockedXor16(ptr, val) ^ val;
} }
#endif
long interlocked_xor_fetch_32(long volatile* ptr, long val) { long interlocked_xor_fetch_32(long volatile* ptr, long val) {
return _InterlockedXor(ptr, val) ^ val; return _InterlockedXor(ptr, val) ^ val;
} }
...@@ -397,3 +413,15 @@ char *strndup(const char *s, size_t n) { ...@@ -397,3 +413,15 @@ char *strndup(const char *s, size_t n) {
} }
void taosSetCoreDump() {} void taosSetCoreDump() {}
#ifdef _TD_GO_DLL_
int64_t str2int64(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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册