/// be created when it is referenced for the first
/// time.
/// See the NestedDiagnosticContext class for an
/// example how to use this template.
/// Every thread only has access to its own
/// thread local data. There is no way for a thread
/// to access another thread's local data.
{
typedef TLSSlot
public:
ThreadLocal()
{
}
~ThreadLocal()
{
}
C* operator -> ()
{
return &get();
}
C& operator * ()
/// "Dereferences" the smart pointer and returns a reference
/// to the underlying data object. The reference can be used
/// to modify the object.
{
return get();
}
C& get()
/// Returns a reference to the underlying data object.
/// The reference can be used to modify the object.
{
TLSAbstractSlot*& p = ThreadLocalStorage::current().get(this);
if (!p) p = new Slot;
return static_cast
}
private:
ThreadLocal(const ThreadLocal&);
ThreadLocal& operator = (const ThreadLocal&);
};
到这里Poco中所有的NDC流程都被打通了,用户终于可以实现按线程打印日志信息了。