File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -470,11 +470,19 @@ class Thread : public std::enable_shared_from_this<Thread>,
470470
471471 virtual void ClearStackFrames ();
472472
473- // / Derived classes implementing SetBackingThread should use this to provide
474- // / bidirectional access to the Backing-Backed relationship.
473+ // / Sets the thread that is backed by this thread.
474+ // / If backed_thread.GetBackedThread() is null, this method also calls
475+ // / backed_thread.SetBackedThread(this).
476+ // / If backed_thread.GetBackedThread() is non-null, asserts that it is equal
477+ // / to `this`.
475478 void SetBackedThread (Thread &backed_thread) {
476- assert (backed_thread.GetBackingThread ().get () == this );
477479 m_backed_thread = backed_thread.shared_from_this ();
480+
481+ // Ensure the bidrectional relationship is preserved.
482+ Thread *backing_thread = backed_thread.GetBackingThread ().get ();
483+ assert (backing_thread == nullptr || backing_thread == this );
484+ if (backing_thread == nullptr )
485+ backed_thread.SetBackingThread (shared_from_this ());
478486 }
479487
480488 void ClearBackedThread () { m_backed_thread.reset (); }
You can’t perform that action at this time.
0 commit comments