2016-06-30 01:56:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsProxyRelease.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
2017-06-13 13:10:13 +03:00
|
|
|
/* static */ void ProxyReleaseChooser<true>::ProxyReleaseISupports(
|
|
|
|
const char* aName, nsIEventTarget* aTarget, nsISupports* aDoomed,
|
2016-06-30 01:56:41 +03:00
|
|
|
bool aAlwaysProxy) {
|
2017-06-13 13:10:13 +03:00
|
|
|
::detail::ProxyRelease<nsISupports>(aName, aTarget, dont_AddRef(aDoomed),
|
2016-06-30 01:56:41 +03:00
|
|
|
aAlwaysProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace detail
|
Bug 1482608 - Add owning thread pointer holders for Rust code. r=nika,myk
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
2019-03-25 07:49:24 +03:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
// This function uses C linkage because it's exposed to Rust to support the
|
|
|
|
// `ThreadPtrHolder` wrapper in the `moz_task` crate.
|
|
|
|
void NS_ProxyReleaseISupports(const char* aName, nsIEventTarget* aTarget,
|
|
|
|
nsISupports* aDoomed, bool aAlwaysProxy) {
|
|
|
|
NS_ProxyRelease(aName, aTarget, dont_AddRef(aDoomed), aAlwaysProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|