blob: 98a73eb0ef4539a7cc2a96bb7cb01791e8a11713 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/* http://frotznet.googlecode.com/svn/trunk/utils/fdevent.c
2**
3** Copyright 2006, Brian Swetland <swetland@frotz.net>
4**
Elliott Hughesaa245492015-08-03 10:38:08 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08008**
Elliott Hughesaa245492015-08-03 10:38:08 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080010**
Elliott Hughesaa245492015-08-03 10:38:08 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080015** limitations under the License.
16*/
17
Yabin Cuiaed3c612015-09-22 15:52:57 -070018#define TRACE_TAG FDEVENT
JP Abgrall408fa572011-03-16 15:57:42 -070019
Dan Albert33134262015-03-19 15:21:08 -070020#include "sysdeps.h"
21#include "fdevent.h"
22
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080023#include <fcntl.h>
Josh Gaoded557f2018-06-18 14:55:27 -070024#include <inttypes.h>
Josh Gao5791e212018-03-16 14:25:42 -070025#include <stdint.h>
Dan Albert33134262015-03-19 15:21:08 -070026#include <stdlib.h>
27#include <string.h>
Dan Albert33134262015-03-19 15:21:08 -070028#include <unistd.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080029
Josh Gao022d4472016-02-10 14:49:00 -080030#include <atomic>
Josh Gaoe39ccd32018-02-23 14:37:07 -080031#include <deque>
Josh Gao4c936392017-05-03 14:10:39 -070032#include <functional>
Yabin Cuia1080162015-09-04 16:19:56 -070033#include <list>
Josh Gao4c936392017-05-03 14:10:39 -070034#include <mutex>
Yabin Cuia1080162015-09-04 16:19:56 -070035#include <unordered_map>
36#include <vector>
37
Elliott Hughes4f713192015-12-04 22:00:26 -080038#include <android-base/logging.h>
39#include <android-base/stringprintf.h>
Josh Gao4c936392017-05-03 14:10:39 -070040#include <android-base/thread_annotations.h>
Josh Gao5791e212018-03-16 14:25:42 -070041#include <android-base/threads.h>
Yabin Cuia1080162015-09-04 16:19:56 -070042
Dan Albertcc731cc2015-02-24 21:26:58 -080043#include "adb_io.h"
leozwangd3fc15f2014-07-29 12:50:02 -070044#include "adb_trace.h"
Josh Gao4c936392017-05-03 14:10:39 -070045#include "adb_unique_fd.h"
Yabin Cui6dfef252015-10-06 15:10:05 -070046#include "adb_utils.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080047
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080048#define FDE_EVENTMASK 0x00ff
49#define FDE_STATEMASK 0xff00
50
51#define FDE_ACTIVE 0x0100
52#define FDE_PENDING 0x0200
53#define FDE_CREATED 0x0400
54
Yabin Cuia1080162015-09-04 16:19:56 -070055struct PollNode {
56 fdevent* fde;
Josh Gao3777d2e2016-02-16 17:34:53 -080057 adb_pollfd pollfd;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080058
Chih-Hung Hsieh1c563d92016-04-29 15:44:04 -070059 explicit PollNode(fdevent* fde) : fde(fde) {
Yabin Cuia1080162015-09-04 16:19:56 -070060 memset(&pollfd, 0, sizeof(pollfd));
Josh Gao3b37fa22018-05-14 13:42:49 -070061 pollfd.fd = fde->fd.get();
Yabin Cuiaa77e222015-09-29 12:25:33 -070062
63#if defined(__linux__)
64 // Always enable POLLRDHUP, so the host server can take action when some clients disconnect.
65 // Then we can avoid leaving many sockets in CLOSE_WAIT state. See http://b/23314034.
66 pollfd.events = POLLRDHUP;
67#endif
Yabin Cuia1080162015-09-04 16:19:56 -070068 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080069};
70
Yabin Cuia1080162015-09-04 16:19:56 -070071// All operations to fdevent should happen only in the main thread.
72// That's why we don't need a lock for fdevent.
Josh Gaob7b1edf2015-11-11 17:56:12 -080073static auto& g_poll_node_map = *new std::unordered_map<int, PollNode>();
74static auto& g_pending_list = *new std::list<fdevent*>();
Josh Gao022d4472016-02-10 14:49:00 -080075static std::atomic<bool> terminate_loop(false);
Yabin Cuifbfa8402015-10-30 18:37:26 -070076static bool main_thread_valid;
Josh Gao5791e212018-03-16 14:25:42 -070077static uint64_t main_thread_id;
Yabin Cuifbfa8402015-10-30 18:37:26 -070078
Josh Gaoded557f2018-06-18 14:55:27 -070079static uint64_t fdevent_id;
80
Josh Gaofa30bf32018-03-29 16:23:43 -070081static bool run_needs_flush = false;
Josh Gao4c936392017-05-03 14:10:39 -070082static auto& run_queue_notify_fd = *new unique_fd();
83static auto& run_queue_mutex = *new std::mutex();
Josh Gaoe39ccd32018-02-23 14:37:07 -080084static auto& run_queue GUARDED_BY(run_queue_mutex) = *new std::deque<std::function<void()>>();
Josh Gao4c936392017-05-03 14:10:39 -070085
Yabin Cuib5e11412017-03-10 16:01:01 -080086void check_main_thread() {
Yabin Cuifbfa8402015-10-30 18:37:26 -070087 if (main_thread_valid) {
Josh Gao5791e212018-03-16 14:25:42 -070088 CHECK_EQ(main_thread_id, android::base::GetThreadId());
Yabin Cuifbfa8402015-10-30 18:37:26 -070089 }
90}
91
Yabin Cuib5e11412017-03-10 16:01:01 -080092void set_main_thread() {
Yabin Cuifbfa8402015-10-30 18:37:26 -070093 main_thread_valid = true;
Josh Gao5791e212018-03-16 14:25:42 -070094 main_thread_id = android::base::GetThreadId();
Yabin Cuifbfa8402015-10-30 18:37:26 -070095}
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080096
Yabin Cuia1080162015-09-04 16:19:56 -070097static std::string dump_fde(const fdevent* fde) {
98 std::string state;
99 if (fde->state & FDE_ACTIVE) {
100 state += "A";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800101 }
Yabin Cuia1080162015-09-04 16:19:56 -0700102 if (fde->state & FDE_PENDING) {
103 state += "P";
104 }
105 if (fde->state & FDE_CREATED) {
106 state += "C";
107 }
108 if (fde->state & FDE_READ) {
109 state += "R";
110 }
111 if (fde->state & FDE_WRITE) {
112 state += "W";
113 }
114 if (fde->state & FDE_ERROR) {
115 state += "E";
116 }
Josh Gaoded557f2018-06-18 14:55:27 -0700117 return android::base::StringPrintf("(fdevent %" PRIu64 ": fd %d %s)", fde->id, fde->fd.get(),
118 state.c_str());
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800119}
120
Yabin Cuia1080162015-09-04 16:19:56 -0700121void fdevent_install(fdevent* fde, int fd, fd_func func, void* arg) {
Yabin Cuifbfa8402015-10-30 18:37:26 -0700122 check_main_thread();
Yabin Cuia1080162015-09-04 16:19:56 -0700123 CHECK_GE(fd, 0);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800124 memset(fde, 0, sizeof(fdevent));
Josh Gao71f775a2018-05-14 11:14:33 -0700125}
126
127fdevent* fdevent_create(int fd, fd_func func, void* arg) {
128 check_main_thread();
129 CHECK_GE(fd, 0);
130
131 fdevent* fde = new fdevent();
Josh Gaoded557f2018-06-18 14:55:27 -0700132 fde->id = fdevent_id++;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800133 fde->state = FDE_ACTIVE;
Josh Gao3b37fa22018-05-14 13:42:49 -0700134 fde->fd.reset(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800135 fde->func = func;
136 fde->arg = arg;
Yabin Cui6dfef252015-10-06 15:10:05 -0700137 if (!set_file_block_mode(fd, false)) {
Yabin Cuic1b1f6f2015-09-15 16:27:09 -0700138 // Here is not proper to handle the error. If it fails here, some error is
139 // likely to be detected by poll(), then we can let the callback function
140 // to handle it.
Yabin Cui6dfef252015-10-06 15:10:05 -0700141 LOG(ERROR) << "failed to set non-blocking mode for fd " << fd;
Yabin Cuia1080162015-09-04 16:19:56 -0700142 }
Josh Gao3b37fa22018-05-14 13:42:49 -0700143 auto pair = g_poll_node_map.emplace(fde->fd.get(), PollNode(fde));
Yabin Cuia1080162015-09-04 16:19:56 -0700144 CHECK(pair.second) << "install existing fd " << fd;
Josh Gao71f775a2018-05-14 11:14:33 -0700145
146 fde->state |= FDE_CREATED;
147 return fde;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800148}
149
Josh Gao2f6c2fa2018-09-20 17:38:55 -0700150unique_fd fdevent_release(fdevent* fde) {
Yabin Cuifbfa8402015-10-30 18:37:26 -0700151 check_main_thread();
Josh Gao2f6c2fa2018-09-20 17:38:55 -0700152 if (!fde) {
153 return {};
154 }
155
Josh Gao71f775a2018-05-14 11:14:33 -0700156 if (!(fde->state & FDE_CREATED)) {
157 LOG(FATAL) << "destroying fde not created by fdevent_create(): " << dump_fde(fde);
158 }
159
Josh Gao2f6c2fa2018-09-20 17:38:55 -0700160 unique_fd result = std::move(fde->fd);
Yabin Cuia1080162015-09-04 16:19:56 -0700161 if (fde->state & FDE_ACTIVE) {
Josh Gao2f6c2fa2018-09-20 17:38:55 -0700162 g_poll_node_map.erase(result.get());
163
Yabin Cuia1080162015-09-04 16:19:56 -0700164 if (fde->state & FDE_PENDING) {
165 g_pending_list.remove(fde);
166 }
Yabin Cuia1080162015-09-04 16:19:56 -0700167 fde->state = 0;
168 fde->events = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800169 }
Josh Gao71f775a2018-05-14 11:14:33 -0700170
171 delete fde;
Josh Gao2f6c2fa2018-09-20 17:38:55 -0700172 return result;
173}
174
175void fdevent_destroy(fdevent* fde) {
176 // Release, and then let unique_fd's destructor cleanup.
177 fdevent_release(fde);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800178}
179
Yabin Cuia1080162015-09-04 16:19:56 -0700180static void fdevent_update(fdevent* fde, unsigned events) {
Josh Gao3b37fa22018-05-14 13:42:49 -0700181 auto it = g_poll_node_map.find(fde->fd.get());
Yabin Cuia1080162015-09-04 16:19:56 -0700182 CHECK(it != g_poll_node_map.end());
183 PollNode& node = it->second;
184 if (events & FDE_READ) {
185 node.pollfd.events |= POLLIN;
186 } else {
187 node.pollfd.events &= ~POLLIN;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800188 }
189
Yabin Cuia1080162015-09-04 16:19:56 -0700190 if (events & FDE_WRITE) {
191 node.pollfd.events |= POLLOUT;
192 } else {
193 node.pollfd.events &= ~POLLOUT;
194 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800195 fde->state = (fde->state & FDE_STATEMASK) | events;
Yabin Cuia1080162015-09-04 16:19:56 -0700196}
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800197
Yabin Cuia1080162015-09-04 16:19:56 -0700198void fdevent_set(fdevent* fde, unsigned events) {
Yabin Cuifbfa8402015-10-30 18:37:26 -0700199 check_main_thread();
Yabin Cuia1080162015-09-04 16:19:56 -0700200 events &= FDE_EVENTMASK;
201 if ((fde->state & FDE_EVENTMASK) == events) {
202 return;
203 }
Spencer Low888a7482015-09-29 18:33:38 -0700204 CHECK(fde->state & FDE_ACTIVE);
205 fdevent_update(fde, events);
206 D("fdevent_set: %s, events = %u", dump_fde(fde).c_str(), events);
Yabin Cuia1080162015-09-04 16:19:56 -0700207
Spencer Low888a7482015-09-29 18:33:38 -0700208 if (fde->state & FDE_PENDING) {
209 // If we are pending, make sure we don't signal an event that is no longer wanted.
210 fde->events &= events;
211 if (fde->events == 0) {
212 g_pending_list.remove(fde);
213 fde->state &= ~FDE_PENDING;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800214 }
215 }
216}
217
Yabin Cuia1080162015-09-04 16:19:56 -0700218void fdevent_add(fdevent* fde, unsigned events) {
Yabin Cuifbfa8402015-10-30 18:37:26 -0700219 check_main_thread();
Yabin Cuia1080162015-09-04 16:19:56 -0700220 fdevent_set(fde, (fde->state & FDE_EVENTMASK) | events);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800221}
222
Yabin Cuia1080162015-09-04 16:19:56 -0700223void fdevent_del(fdevent* fde, unsigned events) {
Yabin Cuifbfa8402015-10-30 18:37:26 -0700224 check_main_thread();
Yabin Cuia1080162015-09-04 16:19:56 -0700225 fdevent_set(fde, (fde->state & FDE_EVENTMASK) & ~events);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800226}
227
Josh Gao3777d2e2016-02-16 17:34:53 -0800228static std::string dump_pollfds(const std::vector<adb_pollfd>& pollfds) {
Yabin Cuia1080162015-09-04 16:19:56 -0700229 std::string result;
Elliott Hughes65fe2512015-10-07 15:59:35 -0700230 for (const auto& pollfd : pollfds) {
Yabin Cuia1080162015-09-04 16:19:56 -0700231 std::string op;
232 if (pollfd.events & POLLIN) {
233 op += "R";
234 }
235 if (pollfd.events & POLLOUT) {
236 op += "W";
237 }
238 android::base::StringAppendF(&result, " %d(%s)", pollfd.fd, op.c_str());
239 }
240 return result;
241}
242
243static void fdevent_process() {
Josh Gao3777d2e2016-02-16 17:34:53 -0800244 std::vector<adb_pollfd> pollfds;
Elliott Hughes65fe2512015-10-07 15:59:35 -0700245 for (const auto& pair : g_poll_node_map) {
246 pollfds.push_back(pair.second.pollfd);
Yabin Cuia1080162015-09-04 16:19:56 -0700247 }
248 CHECK_GT(pollfds.size(), 0u);
249 D("poll(), pollfds = %s", dump_pollfds(pollfds).c_str());
Josh Gao3777d2e2016-02-16 17:34:53 -0800250 int ret = adb_poll(&pollfds[0], pollfds.size(), -1);
Yabin Cuia1080162015-09-04 16:19:56 -0700251 if (ret == -1) {
Yabin Cuic1b1f6f2015-09-15 16:27:09 -0700252 PLOG(ERROR) << "poll(), ret = " << ret;
253 return;
Yabin Cuia1080162015-09-04 16:19:56 -0700254 }
Elliott Hughes65fe2512015-10-07 15:59:35 -0700255 for (const auto& pollfd : pollfds) {
Yabin Cuic1b1f6f2015-09-15 16:27:09 -0700256 if (pollfd.revents != 0) {
257 D("for fd %d, revents = %x", pollfd.fd, pollfd.revents);
258 }
Yabin Cuia1080162015-09-04 16:19:56 -0700259 unsigned events = 0;
260 if (pollfd.revents & POLLIN) {
261 events |= FDE_READ;
262 }
263 if (pollfd.revents & POLLOUT) {
264 events |= FDE_WRITE;
265 }
266 if (pollfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
267 // We fake a read, as the rest of the code assumes that errors will
268 // be detected at that point.
269 events |= FDE_READ | FDE_ERROR;
270 }
Yabin Cuiaa77e222015-09-29 12:25:33 -0700271#if defined(__linux__)
272 if (pollfd.revents & POLLRDHUP) {
273 events |= FDE_READ | FDE_ERROR;
274 }
275#endif
Yabin Cuia1080162015-09-04 16:19:56 -0700276 if (events != 0) {
277 auto it = g_poll_node_map.find(pollfd.fd);
278 CHECK(it != g_poll_node_map.end());
279 fdevent* fde = it->second.fde;
Josh Gao3b37fa22018-05-14 13:42:49 -0700280 CHECK_EQ(fde->fd.get(), pollfd.fd);
Yabin Cuia1080162015-09-04 16:19:56 -0700281 fde->events |= events;
282 D("%s got events %x", dump_fde(fde).c_str(), events);
283 fde->state |= FDE_PENDING;
284 g_pending_list.push_back(fde);
285 }
286 }
287}
288
Josh Gao4c936392017-05-03 14:10:39 -0700289static void fdevent_call_fdfunc(fdevent* fde) {
Yabin Cuia1080162015-09-04 16:19:56 -0700290 unsigned events = fde->events;
291 fde->events = 0;
Spencer Low888a7482015-09-29 18:33:38 -0700292 CHECK(fde->state & FDE_PENDING);
Yabin Cuia1080162015-09-04 16:19:56 -0700293 fde->state &= (~FDE_PENDING);
294 D("fdevent_call_fdfunc %s", dump_fde(fde).c_str());
Josh Gao3b37fa22018-05-14 13:42:49 -0700295 fde->func(fde->fd.get(), events, fde->arg);
Yabin Cuia1080162015-09-04 16:19:56 -0700296}
297
Josh Gaoe39ccd32018-02-23 14:37:07 -0800298static void fdevent_run_flush() EXCLUDES(run_queue_mutex) {
299 // We need to be careful around reentrancy here, since a function we call can queue up another
300 // function.
301 while (true) {
302 std::function<void()> fn;
303 {
304 std::lock_guard<std::mutex> lock(run_queue_mutex);
305 if (run_queue.empty()) {
306 break;
307 }
308 fn = run_queue.front();
309 run_queue.pop_front();
310 }
311 fn();
Josh Gao4c936392017-05-03 14:10:39 -0700312 }
Josh Gao4c936392017-05-03 14:10:39 -0700313}
314
315static void fdevent_run_func(int fd, unsigned ev, void* /* userdata */) {
316 CHECK_GE(fd, 0);
317 CHECK(ev & FDE_READ);
318
319 char buf[1024];
320
321 // Empty the fd.
322 if (adb_read(fd, buf, sizeof(buf)) == -1) {
323 PLOG(FATAL) << "failed to empty run queue notify fd";
324 }
325
Josh Gaofa30bf32018-03-29 16:23:43 -0700326 // Mark that we need to flush, and then run it at the end of fdevent_loop.
327 run_needs_flush = true;
Josh Gao4c936392017-05-03 14:10:39 -0700328}
329
330static void fdevent_run_setup() {
Josh Gaoe39ccd32018-02-23 14:37:07 -0800331 {
332 std::lock_guard<std::mutex> lock(run_queue_mutex);
333 CHECK(run_queue_notify_fd.get() == -1);
334 int s[2];
335 if (adb_socketpair(s) != 0) {
336 PLOG(FATAL) << "failed to create run queue notify socketpair";
337 }
Josh Gao4c936392017-05-03 14:10:39 -0700338
Josh Gao1222abc2018-03-19 15:19:45 -0700339 if (!set_file_block_mode(s[0], false) || !set_file_block_mode(s[1], false)) {
340 PLOG(FATAL) << "failed to make run queue notify socket nonblocking";
341 }
342
Josh Gaoe39ccd32018-02-23 14:37:07 -0800343 run_queue_notify_fd.reset(s[0]);
344 fdevent* fde = fdevent_create(s[1], fdevent_run_func, nullptr);
345 CHECK(fde != nullptr);
346 fdevent_add(fde, FDE_READ);
347 }
Josh Gao4c936392017-05-03 14:10:39 -0700348
349 fdevent_run_flush();
350}
351
352void fdevent_run_on_main_thread(std::function<void()> fn) {
353 std::lock_guard<std::mutex> lock(run_queue_mutex);
354 run_queue.push_back(std::move(fn));
355
356 // run_queue_notify_fd could still be -1 if we're called before fdevent has finished setting up.
357 // In that case, rely on the setup code to flush the queue without a notification being needed.
358 if (run_queue_notify_fd != -1) {
Josh Gao1222abc2018-03-19 15:19:45 -0700359 int rc = adb_write(run_queue_notify_fd.get(), "", 1);
360
361 // It's possible that we get EAGAIN here, if lots of notifications came in while handling.
362 if (rc == 0) {
363 PLOG(FATAL) << "run queue notify fd was closed?";
364 } else if (rc == -1 && errno != EAGAIN) {
Josh Gao4c936392017-05-03 14:10:39 -0700365 PLOG(FATAL) << "failed to write to run queue notify fd";
366 }
367 }
368}
369
370void fdevent_loop() {
Yabin Cuifbfa8402015-10-30 18:37:26 -0700371 set_main_thread();
Josh Gao4c936392017-05-03 14:10:39 -0700372 fdevent_run_setup();
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200373
Elliott Hughesaa245492015-08-03 10:38:08 -0700374 while (true) {
Josh Gao022d4472016-02-10 14:49:00 -0800375 if (terminate_loop) {
376 return;
377 }
378
Yabin Cuia1080162015-09-04 16:19:56 -0700379 D("--- --- waiting for events");
JP Abgrall408fa572011-03-16 15:57:42 -0700380
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800381 fdevent_process();
David 'Digit' Turnerf6330a22009-05-18 17:36:28 +0200382
Yabin Cuia1080162015-09-04 16:19:56 -0700383 while (!g_pending_list.empty()) {
384 fdevent* fde = g_pending_list.front();
385 g_pending_list.pop_front();
JP Abgrall408fa572011-03-16 15:57:42 -0700386 fdevent_call_fdfunc(fde);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800387 }
Josh Gaofa30bf32018-03-29 16:23:43 -0700388
389 if (run_needs_flush) {
390 fdevent_run_flush();
391 run_needs_flush = false;
392 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800393 }
394}
Yabin Cuic1b1f6f2015-09-15 16:27:09 -0700395
Josh Gao022d4472016-02-10 14:49:00 -0800396void fdevent_terminate_loop() {
397 terminate_loop = true;
398}
399
Yabin Cuic1b1f6f2015-09-15 16:27:09 -0700400size_t fdevent_installed_count() {
401 return g_poll_node_map.size();
402}
403
404void fdevent_reset() {
405 g_poll_node_map.clear();
406 g_pending_list.clear();
Josh Gao4c936392017-05-03 14:10:39 -0700407
408 std::lock_guard<std::mutex> lock(run_queue_mutex);
409 run_queue_notify_fd.reset();
410 run_queue.clear();
411
Yabin Cuifbfa8402015-10-30 18:37:26 -0700412 main_thread_valid = false;
Josh Gao022d4472016-02-10 14:49:00 -0800413 terminate_loop = false;
Yabin Cuic1b1f6f2015-09-15 16:27:09 -0700414}