MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / AsyncLogOutput

Method AsyncLogOutput

common/alog.cpp:355–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 6

threadClass · 0.70
get_log_file_fdMethod · 0.45
popMethod · 0.45
writeMethod · 0.45
emptyMethod · 0.45
wait_forMethod · 0.45

Tested by

no test coverage detected