From 94eb0e1e71b713d66d00274242d7667408095154 Mon Sep 17 00:00:00 2001 From: freemine Date: Sat, 23 Jan 2021 08:44:32 +0800 Subject: [PATCH] 1. __APPLE__ 2. tsem_xxx for mac --- src/client/src/tscUtil.c | 4 ++-- src/dnode/src/dnodeSystem.c | 2 +- src/dnode/src/dnodeTelemetry.c | 2 +- src/mnode/src/mnodeCluster.c | 1 + src/os/inc/osDarwin.h | 10 +++++----- src/os/inc/osDef.h | 5 +++-- src/plugins/http/src/httpServer.c | 2 +- src/rpc/src/rpcTcp.c | 13 ++++++++----- src/sync/src/syncTcp.c | 8 ++++---- src/tsdb/inc/tsdbMain.h | 4 ++-- src/tsdb/src/tsdbCommit.c | 4 ++-- src/tsdb/src/tsdbMain.c | 12 ++++++------ src/tsdb/src/tsdbMemTable.c | 8 ++++---- src/util/src/tsocket.c | 2 +- tests/examples/c/epoll.c | 4 ++-- 15 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 19a1e99c33..bb2a81db66 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2520,9 +2520,9 @@ bool tscSetSqlOwner(SSqlObj* pSql) { // set the sql object owner #ifdef __APPLE__ pthread_t threadId = (pthread_t)taosGetSelfPthreadId(); -#else +#else // __APPLE__ uint64_t threadId = taosGetSelfPthreadId(); -#endif +#endif // __APPLE__ if (atomic_val_compare_exchange_64(&pSql->owner, 0, threadId) != 0) { pRes->code = TSDB_CODE_QRY_IN_EXEC; return false; diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 893049df2e..7a218f901e 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -164,7 +164,7 @@ static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) { dInfo("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid); #else // __APPLE__ dInfo("shut down signal is %d, sender PID:%d cmdline:%s", signum, sigInfo->si_pid, taosGetCmdlineByPID(sigInfo->si_pid)); -#endif +#endif // __APPLE__ // protect the application from receive another signal struct sigaction act = {{0}}; diff --git a/src/dnode/src/dnodeTelemetry.c b/src/dnode/src/dnodeTelemetry.c index 1f7084c3b5..b2e8eac267 100644 --- a/src/dnode/src/dnodeTelemetry.c +++ b/src/dnode/src/dnodeTelemetry.c @@ -241,7 +241,7 @@ static int sem_timedwait(tsem_t *sem, struct timespec *to) { fprintf(stderr, "%s[%d]%s(): not implemented yet!\n", basename(__FILE__), __LINE__, __func__); abort(); } -#endif +#endif // __APPLE__ static void* telemetryThread(void* param) { struct timespec end = {0}; diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index 1b153247f0..5dee0e1c26 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -145,6 +145,7 @@ bool taosGetSystemUid(char *uid) { return false; } #endif // __APPLE__ + static int32_t mnodeCreateCluster() { int32_t numOfClusters = sdbGetNumOfRows(tsClusterSdb); if (numOfClusters != 0) return TSDB_CODE_SUCCESS; diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index 935708eb1b..0a77ed6895 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -75,11 +75,11 @@ extern "C" { #define TAOS_OS_FUNC_FILE_SENDIFLE #define TAOS_OS_FUNC_SEMPHONE - #define tsem_t dispatch_semaphore_t - int tsem_init(dispatch_semaphore_t *sem, int pshared, unsigned int value); - int tsem_wait(dispatch_semaphore_t *sem); - int tsem_post(dispatch_semaphore_t *sem); - int tsem_destroy(dispatch_semaphore_t *sem); + 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_STRING_STR2INT64 diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h index d718bef6da..f646940d3a 100644 --- a/src/os/inc/osDef.h +++ b/src/os/inc/osDef.h @@ -90,11 +90,12 @@ extern "C" { #ifdef _ISOC11_SOURCE #define threadlocal _Thread_local #elif defined(__APPLE__) - #define threadlocal + #define threadlocal __thread #elif defined(__GNUC__) && !defined(threadlocal) #define threadlocal __thread #else - #define threadlocal + // #define threadlocal + #error please follow with the target platform's thread-local implementation #endif #ifdef __cplusplus diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 97a5b4bc23..6a8eb556d8 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -33,7 +33,7 @@ static bool httpReadData(HttpContext *pContext); #ifdef __APPLE__ static int sv_dummy = 0; -#endif +#endif // __APPLE__ static void httpStopThread(HttpThread* pThread) { pThread->stop = true; diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index ba90f93073..d64bdb42aa 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -312,9 +312,9 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * epoll_close(pThreadObj->pollFd); pThreadObj->pollFd = -1; } -#else +#else // __APPLE__ taosCloseSocket(pThreadObj->pollFd); -#endif +#endif // __APPLE__ free(pThreadObj); terrno = TAOS_SYSTEM_ERROR(errno); tError("%s failed to create TCP read data thread(%s)", label, strerror(errno)); @@ -477,7 +477,10 @@ static void *taosProcessTcpData(void *param) { SFdObj *pFdObj; struct epoll_event events[maxEvents]; SRecvInfo recvInfo; - + +#ifdef __APPLE__ + taos_block_sigalrm(); +#endif // __APPLE__ while (1) { int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, TAOS_EPOLL_WAIT_TIME); if (pThreadObj->stop) { @@ -524,9 +527,9 @@ static void *taosProcessTcpData(void *param) { epoll_close(pThreadObj->pollFd); pThreadObj->pollFd = -1; } -#else +#else // __APPLE__ if (pThreadObj->pollFd >=0) taosCloseSocket(pThreadObj->pollFd); -#endif +#endif // __APPLE__ while (pThreadObj->pHead) { SFdObj *pFdObj = pThreadObj->pHead; diff --git a/src/sync/src/syncTcp.c b/src/sync/src/syncTcp.c index 1e5761316a..e15f71e905 100644 --- a/src/sync/src/syncTcp.c +++ b/src/sync/src/syncTcp.c @@ -235,9 +235,9 @@ static void *syncProcessTcpData(void *param) { #ifdef __APPLE__ epoll_close(pThread->pollFd); -#else +#else // __APPLE__ close(pThread->pollFd); -#endif +#endif // __APPLE__ tfree(pThread); tfree(buffer); return NULL; @@ -296,9 +296,9 @@ static SThreadObj *syncGetTcpThread(SPoolObj *pPool) { if (ret != 0) { #ifdef __APPLE__ epoll_close(pThread->pollFd); -#else +#else // __APPLE__ close(pThread->pollFd); -#endif +#endif // __APPLE__ tfree(pThread); return NULL; } diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index 984839162e..f3e69d9210 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -235,9 +235,9 @@ typedef struct { STsdbFileH* tsdbFileH; #ifdef __APPLE__ sem_t *readyToCommit; -#else +#else // __APPLE__ sem_t readyToCommit; -#endif +#endif // __APPLE__ pthread_mutex_t mutex; bool repoLocked; int32_t code; // Commit code diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index 9551d1b3a5..1c8a661c0a 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -168,9 +168,9 @@ static void tsdbEndCommit(STsdbRepo *pRepo, int eno) { tsdbUnRefMemTable(pRepo, pIMem); #ifdef __APPLE__ sem_post(pRepo->readyToCommit); -#else +#else // __APPLE__ sem_post(&(pRepo->readyToCommit)); -#endif +#endif // __APPLE__ } static int tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey) { diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 5493188c09..c770f0ff42 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -148,9 +148,9 @@ int tsdbCloseRepo(TSDB_REPO_T *repo, int toCommit) { tsdbAsyncCommit(pRepo); #ifdef __APPLE__ sem_wait(pRepo->readyToCommit); -#else +#else // __APPLE__ sem_wait(&(pRepo->readyToCommit)); -#endif +#endif // __APPLE__ terrno = pRepo->code; } tsdbUnRefMemTable(pRepo, pRepo->mem); @@ -654,14 +654,14 @@ static STsdbRepo *tsdbNewRepo(char *rootDir, STsdbAppH *pAppH, STsdbCfg *pCfg) { terrno = TAOS_SYSTEM_ERROR(code); goto _err; } -#else +#else // __APPLE__ code = sem_init(&(pRepo->readyToCommit), 0, 1); if (code != 0) { code = errno; terrno = TAOS_SYSTEM_ERROR(code); goto _err; } -#endif +#endif // __APPLE__ pRepo->repoLocked = false; @@ -709,9 +709,9 @@ static void tsdbFreeRepo(STsdbRepo *pRepo) { tfree(pRepo->rootDir); #ifdef __APPLE__ sem_close(pRepo->readyToCommit); -#else +#else // __APPLE__ sem_destroy(&(pRepo->readyToCommit)); -#endif +#endif // __APPLE__ pthread_mutex_destroy(&pRepo->mutex); free(pRepo); } diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 202405df00..206a3332d5 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -209,9 +209,9 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) { #ifdef __APPLE__ sem_wait(pRepo->readyToCommit); -#else +#else // __APPLE__ sem_wait(&(pRepo->readyToCommit)); -#endif +#endif // __APPLE__ ASSERT(pRepo->imem == NULL); @@ -236,10 +236,10 @@ int tsdbSyncCommit(TSDB_REPO_T *repo) { #ifdef __APPLE__ sem_wait(pRepo->readyToCommit); sem_post(pRepo->readyToCommit); -#else +#else // __APPLE__ sem_wait(&(pRepo->readyToCommit)); sem_post(&(pRepo->readyToCommit)); -#endif +#endif // __APPLE__ if (pRepo->code != TSDB_CODE_SUCCESS) { terrno = pRepo->code; diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index cfd948265b..4bfd7a855b 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -376,7 +376,7 @@ int32_t taosKeepTcpAlive(SOCKET sockFd) { taosCloseSocket(sockFd); return -1; } -#endif +#endif // __APPLE__ int32_t nodelay = 1; if (taosSetSockOpt(sockFd, IPPROTO_TCP, TCP_NODELAY, (void *)&nodelay, sizeof(nodelay)) < 0) { diff --git a/tests/examples/c/epoll.c b/tests/examples/c/epoll.c index eb66156c14..4f65ea478e 100644 --- a/tests/examples/c/epoll.c +++ b/tests/examples/c/epoll.c @@ -15,9 +15,9 @@ #ifdef __APPLE__ #include "eok.h" -#else +#else // __APPLE__ #include -#endif +#endif // __APPLE__ #include #include #include -- GitLab