-
Notifications
You must be signed in to change notification settings - Fork 0
Thread Safe Sink Design
Danny Peck edited this page Oct 25, 2017
·
2 revisions
ThreadSafeSink design:
- The thread safe sink will act as the Base class for defining custom Thread Safe Sinks.
- The thread safe sink will inherit from BasicSink and override the BasicSink's input stream operator to perform unique write locking.
- The thread safe sink will be interchangeable anywhere where a BasicSink is expected.
ThreadSafeProxySink design:
- The thread safe proxy sink will be parameterized by a BasicSink and will perform synchronized forwarding of output requests to the interior Sink.
- Upon construction, the proxy sink will take ownership of the interior Sink, this implies that all Sink's must be moveable.
- The ThreadSafeProxySink will inherit from ThreadSafeSink in order to emulate the interface of the parameterizing Sink while supplying the ability to synchronize the output. This also allows the ThreadSafeProxySink to be used within interfaces expecting ThreadSafeSinks.
Passing a non-thread-safe sink into a ThreadSafeProxySink => A ThreadSafeProxySink synchronizes use of the BasicSink. Passing a thread-safe sink into a ThreadSafeProxySink => A ThreadSafeProxySink synchronizes use of the ThreadSafeSink, which synchronizes itself. So you could wish to synchronize the use of already synchronized sinks in an attempt to form some complex aggregation of sink usage. In the spirit of not assuming the complexity of potential use cases, we will currently not attempt to ensure that locking only occurs once if you pass an already thread-safe sink to a thread-safe proxy sink.
Namespacing and usage: Building blocks:
- Toolbox::Sink::BasicSink<OutputType>
- Toolbox::Sink::ThreadSafeSink<OutputType>
- Toolbox::Sink::ThreadSafeProxySink<SinkType>
Freebees:
- Toolbox::Sink::ConsoleSink : ThreadSafeSink<std::string>
- Toolbox::Sink::FileSink : ThreadSafeSink<std::string>