mirror of
https://github.com/servo/servo.git
synced 2025-07-04 14:03:39 +01:00
style: Make the threadsafe refcounting macros more reusable.
Bug: 1466609 Reviewed-by: xidorn MozReview-Commit-ID: IanxqRksGqE
This commit is contained in:
parent
2c0a19e517
commit
d461a7ddbe
1 changed files with 32 additions and 30 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
//! A rust helper to ease the use of Gecko's refcounted types.
|
//! A rust helper to ease the use of Gecko's refcounted types.
|
||||||
|
|
||||||
use gecko_bindings::structs;
|
use gecko_bindings::{structs, bindings};
|
||||||
use gecko_bindings::sugar::ownership::HasArcFFI;
|
use gecko_bindings::sugar::ownership::HasArcFFI;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use std::{fmt, mem, ptr};
|
use std::{fmt, mem, ptr};
|
||||||
|
@ -255,13 +255,16 @@ unsafe impl<T: ThreadSafeRefCounted> Send for RefPtr<T> {}
|
||||||
unsafe impl<T: ThreadSafeRefCounted> Sync for RefPtr<T> {}
|
unsafe impl<T: ThreadSafeRefCounted> Sync for RefPtr<T> {}
|
||||||
|
|
||||||
macro_rules! impl_refcount {
|
macro_rules! impl_refcount {
|
||||||
($t:ty, $addref:ident, $release:ident) => {
|
($t:ty, $addref:path, $release:path) => {
|
||||||
unsafe impl RefCounted for $t {
|
unsafe impl RefCounted for $t {
|
||||||
|
#[inline]
|
||||||
fn addref(&self) {
|
fn addref(&self) {
|
||||||
unsafe { ::gecko_bindings::bindings::$addref(self as *const _ as *mut _) }
|
unsafe { $addref(self as *const _ as *mut _) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
unsafe fn release(&self) {
|
unsafe fn release(&self) {
|
||||||
::gecko_bindings::bindings::$release(self as *const _ as *mut _)
|
$release(self as *const _ as *mut _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -271,50 +274,49 @@ macro_rules! impl_refcount {
|
||||||
//
|
//
|
||||||
// Gets you a free RefCounted impl implemented via FFI.
|
// Gets you a free RefCounted impl implemented via FFI.
|
||||||
macro_rules! impl_threadsafe_refcount {
|
macro_rules! impl_threadsafe_refcount {
|
||||||
($t:ty, $addref:ident, $release:ident) => {
|
($t:ty, $addref:path, $release:path) => {
|
||||||
impl_refcount!($t, $addref, $release);
|
impl_refcount!($t, $addref, $release);
|
||||||
unsafe impl ThreadSafeRefCounted for $t {}
|
unsafe impl ThreadSafeRefCounted for $t {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::RawGeckoURLExtraData,
|
structs::RawGeckoURLExtraData,
|
||||||
Gecko_AddRefURLExtraDataArbitraryThread,
|
bindings::Gecko_AddRefURLExtraDataArbitraryThread,
|
||||||
Gecko_ReleaseURLExtraDataArbitraryThread
|
bindings::Gecko_ReleaseURLExtraDataArbitraryThread
|
||||||
);
|
);
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::nsStyleQuoteValues,
|
structs::nsStyleQuoteValues,
|
||||||
Gecko_AddRefQuoteValuesArbitraryThread,
|
bindings::Gecko_AddRefQuoteValuesArbitraryThread,
|
||||||
Gecko_ReleaseQuoteValuesArbitraryThread
|
bindings::Gecko_ReleaseQuoteValuesArbitraryThread
|
||||||
);
|
);
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::nsCSSValueSharedList,
|
structs::nsCSSValueSharedList,
|
||||||
Gecko_AddRefCSSValueSharedListArbitraryThread,
|
bindings::Gecko_AddRefCSSValueSharedListArbitraryThread,
|
||||||
Gecko_ReleaseCSSValueSharedListArbitraryThread
|
bindings::Gecko_ReleaseCSSValueSharedListArbitraryThread
|
||||||
);
|
);
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::mozilla::css::URLValue,
|
structs::mozilla::css::URLValue,
|
||||||
Gecko_AddRefCSSURLValueArbitraryThread,
|
bindings::Gecko_AddRefCSSURLValueArbitraryThread,
|
||||||
Gecko_ReleaseCSSURLValueArbitraryThread
|
bindings::Gecko_ReleaseCSSURLValueArbitraryThread
|
||||||
);
|
);
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::mozilla::css::GridTemplateAreasValue,
|
structs::mozilla::css::GridTemplateAreasValue,
|
||||||
Gecko_AddRefGridTemplateAreasValueArbitraryThread,
|
bindings::Gecko_AddRefGridTemplateAreasValueArbitraryThread,
|
||||||
Gecko_ReleaseGridTemplateAreasValueArbitraryThread
|
bindings::Gecko_ReleaseGridTemplateAreasValueArbitraryThread
|
||||||
);
|
);
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::ImageValue,
|
structs::ImageValue,
|
||||||
Gecko_AddRefImageValueArbitraryThread,
|
bindings::Gecko_AddRefImageValueArbitraryThread,
|
||||||
Gecko_ReleaseImageValueArbitraryThread
|
bindings::Gecko_ReleaseImageValueArbitraryThread
|
||||||
);
|
);
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::SharedFontList,
|
structs::SharedFontList,
|
||||||
Gecko_AddRefSharedFontListArbitraryThread,
|
bindings::Gecko_AddRefSharedFontListArbitraryThread,
|
||||||
Gecko_ReleaseSharedFontListArbitraryThread
|
bindings::Gecko_ReleaseSharedFontListArbitraryThread
|
||||||
);
|
);
|
||||||
|
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
::gecko_bindings::structs::SheetLoadDataHolder,
|
structs::SheetLoadDataHolder,
|
||||||
Gecko_AddRefSheetLoadDataHolderArbitraryThread,
|
bindings::Gecko_AddRefSheetLoadDataHolderArbitraryThread,
|
||||||
Gecko_ReleaseSheetLoadDataHolderArbitraryThread
|
bindings::Gecko_ReleaseSheetLoadDataHolderArbitraryThread
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue