Bug 1466609: Make the threadsafe refcounting macros more reusable. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 04 Jun 2018 19:53:45 +0200
changeset 421571 4607eea0048d5bdba9de9a1b781d47eb5ff7b6c2
parent 421570 9889304ebdea753a8408d1e1ab192ee764520da0
child 421572 f7785e8b50025722da7b2b082d93c1e7c85ff931
push id34098
push usernbeleuzu@mozilla.com
push dateWed, 06 Jun 2018 17:00:32 +0000
treeherdermozilla-central@04cc917f68c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1466609
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466609: Make the threadsafe refcounting macros more reusable. r=xidorn MozReview-Commit-ID: IanxqRksGqE
servo/components/style/gecko_bindings/sugar/refptr.rs
--- a/servo/components/style/gecko_bindings/sugar/refptr.rs
+++ b/servo/components/style/gecko_bindings/sugar/refptr.rs
@@ -1,15 +1,15 @@
 /* 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/. */
 
 //! 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 servo_arc::Arc;
 use std::{fmt, mem, ptr};
 use std::marker::PhantomData;
 use std::ops::{Deref, DerefMut};
 
 /// Trait for all objects that have Addref() and Release
 /// methods and can be placed inside RefPtr<T>
@@ -250,71 +250,73 @@ impl<T: RefCounted> PartialEq for RefPtr
         self.ptr == other.ptr
     }
 }
 
 unsafe impl<T: ThreadSafeRefCounted> Send for RefPtr<T> {}
 unsafe impl<T: ThreadSafeRefCounted> Sync for RefPtr<T> {}
 
 macro_rules! impl_refcount {
-    ($t:ty, $addref:ident, $release:ident) => {
+    ($t:ty, $addref:path, $release:path) => {
         unsafe impl RefCounted for $t {
+            #[inline]
             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) {
-                ::gecko_bindings::bindings::$release(self as *const _ as *mut _)
+                $release(self as *const _ as *mut _)
             }
         }
     };
 }
 
 // Companion of NS_DECL_THREADSAFE_FFI_REFCOUNTING.
 //
 // Gets you a free RefCounted impl implemented via FFI.
 macro_rules! impl_threadsafe_refcount {
-    ($t:ty, $addref:ident, $release:ident) => {
+    ($t:ty, $addref:path, $release:path) => {
         impl_refcount!($t, $addref, $release);
         unsafe impl ThreadSafeRefCounted for $t {}
     };
 }
 
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::RawGeckoURLExtraData,
-    Gecko_AddRefURLExtraDataArbitraryThread,
-    Gecko_ReleaseURLExtraDataArbitraryThread
+    structs::RawGeckoURLExtraData,
+    bindings::Gecko_AddRefURLExtraDataArbitraryThread,
+    bindings::Gecko_ReleaseURLExtraDataArbitraryThread
 );
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::nsStyleQuoteValues,
-    Gecko_AddRefQuoteValuesArbitraryThread,
-    Gecko_ReleaseQuoteValuesArbitraryThread
+    structs::nsStyleQuoteValues,
+    bindings::Gecko_AddRefQuoteValuesArbitraryThread,
+    bindings::Gecko_ReleaseQuoteValuesArbitraryThread
 );
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::nsCSSValueSharedList,
-    Gecko_AddRefCSSValueSharedListArbitraryThread,
-    Gecko_ReleaseCSSValueSharedListArbitraryThread
+    structs::nsCSSValueSharedList,
+    bindings::Gecko_AddRefCSSValueSharedListArbitraryThread,
+    bindings::Gecko_ReleaseCSSValueSharedListArbitraryThread
 );
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::mozilla::css::URLValue,
-    Gecko_AddRefCSSURLValueArbitraryThread,
-    Gecko_ReleaseCSSURLValueArbitraryThread
+    structs::mozilla::css::URLValue,
+    bindings::Gecko_AddRefCSSURLValueArbitraryThread,
+    bindings::Gecko_ReleaseCSSURLValueArbitraryThread
 );
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::mozilla::css::GridTemplateAreasValue,
-    Gecko_AddRefGridTemplateAreasValueArbitraryThread,
-    Gecko_ReleaseGridTemplateAreasValueArbitraryThread
+    structs::mozilla::css::GridTemplateAreasValue,
+    bindings::Gecko_AddRefGridTemplateAreasValueArbitraryThread,
+    bindings::Gecko_ReleaseGridTemplateAreasValueArbitraryThread
 );
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::ImageValue,
-    Gecko_AddRefImageValueArbitraryThread,
-    Gecko_ReleaseImageValueArbitraryThread
+    structs::ImageValue,
+    bindings::Gecko_AddRefImageValueArbitraryThread,
+    bindings::Gecko_ReleaseImageValueArbitraryThread
 );
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::SharedFontList,
-    Gecko_AddRefSharedFontListArbitraryThread,
-    Gecko_ReleaseSharedFontListArbitraryThread
+    structs::SharedFontList,
+    bindings::Gecko_AddRefSharedFontListArbitraryThread,
+    bindings::Gecko_ReleaseSharedFontListArbitraryThread
 );
-
 impl_threadsafe_refcount!(
-    ::gecko_bindings::structs::SheetLoadDataHolder,
-    Gecko_AddRefSheetLoadDataHolderArbitraryThread,
-    Gecko_ReleaseSheetLoadDataHolderArbitraryThread
+    structs::SheetLoadDataHolder,
+    bindings::Gecko_AddRefSheetLoadDataHolderArbitraryThread,
+    bindings::Gecko_ReleaseSheetLoadDataHolderArbitraryThread
 );