diff --git a/src/os/inc/eok.h b/src/os/inc/eok.h index 4d38e8e6328fb230441349ce7e19ab458d114243..0874ca975b44a2e355c7eb746af4f30b4d163610 100644 --- a/src/os/inc/eok.h +++ b/src/os/inc/eok.h @@ -22,6 +22,8 @@ extern "C" { #endif +#ifdef __APPLE__ + enum EPOLL_EVENTS { EPOLLIN = 0x001, @@ -81,6 +83,8 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); int epoll_close(int epfd); +#endif // __APPLE__ + #ifdef __cplusplus } #endif diff --git a/src/os/inc/osDarwin.h b/src/os/inc/osDarwin.h index 52bb661f89efe10f47f0597037efb99fba2fcbd9..935708eb1b4dfa6803705f1238f459061a1c3737 100644 --- a/src/os/inc/osDarwin.h +++ b/src/os/inc/osDarwin.h @@ -104,6 +104,8 @@ int64_t tsosStr2int64(char *str); #include "eok.h" +void taos_block_sigalrm(void); + diff --git a/src/os/src/darwin/darwinTimer.c b/src/os/src/darwin/darwinTimer.c index 5fe65fb99ed72357d88ecbf5d4699bcbb42360c6..121e2e9427a7e313db9f718883d5f21ff39c3dad 100644 --- a/src/os/src/darwin/darwinTimer.c +++ b/src/os/src/darwin/darwinTimer.c @@ -34,3 +34,16 @@ void taosUninitTimer() { setitimer(ITIMER_REAL, &tv, NULL); } +void taos_block_sigalrm(void) { + // since SIGALRM has been used + // consideration: any better solution? + static __thread int already_set = 0; + if (!already_set) { + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGALRM); + pthread_sigmask(SIG_BLOCK, &set, NULL); + already_set = 1; + } +} + diff --git a/src/os/src/darwin/eok.c b/src/os/src/darwin/eok.c index 1be5ec4ac13c0ca690ee3b5a5358b20dd3b36260..9c6a263a40c593cd2484faac8381eb529303b1f7 100644 --- a/src/os/src/darwin/eok.c +++ b/src/os/src/darwin/eok.c @@ -15,15 +15,11 @@ #include "eok.h" -#include -#include -#include -#include -#include -#include +#include "os.h" + #include -#include -#include + +#define LET_IT_BE #ifdef ENABLE_LOG #define D(fmt, ...) fprintf(stderr, "%s[%d]%s(): " fmt "\n", basename(__FILE__), __LINE__, __func__, ##__VA_ARGS__) @@ -414,6 +410,8 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) { static struct timespec do_timespec_diff(struct timespec *from, struct timespec *to); int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) { + taos_block_sigalrm(); + int e = 0; if (!events) { errno = EINVAL; @@ -699,7 +697,7 @@ static void eok_free_ev(ep_over_kq_t *eok, eok_event_t *ev) { else eok->evs_tail = ev->prev; ev->prev = NULL; ev->next = eok->evs_free; - eok->evs_free = ev->next; + eok->evs_free = ev; eok->evs_count -= 1; } diff --git a/src/os/src/detail/osTimer.c b/src/os/src/detail/osTimer.c index 1d3ba30def9416785d72556ac218bd5a48aead77..c1135ce292c4ef0a5ae968525ca2685a97b6f62e 100644 --- a/src/os/src/detail/osTimer.c +++ b/src/os/src/detail/osTimer.c @@ -116,6 +116,9 @@ void taosUninitTimer() { pthread_sigmask(SIG_BLOCK, &set, NULL); */ void taosMsleep(int mseconds) { +#ifdef __APPLE__ + taos_block_sigalrm(); +#endif // __APPLE__ #if 1 usleep(mseconds * 1000); #else @@ -136,6 +139,7 @@ void taosMsleep(int mseconds) { /* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */ #endif + } -#endif \ No newline at end of file +#endif