Skip to content

Commit

Permalink
[NFC] Extend TDirectoryAtomicAdapter comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pcanal committed Jan 20, 2023
1 parent 58b00f5 commit 8199acd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions core/base/inc/TDirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,30 @@ can be replaced with the simpler and exception safe:

namespace ROOT {
namespace Internal {
// The objects of type TDirectoryAtomicAdapter should only be used inside the
// thread that created them. The intent is for this to be used (indirectly) solely as
// temporary objects. For example:
//
// gDirectory = newvalue;
// gDirectory->ls();
// TDirectory *current = gDirectory;
//
// Note that:
// auto dir = gDirectory;
// currently behaves "unexpectedly" as changing dir will change gDirectory:
// dir = newvalue;
// leads to
// gDirectory == newvalue
// To prevent this we would need a new mechanism such that the type
// used by 'auto' in that case is `TDirectory*` rather than the Internal
// type TDirectoryAtomicAdapter.
struct TDirectoryAtomicAdapter {
// The shared pointer's lifetime is that of the thread creating this object
// (with the default constructor)
TDirectory::SharedGDirectory_t &fValue;

TDirectoryAtomicAdapter() : fValue(TDirectory::GetSharedLocalCurrentDirectory()) {}

TDirectoryAtomicAdapter(TDirectory::SharedGDirectory_t &value) : fValue(value) {}

template <typename T>
explicit operator T*() const {
return (T *)fValue->load();
Expand Down

0 comments on commit 8199acd

Please sign in to comment.