Skip to content

Redesign SharedSingleton<T>: explicit Get/Install/Reset and thread safety #119

Description

@gagelarsen

Follow-up from issue #116 (review finding #9).

xmscore/misc/Singleton.h:81-121SharedSingleton<T>::Instance(Ptr a_new = Ptr(), bool a_delete = false) has the same conflated get/install/destroy shape as Singleton<T> (#116-followup-singleton), plus:

  • A second installer call silently clobbers the first. The precondition assert is commented out.
  • No documented thread-safety expectations; concurrent first-time installs race.

Proposed change

  • Replace with explicit methods:
    • Get() — returns the current shared_ptr.
    • Install(Ptr) — install a replacement; either fail loudly on a second install or document the policy.
    • Reset() — tear down.
  • Either guard install with std::call_once / a std::mutex, or document explicitly that callers are responsible for serializing installs.
  • Document interaction with in-flight users of the previous instance.

Why follow-up, not part of #117

The new \brief in #117 names this type as the canonical CRTP base for xmscore singletons. The actual fix needs its own type-design review.

Acceptance

  • Get() / Install() / Reset() exist; combined Instance(Ptr, bool) marked deprecated
  • Second Install() either errors loudly or is documented as last-write-wins
  • Thread-safety policy documented and (where claimed) enforced
  • Foundation singletons (XmLog, ProgressListener) audited against the new shape

Refs: issue #116, PR #117.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions