MCPcopy Create free account
hub / github.com/apache/brpc / epoll_thread

Function epoll_thread

test/bthread_fd_unittest.cpp:118–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118void* epoll_thread(void* arg) {
119 bthread_usleep(1);
120 EpollMeta* m = (EpollMeta*)arg;
121 const int epfd = m->epfd;
122#if defined(OS_LINUX)
123 epoll_event e[32];
124#elif defined(OS_MACOSX)
125 struct kevent e[32];
126#endif
127
128 while (!stop) {
129
130#if defined(OS_LINUX)
131# ifndef USE_BLOCKING_EPOLL
132 const int n = epoll_wait(epfd, e, ARRAY_SIZE(e), 0);
133 if (stop) {
134 break;
135 }
136 if (n == 0) {
137 bthread_fd_wait(epfd, EPOLLIN);
138 continue;
139 }
140# else
141 const int n = epoll_wait(epfd, e, ARRAY_SIZE(e), -1);
142 if (stop) {
143 break;
144 }
145 if (n == 0) {
146 continue;
147 }
148# endif
149#elif defined(OS_MACOSX)
150 const int n = kevent(epfd, NULL, 0, e, ARRAY_SIZE(e), NULL);
151 if (stop) {
152 break;
153 }
154 if (n == 0) {
155 continue;
156 }
157#endif
158 if (n < 0) {
159 if (EINTR == errno) {
160 continue;
161 }
162#if defined(OS_LINUX)
163 PLOG(FATAL) << "Fail to epoll_wait";
164#elif defined(OS_MACOSX)
165 PLOG(FATAL) << "Fail to kevent";
166#endif
167 break;
168 }
169
170#ifdef CREATE_THREAD_TO_PROCESS
171 bthread_fvec vec[n];
172 for (int i = 0; i < n; ++i) {
173 vec[i].fn = process_thread;
174# if defined(OS_LINUX)
175 vec[i].arg = e[i].data.ptr;

Callers

nothing calls this directly

Calls 4

bthread_usleepFunction · 0.85
bthread_fd_waitFunction · 0.85
keventClass · 0.70
process_threadFunction · 0.70

Tested by

no test coverage detected