Changed nsAutoMonitor to nsAutoCMonitor (cached monitors).

This commit is contained in:
warren%netscape.com 1999-06-16 04:15:08 +00:00
Родитель 27856b5d92
Коммит ea65cc126c
3 изменённых файлов: 65 добавлений и 10 удалений

Просмотреть файл

@ -85,7 +85,7 @@ nsBuffer::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
nsresult
nsBuffer::PushWriteSegment()
{
nsAutoMonitor mon(this); // protect mSegments
nsAutoCMonitor mon(this); // protect mSegments
if (mBufferSize >= mMaxSize) {
if (mObserver) {
@ -118,7 +118,7 @@ nsresult
nsBuffer::PopReadSegment()
{
nsresult rv;
nsAutoMonitor mon(this); // protect mSegments
nsAutoCMonitor mon(this); // protect mSegments
PRCList* header = (PRCList*)mSegments.next;
char* segment = (char*)header;

Просмотреть файл

@ -34,7 +34,7 @@ public:
NS_IMETHOD Run() {
nsresult rv;
nsAutoMonitor mon(this);
nsAutoCMonitor mon(this);
char buf[100];
PRUint32 readCnt;
@ -128,7 +128,7 @@ WriteMessages(nsIBuffer* buffer)
return rv;
}
if (cnt == 0) {
nsAutoMonitor mon(reader);
nsAutoCMonitor mon(reader);
mon.Notify(); // wake up reader
mon.Wait(); // and wait for reader to read all
}
@ -142,7 +142,7 @@ WriteMessages(nsIBuffer* buffer)
PR_FREEIF(mem);
{
reader->SetEOF();
nsAutoMonitor mon(reader);
nsAutoCMonitor mon(reader);
mon.Notify(); // wake up reader
}

Просмотреть файл

@ -130,14 +130,69 @@ public:
class nsAutoMonitor {
public:
nsAutoMonitor(void* lockObject)
nsAutoMonitor(PRMonitor* mon)
: mMonitor(mon)
{
NS_ASSERTION(mMonitor, "null lock object");
PR_EnterMonitor(mMonitor);
}
~nsAutoMonitor() {
PR_ExitMonitor(mMonitor);
}
nsresult Wait(PRIntervalTime interval = PR_INTERVAL_NO_TIMEOUT) {
return PR_Wait(mMonitor, interval) == PR_SUCCESS
? NS_OK : NS_ERROR_FAILURE;
}
nsresult Notify() {
return PR_Notify(mMonitor) == PR_SUCCESS
? NS_OK : NS_ERROR_FAILURE;
}
nsresult NotifyAll() {
return PR_NotifyAll(mMonitor) == PR_SUCCESS
? NS_OK : NS_ERROR_FAILURE;
}
private:
PRMonitor* mMonitor;
// Not meant to be implemented. This makes it a compiler error to
// construct or assign an nsAutoLock object incorrectly.
nsAutoMonitor(void) {}
nsAutoMonitor(nsAutoMonitor& aMon) {}
nsAutoMonitor& operator =(nsAutoMonitor& aMon) {
return *this;
}
// Not meant to be implemented. This makes it a compiler error to
// attempt to create an nsAutoLock object on the heap.
static void* operator new(size_t size) {
return nsnull;
}
static void operator delete(void* memory) {}
};
////////////////////////////////////////////////////////////////////////////////
// Once again, this time with a cache...
// (Using this avoids the need to allocate a PRMonitor, which may be useful when
// a large number of objects of the same class need associated monitors.)
#include "prcmon.h"
#include "nsError.h"
class nsAutoCMonitor {
public:
nsAutoCMonitor(void* lockObject)
: mLockObject(lockObject)
{
NS_ASSERTION(lockObject, "null lock object");
PR_CEnterMonitor(mLockObject);
}
~nsAutoMonitor() {
~nsAutoCMonitor() {
PR_CExitMonitor(mLockObject);
}
@ -161,9 +216,9 @@ private:
// Not meant to be implemented. This makes it a compiler error to
// construct or assign an nsAutoLock object incorrectly.
nsAutoMonitor(void) {}
nsAutoMonitor(nsAutoMonitor& aMon) {}
nsAutoMonitor& operator =(nsAutoMonitor& aMon) {
nsAutoCMonitor(void) {}
nsAutoCMonitor(nsAutoCMonitor& aMon) {}
nsAutoCMonitor& operator =(nsAutoCMonitor& aMon) {
return *this;
}