bug 357426 add static ctor/dtor PRLock methods via nsAutoLock ala. nsAutoMonitor

r=brendan
sr=jst
This commit is contained in:
redfive%acm.org 2006-10-27 00:57:14 +00:00
Родитель c10cbf5223
Коммит 6d59aea94b
2 изменённых файлов: 52 добавлений и 15 удалений

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

@ -138,11 +138,13 @@ _purge_one(PLHashEntry* he, PRIntn cnt, void* arg)
}
PR_STATIC_CALLBACK(void)
OnMonitorRecycle(void* addr)
OnSemaphoreRecycle(void* addr)
{
PR_Lock(OrderTableLock);
PL_HashTableEnumerateEntries(OrderTable, _purge_one, addr);
PR_Unlock(OrderTableLock);
if (OrderTable) {
PR_Lock(OrderTableLock);
PL_HashTableEnumerateEntries(OrderTable, _purge_one, addr);
PR_Unlock(OrderTableLock);
}
}
PR_STATIC_CALLBACK(PLHashNumber)
@ -162,7 +164,7 @@ static void InitAutoLockStatics()
PL_HashTableDestroy(OrderTable);
OrderTable = 0;
}
PR_CSetOnMonitorRecycle(OnMonitorRecycle);
PR_CSetOnMonitorRecycle(OnSemaphoreRecycle);
}
void _FreeAutoLockStatics()
@ -191,6 +193,18 @@ static nsNamedVector* GetVector(PLHashTable* table, const void* key)
return vec;
}
static void OnSemaphoreCreated(const void* key, const char* name )
{
if (key && OrderTable) {
nsNamedVector* value = new nsNamedVector(name);
if (value) {
PR_Lock(OrderTableLock);
PL_HashTableAdd(OrderTable, key, value);
PR_Unlock(OrderTableLock);
}
}
}
// We maintain an acyclic graph in OrderTable, so recursion can't diverge.
static PRBool Reachable(PLHashTable* table, const void* goal, const void* start)
{
@ -374,18 +388,28 @@ nsAutoUnlockBase::~nsAutoUnlockBase()
#endif /* DEBUG */
PRLock* nsAutoLock::NewLock(const char* name)
{
PRLock* lock = PR_NewLock();
#ifdef DEBUG
OnSemaphoreCreated(lock, name);
#endif
return lock;
}
void nsAutoLock::DestroyLock(PRLock* lock)
{
#ifdef DEBUG
OnSemaphoreRecycle(lock);
#endif
PR_DestroyLock(lock);
}
PRMonitor* nsAutoMonitor::NewMonitor(const char* name)
{
PRMonitor* mon = PR_NewMonitor();
#ifdef DEBUG
if (mon && OrderTable) {
nsNamedVector* value = new nsNamedVector(name);
if (value) {
PR_Lock(OrderTableLock);
PL_HashTableAdd(OrderTable, mon, value);
PR_Unlock(OrderTableLock);
}
}
OnSemaphoreCreated(mon, name);
#endif
return mon;
}
@ -393,8 +417,7 @@ PRMonitor* nsAutoMonitor::NewMonitor(const char* name)
void nsAutoMonitor::DestroyMonitor(PRMonitor* mon)
{
#ifdef DEBUG
if (OrderTable)
OnMonitorRecycle(mon);
OnSemaphoreRecycle(mon);
#endif
PR_DestroyMonitor(mon);
}

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

@ -186,6 +186,20 @@ private:
static void operator delete(void* /*memory*/) {}
public:
/**
* NewLock
* Allocates a new PRLock for use with nsAutoLock. name is
* not checked for uniqueness.
* @param name A name which can reference this lock
* @param lock A valid PRLock* that was created by nsAutoLock::NewLock()
* @returns nsnull if failure
* A valid PRLock* if successful, which must be destroyed
* by nsAutoLock::DestroyLock()
**/
static PRLock* NewLock(const char* name);
static void DestroyLock(PRLock* lock);
/**
* Constructor
* The constructor aquires the given lock. The destructor