Commit fe16a5e7 by Andy Getzendanner Committed by Copybara-Service

Add protected copy ctor+assign to absl::LogSink, and clarify thread-safety…

Add protected copy ctor+assign to absl::LogSink, and clarify thread-safety requirements to apply to the interface methods.

PiperOrigin-RevId: 599266310
Change-Id: I3b5a91eb17b4b09feba5e048892875f3a747afb1
parent 10f3e611
...@@ -32,15 +32,16 @@ ABSL_NAMESPACE_BEGIN ...@@ -32,15 +32,16 @@ ABSL_NAMESPACE_BEGIN
// `absl::LogSink` is an interface which can be extended to intercept and // `absl::LogSink` is an interface which can be extended to intercept and
// process particular messages (with `LOG.ToSinkOnly()` or // process particular messages (with `LOG.ToSinkOnly()` or
// `LOG.ToSinkAlso()`) or all messages (if registered with // `LOG.ToSinkAlso()`) or all messages (if registered with
// `absl::AddLogSink`). Implementations must be thread-safe, and should take // `absl::AddLogSink`). Implementations must not take any locks that might be
// care not to take any locks that might be held by the `LOG` caller. // held by the `LOG` caller.
class LogSink { class LogSink {
public: public:
virtual ~LogSink() = default; virtual ~LogSink() = default;
// LogSink::Send() // LogSink::Send()
// //
// `Send` is called synchronously during the log statement. // `Send` is called synchronously during the log statement. `Send` must be
// thread-safe.
// //
// It is safe to use `LOG` within an implementation of `Send`. `ToSinkOnly` // It is safe to use `LOG` within an implementation of `Send`. `ToSinkOnly`
// and `ToSinkAlso` are safe in general but can be used to create an infinite // and `ToSinkAlso` are safe in general but can be used to create an infinite
...@@ -50,9 +51,15 @@ class LogSink { ...@@ -50,9 +51,15 @@ class LogSink {
// LogSink::Flush() // LogSink::Flush()
// //
// Sinks that buffer messages should override this method to flush the buffer // Sinks that buffer messages should override this method to flush the buffer
// and return. // and return. `Flush` must be thread-safe.
virtual void Flush() {} virtual void Flush() {}
protected:
LogSink() = default;
// Implementations may be copyable and/or movable.
LogSink(const LogSink&) = default;
LogSink& operator=(const LogSink&) = default;
private: private:
// https://lld.llvm.org/missingkeyfunction.html#missing-key-function // https://lld.llvm.org/missingkeyfunction.html#missing-key-function
virtual void KeyFunction() const final; // NOLINT(readability/inheritance) virtual void KeyFunction() const final; // NOLINT(readability/inheritance)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment