Bug 771489: Use standard threadsafe refcounting in host resolver. r=sworkman

This commit is contained in:
Josh Aas 2012-07-10 10:14:01 -04:00
parent c5c89211d2
commit 4880d7e328
2 changed files with 4 additions and 23 deletions

View File

@ -149,8 +149,7 @@ private:
#define RES_KEY_FLAGS(_f) ((_f) & nsHostResolver::RES_CANON_NAME)
nsHostRecord::nsHostRecord(const nsHostKey *key)
: _refc(1)
, addr_info_lock("nsHostRecord.addr_info_lock")
: addr_info_lock("nsHostRecord.addr_info_lock")
, addr_info_gencnt(0)
, addr_info(nsnull)
, addr(nsnull)
@ -164,7 +163,6 @@ nsHostRecord::nsHostRecord(const nsHostKey *key)
flags = key->flags;
af = key->af;
NS_LOG_ADDREF(this, 1, "nsHostRecord", sizeof(nsHostRecord));
expiration = NowInMinutes();
PR_INIT_CLIST(this);
@ -181,6 +179,7 @@ nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
// allocated after it.
void *place = ::operator new(size);
*result = new(place) nsHostRecord(key);
NS_ADDREF(*result);
return NS_OK;
}

View File

@ -22,24 +22,6 @@ class nsHostResolver;
class nsHostRecord;
class nsResolveHostCallback;
/* XXX move this someplace more generic */
#define NS_DECL_REFCOUNTED_THREADSAFE(classname) \
private: \
nsAutoRefCnt _refc; \
public: \
PRInt32 AddRef() { \
PRInt32 n = NS_AtomicIncrementRefcnt(_refc); \
NS_LOG_ADDREF(this, n, #classname, sizeof(classname)); \
return n; \
} \
PRInt32 Release() { \
PRInt32 n = NS_AtomicDecrementRefcnt(_refc); \
NS_LOG_RELEASE(this, n, #classname); \
if (n == 0) \
delete this; \
return n; \
}
#define MAX_RESOLVER_THREADS_FOR_ANY_PRIORITY 3
#define MAX_RESOLVER_THREADS_FOR_HIGH_PRIORITY 5
#define MAX_NON_PRIORITY_REQUESTS 150
@ -62,7 +44,7 @@ class nsHostRecord : public PRCList, public nsHostKey
typedef mozilla::Mutex Mutex;
public:
NS_DECL_REFCOUNTED_THREADSAFE(nsHostRecord)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHostRecord)
/* instantiates a new host record */
static nsresult Create(const nsHostKey *key, nsHostRecord **record);
@ -178,7 +160,7 @@ public:
/**
* host resolver instances are reference counted.
*/
NS_DECL_REFCOUNTED_THREADSAFE(nsHostResolver)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHostResolver)
/**
* creates an addref'd instance of a nsHostResolver object.