| 353 | bool stopped = false; |
| 354 | |
| 355 | AsyncLogOutput(ILogOutput* output) : log_output(output) { |
| 356 | background = std::thread([&] { |
| 357 | auto log_file_fd = log_output->get_log_file_fd(); |
| 358 | auto wb = [this, log_file_fd] { |
| 359 | iovec iov; |
| 360 | while (pending.pop(iov)) { |
| 361 | log_output->write(log_file_fd, (char*)iov.iov_base, (char*)iov.iov_base + iov.iov_len); |
| 362 | delete[] (char*)iov.iov_base; |
| 363 | } |
| 364 | }; |
| 365 | while (!stopped) { |
| 366 | uint64_t interval = 1000UL; |
| 367 | if (!pending.empty()) { |
| 368 | interval = 100UL; |
| 369 | wb(); |
| 370 | } |
| 371 | std::unique_lock<std::mutex> l(mt); |
| 372 | if (!stopped) cv.wait_for(l, std::chrono::milliseconds(interval)); |
| 373 | } |
| 374 | if (!pending.empty()) wb(); |
| 375 | }); |
| 376 | } |
| 377 | |
| 378 | void write(int, const char* begin, const char* end) override { |
| 379 | uint64_t length = end - begin; |