diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 19a1e99c33ced27124a9e6b0b6e357d108ebd896..bb2a81db66585f2db404e0529801480af50ef5df 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 893049df2ee445a1e5f1b558b35f67a2f12853e2..7a218f901e99302f01860738b988083fa559f4f3 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 1f7084c3b5fc3cc98646926a0007c52ca0c7cbfe..b2e8eac267fc797b7cca3198593eda4d95d20233 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 1b153247f033bc16aeadb1812f25383f70741fb8..5dee0e1c26399f5a17f86f94f9db0c3fddb7169a 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 935708eb1b4dfa6803705f1238f459061a1c3737..0a77ed68956a8b4a9e1252ee606b623fbf8b19fe 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 d718bef6da42f59c5ee4ea7bfaad098b47062984..f646940d3aa4379ba6e7ca12b106fdd4b147f5b1 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 97a5b4bc235290bbe0c7c0d9bc6855fd18ad966f..6a8eb556d8a1a64946c67ce02d0f80b5ad22bba1 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 ba90f93073051c0c8c776496a3f3f77688764867..d64bdb42aad37cb64d14e48804d542210512057b 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 1e5761316a5730f3b0dff8d7bfb4582689274eb6..e15f71e905e06ff448cab5090613f95bb31f4671 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 984839162e888c34bd7c898b2d6fefd74945ab60..f3e69d92103b691b934bf0dee8ccbde324da89fa 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 9551d1b3a5aa53a7c3afc61ebf26f82c735ab39c..1c8a661c0a87711065e02cd2e5092a199506cb4c 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 5493188c0933cf8d1c06de1a2ff87ca3ea213596..c770f0ff4264b05ce6413ca04d89000d829d67c4 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 202405df00d9307e884168b85a8442f0eeff55a6..206a3332d57e4db3f4ce6fae4421298fd0736865 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 cfd948265bac1d7895f3a77922409e52004ee010..4bfd7a855bae4a8aab958f485b43174aaf0233aa 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 eb66156c14ae6a856846b28fb061e0766c923eb2..4f65ea478e21dbf7d5fe067bfc5b142c410ad666 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