MengRao / fmtlog

fmtlog is a performant fmtlib-style logging library with latency in nanoseconds.
MIT License
807 stars 124 forks source link

FMTLOG_BLOCK那个循环, 不会跳出来啊? #25

Closed JaydenFish closed 2 years ago

JaydenFish commented 2 years ago

里面只有continue,没有break和return. 死循环吧? 我一运行程序就卡住了.

MengRao commented 2 years ago

如果设置了FMTLOG_BLOCK则log writer会等到入队列成功才返回,如果没有其他线程poll的话确实会死循环。所以单线程程序不应该设置FMTLOG_BLOCK,这样队列满了直接丢弃并返回。

gh-andre commented 2 years ago

Please correct me if I'm wrong, but it seems that the OP is correct. If header is not a null pointer, then data is formatted using this header and after header->push(alloc_size) is called, the loop continues until the queue is full and then it starts looping via continue.

    do {
      auto header = threadBuffer->varq.allocMsg(alloc_size);
      if (!header) continue;
      header->logId = logId;
      char* out = (char*)(header + 1);
      // ...
      encodeArgs<0>(cstringSizes, out, std::forward<Args>(args)...);
      header->push(alloc_size);
    } while (1);

Am I missing something?

MengRao commented 2 years ago

Sorry, I made a mistake in previous revision, fixed now. Thanks for notifying me.