================
@@ -60,9 +61,14 @@ class LogLine {
};
class AtomicLineLogger {
- int FD = -1;
+ std::atomic<int> FD{-1};
std::string LogPath;
std::atomic<uint64_t> DroppedLines{0};
+ std::mutex EnableMtx;
+ bool EnabledAtConstruction = false;
+ bool CommittedByFlag = false;
----------------
cyndyishida wrote:
nit: The naming and usage of these bools feel a bit confusing to me, since they
actually represent the state of how the input log path was set to determine
what errors should be emitted.
Why not hold a ternary state?
e.g.
```
- bool EnabledAtConstruction = false;
- bool CommittedByFlag = false;
+ enum class LogPathSource { None, ServiceOptions, ScanFlag };
+ LogPathSource PathSource = LogPathSource::None;
...
@@ -117,22 +117,27 @@ void AtomicLineLogger::initialize(StringRef LogFilePath) {
AtomicLineLogger::AtomicLineLogger(StringRef LogFilePath) {
if (LogFilePath.empty())
return;
+ PathSource = LogPathSource::ServiceOptions;
initialize(LogFilePath);
- EnabledAtConstruction = true;
}
...
bool AtomicLineLogger::enable(StringRef RequestedLogPath) {
std::lock_guard<std::mutex> Lock(EnableMtx);
- if (EnabledAtConstruction)
- return RequestedLogPath.empty() || RequestedLogPath == LogPath;
-
- if (!CommittedByFlag) {
- CommittedByFlag = true;
+ switch (PathSource) {
+ case LogPathSource::None:
+ // The first request to log.
+ PathSource = LogPathSource::ScanFlag;
if (!RequestedLogPath.empty())
initialize(RequestedLogPath);
return true;
+ case LogPathSource::ServiceOptions:
+ // The path is already committed, only verify it matches.
+ return RequestedLogPath.empty() || RequestedLogPath == LogPath;
+ case LogPathSource::ScanFlag:
+ // The path is already committed, only verify it matches.
+ return RequestedLogPath == LogPath;
}
- return RequestedLogPath == LogPath;
+ llvm_unreachable("unhandled LogPathSource");
}
```
Checked this passed all the tests for me locally.
https://github.com/llvm/llvm-project/pull/211966
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits