From 02798e10d8ff9e6e749a519e531ef6f8bd76e2b8 Mon Sep 17 00:00:00 2001 From: slguan Date: Sat, 12 Oct 2019 23:16:58 +0800 Subject: [PATCH] Fix compile errors on different platforms --- src/client/src/TSDBJNIConnector.c | 4 ++-- src/os/darwin/inc/os.h | 2 ++ src/os/darwin/src/tdarwin.c | 8 ++++++++ src/os/linux/inc/os.h | 2 ++ src/os/linux/src/tlinux.c | 10 +++++++++- src/os/windows/inc/os.h | 4 ++++ src/os/windows/src/twindows.c | 14 +++++++++++++- 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index e4a271d845..70bc4df4ca 100755 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -68,7 +68,7 @@ void jniGetGlobalMethod(JNIEnv *env) { case 1: do { taosMsleep(0); - } while (__atomic_load_n(&__init, __ATOMIC_ACQUIRE) == 1); + } while (__sync_val_load_32(&__init) == 1); case 2: return; } @@ -108,7 +108,7 @@ void jniGetGlobalMethod(JNIEnv *env) { g_rowdataSetByteArrayFp = (*env)->GetMethodID(env, g_rowdataClass, "setByteArray", "(I[B)V"); (*env)->DeleteLocalRef(env, rowdataClass); - __atomic_store_n(&__init, 2, __ATOMIC_RELEASE); + __sync_val_restore_32(&__init, 2); jniTrace("native method register finished"); } diff --git a/src/os/darwin/inc/os.h b/src/os/darwin/inc/os.h index 485d3ab788..217981d90c 100644 --- a/src/os/darwin/inc/os.h +++ b/src/os/darwin/inc/os.h @@ -59,6 +59,8 @@ #define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap #define __sync_add_and_fetch_64 __sync_add_and_fetch #define __sync_add_and_fetch_32 __sync_add_and_fetch +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 { \ diff --git a/src/os/darwin/src/tdarwin.c b/src/os/darwin/src/tdarwin.c index 266370633d..2f97c7c376 100644 --- a/src/os/darwin/src/tdarwin.c +++ b/src/os/darwin/src/tdarwin.c @@ -415,4 +415,12 @@ int tsem_post(dispatch_semaphore_t *sem) { int tsem_destroy(dispatch_semaphore_t *sem) { return 0; +} + +int32_t __sync_val_load_32(int32_t *ptr) { + return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); +} + +void __sync_val_restore_32(int32_t *ptr, int32_t newval) { + __atomic_store_n(ptr, newval, __ATOMIC_RELEASE); } \ No newline at end of file diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h index e842f486e1..47533a8544 100644 --- a/src/os/linux/inc/os.h +++ b/src/os/linux/inc/os.h @@ -62,6 +62,8 @@ #define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap #define __sync_add_and_fetch_64 __sync_add_and_fetch #define __sync_add_and_fetch_32 __sync_add_and_fetch +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 { \ diff --git a/src/os/linux/src/tlinux.c b/src/os/linux/src/tlinux.c index 251b53cbd2..b5271006e2 100644 --- a/src/os/linux/src/tlinux.c +++ b/src/os/linux/src/tlinux.c @@ -339,4 +339,12 @@ bool taosSkipSocketCheck() { } return false; -} \ No newline at end of file +} + +int32_t __sync_val_load_32(int32_t *ptr) { + return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); +} + +void __sync_val_restore_32(int32_t *ptr, int32_t newval) { + __atomic_store_n(ptr, newval, __ATOMIC_RELEASE); +} diff --git a/src/os/windows/inc/os.h b/src/os/windows/inc/os.h index cb2fd2e034..c74709449d 100644 --- a/src/os/windows/inc/os.h +++ b/src/os/windows/inc/os.h @@ -78,6 +78,8 @@ int32_t __sync_val_compare_and_swap_32(int32_t *ptr, int32_t oldval, int32_t new int32_t __sync_add_and_fetch_32(int32_t *ptr, int32_t val); int64_t __sync_val_compare_and_swap_64(int64_t *ptr, int64_t oldval, int64_t newval); int64_t __sync_add_and_fetch_64(int64_t *ptr, int64_t 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 { \ @@ -151,6 +153,8 @@ 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); diff --git a/src/os/windows/src/twindows.c b/src/os/windows/src/twindows.c index f2aa4d2c50..2de719b0fd 100644 --- a/src/os/windows/src/twindows.c +++ b/src/os/windows/src/twindows.c @@ -47,7 +47,7 @@ int64_t taosGetPthreadId() { } int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) { - if (level == SOL_TCP && optname == TCP_KEEPCNT) { + if (level == SOL_SOCKET && optname == TCP_KEEPCNT) { return 0; } @@ -78,6 +78,14 @@ int64_t __sync_add_and_fetch_64(int64_t *ptr, int64_t val) { return InterlockedAdd64(ptr, val); } +int32_t __sync_val_load_32(int32_t *ptr) { + return InterlockedOr(ptr, 0); +} + +void __sync_val_restore_32(int32_t *ptr, int32_t newval) { + InterlockedCompareExchange(ptr, *ptr, newval); +} + void tsPrintOsInfo() {} char *taosCharsetReplace(char *charsetstr) { @@ -178,6 +186,10 @@ 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; } -- GitLab