2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef _nsCacheRequest_h_
|
|
|
|
#define _nsCacheRequest_h_
|
|
|
|
|
|
|
|
#include "nspr.h"
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
#include "mozilla/CondVar.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsICache.h"
|
|
|
|
#include "nsICacheListener.h"
|
|
|
|
#include "nsCacheSession.h"
|
|
|
|
#include "nsCacheService.h"
|
|
|
|
|
|
|
|
|
|
|
|
class nsCacheRequest : public PRCList
|
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
typedef mozilla::CondVar CondVar;
|
|
|
|
typedef mozilla::MutexAutoLock MutexAutoLock;
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
friend class nsCacheService;
|
|
|
|
friend class nsCacheEntry;
|
2010-08-23 18:06:23 -07:00
|
|
|
friend class nsProcessRequestEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCacheRequest( nsCString * key,
|
|
|
|
nsICacheListener * listener,
|
|
|
|
nsCacheAccessMode accessRequested,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool blockingMode,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCacheSession * session)
|
|
|
|
: mKey(key),
|
|
|
|
mInfo(0),
|
|
|
|
mListener(listener),
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
mLock("nsCacheRequest.mLock"),
|
|
|
|
mCondVar(mLock, "nsCacheRequest.mCondVar")
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCacheRequest);
|
|
|
|
PR_INIT_CLIST(this);
|
|
|
|
SetAccessRequested(accessRequested);
|
|
|
|
SetStoragePolicy(session->StoragePolicy());
|
|
|
|
if (session->IsStreamBased()) MarkStreamBased();
|
|
|
|
if (session->WillDoomEntriesIfExpired()) MarkDoomEntriesIfExpired();
|
|
|
|
if (blockingMode == nsICache::BLOCKING) MarkBlockingMode();
|
|
|
|
MarkWaitingForValidation();
|
|
|
|
NS_IF_ADDREF(mListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsCacheRequest()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCacheRequest);
|
|
|
|
delete mKey;
|
|
|
|
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list");
|
|
|
|
|
|
|
|
if (mListener)
|
|
|
|
nsCacheService::ReleaseObject_Locked(mListener, mThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple Accessors
|
|
|
|
*/
|
|
|
|
enum CacheRequestInfo {
|
|
|
|
eStoragePolicyMask = 0x000000FF,
|
|
|
|
eStreamBasedMask = 0x00000100,
|
|
|
|
eDoomEntriesIfExpiredMask = 0x00001000,
|
|
|
|
eBlockingModeMask = 0x00010000,
|
|
|
|
eWaitingForValidationMask = 0x00100000,
|
|
|
|
eAccessRequestedMask = 0xFF000000
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetAccessRequested(nsCacheAccessMode mode)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mode <= 0xFF, "too many bits in nsCacheAccessMode");
|
|
|
|
mInfo &= ~eAccessRequestedMask;
|
|
|
|
mInfo |= mode << 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCacheAccessMode AccessRequested()
|
|
|
|
{
|
|
|
|
return (nsCacheAccessMode)((mInfo >> 24) & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool WillDoomEntriesIfExpired() { return (0 != (mInfo & eDoomEntriesIfExpiredMask)); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void MarkBlockingMode() { mInfo |= eBlockingModeMask; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsBlocking() { return (0 != (mInfo & eBlockingModeMask)); }
|
|
|
|
bool IsNonBlocking() { return !(mInfo & eBlockingModeMask); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
|
|
|
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
|
|
|
mInfo |= policy; // or in new bits
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCacheStoragePolicy StoragePolicy()
|
|
|
|
{
|
|
|
|
return (nsCacheStoragePolicy)(mInfo & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkWaitingForValidation() { mInfo |= eWaitingForValidationMask; }
|
|
|
|
void DoneWaitingForValidation() { mInfo &= ~eWaitingForValidationMask; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool WaitingForValidation()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return (mInfo & eWaitingForValidationMask) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
WaitForValidation(void)
|
|
|
|
{
|
|
|
|
if (!WaitingForValidation()) { // flag already cleared
|
|
|
|
MarkWaitingForValidation(); // set up for next time
|
|
|
|
return NS_OK; // early exit;
|
|
|
|
}
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
while (WaitingForValidation()) {
|
|
|
|
mCondVar.Wait();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
MarkWaitingForValidation(); // set up for next time
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WakeUp(void) {
|
|
|
|
DoneWaitingForValidation();
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
mCondVar.Notify();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data members
|
|
|
|
*/
|
|
|
|
nsCString * mKey;
|
|
|
|
PRUint32 mInfo;
|
|
|
|
nsICacheListener * mListener; // strong ref
|
|
|
|
nsCOMPtr<nsIThread> mThread;
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-03-31 21:29:02 -07:00
|
|
|
Mutex mLock;
|
|
|
|
CondVar mCondVar;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _nsCacheRequest_h_
|