Restrict `moz_task::ThreadPtrHolder` to main-thread only
Categories
(Core :: XPCOM, task)
Tracking
()
People
(Reporter: lina, Unassigned)
Details
(Keywords: good-first-bug)
Back when bug 1482608 added ThreadPtrHolder for Rust, I had its constructor call get_current_thread, so that it could be bound to the thread that created it, not just the main thread.
That was important in an early version of the bookmark sync code, but the code that used it is long gone. In fact, creating a ThreadPtrHolder in a runnable on a background thread queue might be a footgun, if that queue schedules its runnables on multiple threads—as bug 1584568, comment 5 hints at.
Since we only ever create ThreadPtrHolders on the main thread (just like its C++ cousin), let's rename it to MainThreadPtrHolder, remove ThreadPtrHolder::owning_thread, and make it main-thread only. It'll match C++, and remove a level of indirection that gets in the way.
Comment 1•6 months ago
|
||
The premise still holds. Five years on:
ThreadPtrHolderis unchanged atxpcom/rust/moz_task/src/lib.rs:317, still has theowning_thread: RefPtr<nsIThread>field.- There is exactly one consumer left:
toolkit/components/places/bookmark_sync/src/merger.rs:117,125. It wraps the callback inMergeTask::new, called from the XPCOM-exposedMerge()method (line 73) before dispatch to the async DB thread — i.e. the only live use already matches the "main-thread only" restriction lina proposed.
Scope seems small: rename to MainThreadPtrHolder (matching C++ nsMainThreadPtrHolder), drop owning_thread in favour of a main-thread getter, add a main-thread assert in the constructor, update the one caller.
Description
•