Bug 865583 - Use thread-safe ref-counting in the linker. r=nfroyd
authorMike Hommey <mh+mozilla@glandium.org>
Sat, 18 May 2013 09:53:18 +0200
changeset 132305 68ec60cf14a9f5c635eb4cd9e36bf27534094d51
parent 132304 5ff5c972e3af55bd1190d1418f6634e665213dbc
child 132306 013863871e614a5d366916d3fd588cbd84c1ef6a
push id24693
push userphilringnalda@gmail.com
push dateSun, 19 May 2013 01:08:22 +0000
treeherdermozilla-central@317fe0f314ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs865583
milestone24.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 865583 - Use thread-safe ref-counting in the linker. r=nfroyd
mozglue/linker/ElfLoader.h
mozglue/linker/Zip.h
--- a/mozglue/linker/ElfLoader.h
+++ b/mozglue/linker/ElfLoader.h
@@ -65,34 +65,34 @@ MFBT_API void
  * RefCounted<LibHandle>::Release to support some reentrancy. See further
  * below.
  */
 class LibHandle;
 
 namespace mozilla {
 namespace detail {
 
-template <> inline void RefCounted<LibHandle, NonAtomicRefCount>::Release();
+template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release();
 
-template <> inline RefCounted<LibHandle, NonAtomicRefCount>::~RefCounted()
+template <> inline RefCounted<LibHandle, AtomicRefCount>::~RefCounted()
 {
   MOZ_ASSERT(refCnt == 0x7fffdead);
 }
 
 } /* namespace detail */
 } /* namespace mozilla */
 
 /* Forward declaration */
 class Mappable;
 
 /**
  * Abstract class for loaded libraries. Libraries may be loaded through the
  * system linker or this linker, both cases will be derived from this class.
  */
-class LibHandle: public mozilla::RefCounted<LibHandle>
+class LibHandle: public mozilla::AtomicRefCounted<LibHandle>
 {
 public:
   /**
    * Constructor. Takes the path of the loaded library and will store a copy
    * of the leaf name.
    */
   LibHandle(const char *path)
   : directRefCnt(0), path(path ? strdup(path) : NULL), mappable(NULL) { }
@@ -133,31 +133,32 @@ public:
    * Library handles can be referenced from other library handles or
    * externally (when dlopen()ing using this linker). We need to be
    * able to distinguish between the two kind of referencing for better
    * bookkeeping.
    */
   void AddDirectRef()
   {
     ++directRefCnt;
-    mozilla::RefCounted<LibHandle>::AddRef();
+    mozilla::AtomicRefCounted<LibHandle>::AddRef();
   }
 
   /**
    * Releases a direct reference, and returns whether there are any direct
    * references left.
    */
   bool ReleaseDirectRef()
   {
     bool ret = false;
     if (directRefCnt) {
-      MOZ_ASSERT(directRefCnt <= mozilla::RefCounted<LibHandle>::refCount());
+      MOZ_ASSERT(directRefCnt <=
+                 mozilla::AtomicRefCounted<LibHandle>::refCount());
       if (--directRefCnt)
         ret = true;
-      mozilla::RefCounted<LibHandle>::Release();
+      mozilla::AtomicRefCounted<LibHandle>::Release();
     }
     return ret;
   }
 
   /**
    * Returns the number of direct references
    */
   int DirectRefCount()
@@ -212,17 +213,17 @@ private:
  * to 1 on normal builds, and 0x7fffdead on debug builds so that the LibHandle
  * can still be referenced while the destructor is executing. The refCnt is
  * allowed to grow > 0x7fffdead, but not to decrease under that value, which
  * would mean too many Releases from within the destructor.
  */
 namespace mozilla {
 namespace detail {
 
-template <> inline void RefCounted<LibHandle, NonAtomicRefCount>::Release() {
+template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release() {
 #ifdef DEBUG
   if (refCnt > 0x7fff0000)
     MOZ_ASSERT(refCnt > 0x7fffdead);
 #endif
   MOZ_ASSERT(refCnt > 0);
   if (refCnt > 0) {
     if (0 == --refCnt) {
 #ifdef DEBUG
--- a/mozglue/linker/Zip.h
+++ b/mozglue/linker/Zip.h
@@ -21,17 +21,17 @@ class ZipCollection;
  * Class to handle access to Zip archive streams. The Zip archive is mapped
  * in memory, and streams are direct references to that mapped memory.
  * Zip files are assumed to be correctly formed. No boundary checks are
  * performed, which means hand-crafted malicious Zip archives can make the
  * code fail in bad ways. However, since the only intended use is to load
  * libraries from Zip archives, there is no interest in making this code
  * safe, since the libraries could contain malicious code anyways.
  */
-class Zip: public mozilla::RefCounted<Zip>
+class Zip: public mozilla::AtomicRefCounted<Zip>
 {
 public:
   /**
    * Create a Zip instance for the given file name. Returns NULL in case
    * of failure.
    */
   static mozilla::TemporaryRef<Zip> Create(const char *filename);