Bug 605362, part 4: Notify shmem MemoryReporters from all shmem backends. r=joe
authorChris Jones <jones.chris.g@gmail.com>
Fri, 05 Nov 2010 02:17:07 -0500
changeset 56909 e390c6cf96b1adffdfef04298d6ea95e82073b25
parent 56908 e25e8b0bb4d0929468b0fd595571c51ecd2a8564
child 56910 ffb9040a013b85de49d83fe36d8b52609932b0b9
push id16725
push usercjones@mozilla.com
push dateFri, 05 Nov 2010 07:21:46 +0000
treeherdermozilla-central@0aa98eae87ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs605362
milestone2.0b8pre
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 605362, part 4: Notify shmem MemoryReporters from all shmem backends. r=joe
ipc/glue/SharedMemoryBasic_android.cpp
ipc/glue/SharedMemoryBasic_chromium.h
ipc/glue/SharedMemorySysV.h
--- a/ipc/glue/SharedMemoryBasic_android.cpp
+++ b/ipc/glue/SharedMemoryBasic_android.cpp
@@ -103,16 +103,17 @@ SharedMemoryBasic::Create(size_t aNbytes
   if (ioctl(shmfd, ASHMEM_SET_SIZE, aNbytes)) {
     LogError("ShmemAndroid::Unmap():ioctl(SET_SIZE)");
     close(shmfd);
     return false;
   }
 
   mShmFd = shmfd;
   mAllocSize = aNbytes;
+  Created(aNbytes);
   return true;
 }
 
 bool
 SharedMemoryBasic::Map(size_t nBytes)
 {
   NS_ABORT_IF_FALSE(nsnull == mMemory, "Already Map()d");
 
@@ -123,16 +124,17 @@ SharedMemoryBasic::Map(size_t nBytes)
                  0);
   if (MAP_FAILED == mMemory) {
     LogError("ShmemAndroid::Map()");
     mMemory = nsnull;
     return false;
   }
 
   mSize = nBytes;
+  Mapped(nBytes);
   return true;
 }
 
 bool
 SharedMemoryBasic::ShareToProcess(base::ProcessHandle/*unused*/,
                                   Handle* aNewHandle)
 {
   NS_ABORT_IF_FALSE(mShmFd >= 0, "Should have been Create()d by now");
@@ -155,20 +157,24 @@ SharedMemoryBasic::Unmap()
     return;
   }
 
   if (munmap(mMemory, mSize)) {
     LogError("ShmemAndroid::Unmap()");
   }
   mMemory = nsnull;
   mSize = 0;
+  Unmapped(mSize);
 }
 
 void
 SharedMemoryBasic::Destroy()
 {
   if (mShmFd > 0) {
     close(mShmFd);
+    if (mAllocSize) {
+      Destroyed(mAllocSize);
+    }
   }
 }
 
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/glue/SharedMemoryBasic_chromium.h
+++ b/ipc/glue/SharedMemoryBasic_chromium.h
@@ -66,32 +66,44 @@ public:
 
   SharedMemoryBasic(const Handle& aHandle)
     : mSharedMemory(aHandle, false)
     , mAllocSize(0)
     , mSize(0)
   {
   }
 
+  virtual ~SharedMemoryBasic() {
+    if (memory()) {
+      Unmapped(mSize);
+    }
+    if (mAllocSize) {
+      Destroyed(mAllocSize);
+    }
+  }
+
   NS_OVERRIDE
   virtual bool Create(size_t aNbytes)
   {
     bool ok = mSharedMemory.Create("", false, false, aNbytes);
     if (ok) {
       mAllocSize = aNbytes;
+      Created(aNbytes);
     }
     return ok;
   }
 
   NS_OVERRIDE
   virtual bool Map(size_t nBytes)
   {
     bool ok = mSharedMemory.Map(nBytes);
-    if (ok)
+    if (ok) {
       mSize = nBytes;
+      Mapped(nBytes);
+    }
     return ok;
   }
 
   NS_OVERRIDE
   virtual size_t Size() const
   {
     return mSize;
   }
--- a/ipc/glue/SharedMemorySysV.h
+++ b/ipc/glue/SharedMemorySysV.h
@@ -85,37 +85,41 @@ public:
     mData(nsnull),
     mAllocSize(0),
     mSize(0)
   {
   }
 
   virtual ~SharedMemorySysV()
   {
+    if (memory()) {
+      Unmapped(mSize);
+    }
+    if (mAllocSize) {
+      Destroyed(mAllocSize);
+    }
+
     shmdt(mData);
     mHandle = -1;
     mData = nsnull;
     mSize = 0;
-    
   }
 
   NS_OVERRIDE
   virtual bool Create(size_t aNbytes)
   {
     int id = shmget(IPC_PRIVATE, aNbytes, IPC_CREAT | 0600);
     if (id == -1)
       return false;
 
     mHandle = id;
     mAllocSize = aNbytes;
+    Created(aNbytes);
 
-    if (!Map(aNbytes))
-      return false;
-
-    return true;
+    return Map(aNbytes);
   }
 
   NS_OVERRIDE
   virtual bool Map(size_t nBytes)
   {
     // already mapped
     if (mData)
       return true;
@@ -145,16 +149,17 @@ public:
     struct shmid_ds info;
     if (shmctl(mHandle, IPC_STAT, &info) < 0)
       return false;
 
     NS_ABORT_IF_FALSE(nBytes <= info.shm_segsz,
                       "Segment doesn't have enough space!");
 #endif
 
+    Mapped(nBytes);
     return true;
   }
 
   NS_OVERRIDE
   virtual size_t Size() const
   {
     return mSize;
   }