mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 20:30:41 +00:00

This commit adds `ThreadPtr{Handle, Holder}` to wrap an `XpCom` object with thread-safe refcounting. These are analagous to `nsMainThreadPtr{Handle, Holder}`, but can hold references to objects from any thread, not just the main thread. `ThreadPtrHolder` is similar to `ThreadBoundRefPtr`. However, it's not possible to clone a `ThreadBoundRefPtr`, so it can't be shared among tasks. This is fine for objects that are only used once, like callbacks. However, `ThreadBoundRefPtr` doesn't work well for loggers or event emitters, which might need to be called multiple times on the owning thread. Unlike a `ThreadBoundRefPtr`, it's allowed and expected to clone and drop a `ThreadPtrHolder` on other threads. Internally, the holder keeps an atomic refcount, and releases the wrapped object on the owning thread once the count reaches zero. This commit also changes `TaskRunnable` to support dispatching from threads other than the main thread. Differential Revision: https://phabricator.services.mozilla.com/D20074 --HG-- extra : moz-landing-system : lando