提交 94eb0e1e 编写于 作者: F freemine

1. __APPLE__

2. tsem_xxx for mac
上级 6485afb6
......@@ -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;
......
......@@ -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}};
......
......@@ -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};
......
......@@ -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;
......
......@@ -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
......
......@@ -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
......
......@@ -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;
......
......@@ -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));
......@@ -478,6 +478,9 @@ static void *taosProcessTcpData(void *param) {
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;
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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) {
......
......@@ -15,9 +15,9 @@
#ifdef __APPLE__
#include "eok.h"
#else
#else // __APPLE__
#include <sys/epoll.h>
#endif
#endif // __APPLE__
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册