Bug 605362, part 4: Notify shmem MemoryReporters from all shmem backends. r=joe

This commit is contained in:
Chris Jones 2010-11-05 02:17:07 -05:00
parent d842dc7390
commit bb45a6061a
3 changed files with 29 additions and 6 deletions

View File

@ -108,6 +108,7 @@ SharedMemoryBasic::Create(size_t aNbytes)
mShmFd = shmfd; mShmFd = shmfd;
mAllocSize = aNbytes; mAllocSize = aNbytes;
Created(aNbytes);
return true; return true;
} }
@ -128,6 +129,7 @@ SharedMemoryBasic::Map(size_t nBytes)
} }
mSize = nBytes; mSize = nBytes;
Mapped(nBytes);
return true; return true;
} }
@ -160,6 +162,7 @@ SharedMemoryBasic::Unmap()
} }
mMemory = nsnull; mMemory = nsnull;
mSize = 0; mSize = 0;
Unmapped(mSize);
} }
void void
@ -167,6 +170,9 @@ SharedMemoryBasic::Destroy()
{ {
if (mShmFd > 0) { if (mShmFd > 0) {
close(mShmFd); close(mShmFd);
if (mAllocSize) {
Destroyed(mAllocSize);
}
} }
} }

View File

@ -71,12 +71,22 @@ public:
{ {
} }
virtual ~SharedMemoryBasic() {
if (memory()) {
Unmapped(mSize);
}
if (mAllocSize) {
Destroyed(mAllocSize);
}
}
NS_OVERRIDE NS_OVERRIDE
virtual bool Create(size_t aNbytes) virtual bool Create(size_t aNbytes)
{ {
bool ok = mSharedMemory.Create("", false, false, aNbytes); bool ok = mSharedMemory.Create("", false, false, aNbytes);
if (ok) { if (ok) {
mAllocSize = aNbytes; mAllocSize = aNbytes;
Created(aNbytes);
} }
return ok; return ok;
} }
@ -85,8 +95,10 @@ public:
virtual bool Map(size_t nBytes) virtual bool Map(size_t nBytes)
{ {
bool ok = mSharedMemory.Map(nBytes); bool ok = mSharedMemory.Map(nBytes);
if (ok) if (ok) {
mSize = nBytes; mSize = nBytes;
Mapped(nBytes);
}
return ok; return ok;
} }

View File

@ -90,11 +90,17 @@ public:
virtual ~SharedMemorySysV() virtual ~SharedMemorySysV()
{ {
if (memory()) {
Unmapped(mSize);
}
if (mAllocSize) {
Destroyed(mAllocSize);
}
shmdt(mData); shmdt(mData);
mHandle = -1; mHandle = -1;
mData = nsnull; mData = nsnull;
mSize = 0; mSize = 0;
} }
NS_OVERRIDE NS_OVERRIDE
@ -106,11 +112,9 @@ public:
mHandle = id; mHandle = id;
mAllocSize = aNbytes; mAllocSize = aNbytes;
Created(aNbytes);
if (!Map(aNbytes)) return Map(aNbytes);
return false;
return true;
} }
NS_OVERRIDE NS_OVERRIDE
@ -150,6 +154,7 @@ public:
"Segment doesn't have enough space!"); "Segment doesn't have enough space!");
#endif #endif
Mapped(nBytes);
return true; return true;
} }