From a4f75510d7f4b3dc10a1587e6f1055afae32ed8c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 8 May 2021 15:19:15 +0800 Subject: [PATCH] TD-4088 --- src/os/inc/osDarwin.h | 12 +----------- src/os/inc/osSemphone.h | 13 +++++++++---- src/os/inc/osString.h | 2 +- src/os/inc/osWindows.h | 1 - src/os/src/darwin/darwinSemphone.c | 24 ++++++++++++------------ src/os/src/detail/osSemphone.c | 8 ++++---- src/os/src/windows/wGetline.c | 1 + 7 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index f8e3c65d63..c90f604f6e 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -74,17 +74,9 @@ extern "C" { #define TAOS_OS_FUNC_FILE_SENDIFLE -#define TAOS_OS_FUNC_SEMPHONE - typedef struct tsem_s *tsem_t; - int tsem_init(tsem_t *sem, int pshared, unsigned int value); - int tsem_wait(tsem_t *sem); - int tsem_post(tsem_t *sem); - int tsem_destroy(tsem_t *sem); - #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT #define TAOS_OS_FUNC_SYSINFO -#define TAOS_OS_FUNC_TIMER -#define TAOS_OS_FUNC_SEMPHONE_PTHREAD +#define TAOS_OS_FUNC_TIMERD // specific typedef int(*__compar_fn_t)(const void *, const void *); @@ -104,8 +96,6 @@ typedef int(*__compar_fn_t)(const void *, const void *); #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE #endif -#define TAOS_OS_FUNC_PTHREAD_RWLOCK - #include "eok.h" void taos_block_sigalrm(void); diff --git a/src/os/inc/osSemphone.h b/src/os/inc/osSemphone.h index 3332a9234b..2e2d432607 100644 --- a/src/os/inc/osSemphone.h +++ b/src/os/inc/osSemphone.h @@ -20,15 +20,21 @@ extern "C" { #endif -#ifndef TAOS_OS_FUNC_SEMPHONE +#if defined (_TD_DARWIN_64) + typedef struct tsem_s *tsem_t; + int tsem_init(tsem_t *sem, int pshared, unsigned int value); + int tsem_wait(tsem_t *sem); + int tsem_post(tsem_t *sem); + int tsem_destroy(tsem_t *sem); +#else #define tsem_t sem_t #define tsem_init sem_init - int tsem_wait(tsem_t* sem); + int32_t tsem_wait(tsem_t* sem); #define tsem_post sem_post #define tsem_destroy sem_destroy #endif -#ifdef TAOS_OS_FUNC_PTHREAD_RWLOCK +#if defined (_TD_DARWIN_64) #define pthread_rwlock_t pthread_mutex_t #define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL) #define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock) @@ -43,7 +49,6 @@ extern "C" { #define pthread_spin_unlock(lock) pthread_mutex_unlock(lock) #endif -// TAOS_OS_FUNC_SEMPHONE_PTHREAD bool taosCheckPthreadValid(pthread_t thread); int64_t taosGetSelfPthreadId(); int64_t taosGetPthreadId(pthread_t thread); diff --git a/src/os/inc/osString.h b/src/os/inc/osString.h index f2e8b381fe..33f858485c 100644 --- a/src/os/inc/osString.h +++ b/src/os/inc/osString.h @@ -28,7 +28,7 @@ extern "C" { #else #define tstrdup(str) strdup(str) #define tstrndup(str, size) strndup(str, size) - #define tgetline(lineptr, n, stream) getline(lineptr, n , stream) + #define tgetline(lineptr, n, stream) getline(lineptr, n, stream) #define twcslen wcslen #endif diff --git a/src/os/inc/osWindows.h b/src/os/inc/osWindows.h index f90ae6f059..bfb3811176 100644 --- a/src/os/inc/osWindows.h +++ b/src/os/inc/osWindows.h @@ -65,7 +65,6 @@ extern "C" { #define TAOS_OS_FUNC_FILE_FTRUNCATE -#define TAOS_OS_FUNC_SEMPHONE_PTHREAD #define TAOS_OS_FUNC_SOCKET #define TAOS_OS_FUNC_SOCKET_SETSOCKETOPT diff --git a/src/os/src/darwin/darwinSemphone.c b/src/os/src/darwin/darwinSemphone.c index 5bb926732a..1805fd176f 100644 --- a/src/os/src/darwin/darwinSemphone.c +++ b/src/os/src/darwin/darwinSemphone.c @@ -37,7 +37,7 @@ static pthread_t sem_thread; static pthread_once_t sem_once; static task_t sem_port; -static volatile int sem_inited = 0; +static volatile int32_t sem_inited = 0; static semaphore_t sem_exit; static void* sem_thread_routine(void *arg) { @@ -55,7 +55,7 @@ static void* sem_thread_routine(void *arg) { } static void once_init(void) { - int r = 0; + int32_t r = 0; r = pthread_create(&sem_thread, NULL, sem_thread_routine, NULL); if (r) { fprintf(stderr, "==%s[%d]%s()==failed to create thread\n", basename(__FILE__), __LINE__, __func__); @@ -81,10 +81,10 @@ struct tsem_s { dispatch_semaphore_t sem; #endif // SEM_USE_PTHREAD - volatile unsigned int valid:1; + volatile unsigned int32_t valid:1; }; -int tsem_init(tsem_t *sem, int pshared, unsigned int value) { +int32_t tsem_init(tsem_t *sem, int32_t pshared, unsigned int32_t value) { // fprintf(stderr, "==%s[%d]%s():[%p]==creating\n", basename(__FILE__), __LINE__, __func__, sem); if (*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==already initialized\n", basename(__FILE__), __LINE__, __func__, sem); @@ -97,7 +97,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) { } #ifdef SEM_USE_PTHREAD - int r = pthread_mutex_init(&p->lock, NULL); + int32_t r = pthread_mutex_init(&p->lock, NULL); do { if (r) break; r = pthread_cond_init(&p->cond, NULL); @@ -124,7 +124,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) { p->sem = sem_open(name, O_CREAT|O_EXCL, pshared, value); p->id = id; if (p->sem!=SEM_FAILED) break; - int e = errno; + int32_t e = errno; if (e==EEXIST) continue; if (e==EINTR) continue; fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e)); @@ -158,7 +158,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) { return 0; } -int tsem_wait(tsem_t *sem) { +int32_t tsem_wait(tsem_t *sem) { if (!*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); abort(); @@ -194,7 +194,7 @@ int tsem_wait(tsem_t *sem) { #endif // SEM_USE_PTHREAD } -int tsem_post(tsem_t *sem) { +int32_t tsem_post(tsem_t *sem) { if (!*sem) { fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); abort(); @@ -230,7 +230,7 @@ int tsem_post(tsem_t *sem) { #endif // SEM_USE_PTHREAD } -int tsem_destroy(tsem_t *sem) { +int32_t tsem_destroy(tsem_t *sem) { // fprintf(stderr, "==%s[%d]%s():[%p]==destroying\n", basename(__FILE__), __LINE__, __func__, sem); if (!*sem) { // fprintf(stderr, "==%s[%d]%s():[%p]==not initialized\n", basename(__FILE__), __LINE__, __func__, sem); @@ -264,9 +264,9 @@ int tsem_destroy(tsem_t *sem) { #elif defined(SEM_USE_POSIX) char name[NAME_MAX-4]; snprintf(name, sizeof(name), "/t%ld", p->id); - int r = sem_unlink(name); + int32_t r = sem_unlink(name); if (r) { - int e = errno; + int32_t e = errno; fprintf(stderr, "==%s[%d]%s():[%p]==unlink failed[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e)); abort(); } @@ -284,7 +284,7 @@ int tsem_destroy(tsem_t *sem) { bool taosCheckPthreadValid(pthread_t thread) { uint64_t id = 0; - int r = pthread_threadid_np(thread, &id); + int32_t r = pthread_threadid_np(thread, &id); return r ? false : true; } diff --git a/src/os/src/detail/osSemphone.c b/src/os/src/detail/osSemphone.c index 2bf2f24487..06907d5258 100644 --- a/src/os/src/detail/osSemphone.c +++ b/src/os/src/detail/osSemphone.c @@ -16,9 +16,9 @@ #define _DEFAULT_SOURCE #include "os.h" -#ifndef TAOS_OS_FUNC_SEMPHONE +#if !defined (_TD_DARWIN_64) -int tsem_wait(tsem_t* sem) { +int32_t tsem_wait(tsem_t* sem) { int ret = 0; do { ret = sem_wait(sem); @@ -28,9 +28,9 @@ int tsem_wait(tsem_t* sem) { #endif -#ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined (_TD_DARWIN_64)) -bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } +bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } int64_t taosGetSelfPthreadId() { static __thread int id = 0; diff --git a/src/os/src/windows/wGetline.c b/src/os/src/windows/wGetline.c index b9d8ccf928..553aecaf0a 100644 --- a/src/os/src/windows/wGetline.c +++ b/src/os/src/windows/wGetline.c @@ -22,6 +22,7 @@ General Public License for more details. */ #include #include #include +#include #if STDC_HEADERS #include -- GitLab