void CacheEntry::PurgeAndDoom() { LOG(("CacheEntry::PurgeAndDoom [this=%p]", this)); CacheStorageService::Self()->RemoveEntry(this); DoomAlreadyRemoved(); }
void CacheEntry::BackgroundOp(uint32_t aOperations, bool aForceAsync) { mLock.AssertCurrentThreadOwns(); if (!CacheStorageService::IsOnManagementThread() || aForceAsync) { if (mBackgroundOperations.Set(aOperations)) CacheStorageService::Self()->Dispatch(this); LOG(("CacheEntry::BackgroundOp this=%p dipatch of %x", this, aOperations)); return; } mozilla::MutexAutoUnlock unlock(mLock); MOZ_ASSERT(CacheStorageService::IsOnManagementThread()); if (aOperations & Ops::FRECENCYUPDATE) { #ifndef M_LN2 #define M_LN2 0.69314718055994530942 #endif // Half-life is 90 days. static double const half_life = 90.0 * (24 * 60 * 60); // Must convert from seconds to milliseconds since PR_Now() gives usecs. static double const decay = (M_LN2 / half_life) / static_cast<double>(PR_USEC_PER_SEC); double now_decay = static_cast<double>(PR_Now()) * decay; if (mFrecency == 0) { mFrecency = now_decay; } else { // TODO: when C++11 enabled, use std::log1p(n) which is equal to log(n + 1) but // more precise. mFrecency = log(exp(mFrecency - now_decay) + 1) + now_decay; } LOG(("CacheEntry FRECENCYUPDATE [this=%p, frecency=%1.10f]", this, mFrecency)); } if (aOperations & Ops::REGISTER) { LOG(("CacheEntry REGISTER [this=%p]", this)); CacheStorageService::Self()->RegisterEntry(this); } if (aOperations & Ops::DOOM) { LOG(("CacheEntry DOOM [this=%p]", this)); DoomAlreadyRemoved(); } if (aOperations & Ops::CALLBACKS) { LOG(("CacheEntry CALLBACKS (invoke) [this=%p]", this)); mozilla::MutexAutoLock lock(mLock); InvokeCallbacks(); } }
void CacheEntry::PurgeAndDoom() { LOG(("CacheEntry::PurgeAndDoom [this=%p]", this)); MOZ_ASSERT(CacheStorageService::IsOnManagementThread()); CacheStorageService::Self()->RemoveEntry(this); DoomAlreadyRemoved(); }
void CacheEntry::BackgroundOp(uint32_t aOperations, bool aForceAsync) { mLock.AssertCurrentThreadOwns(); if (!CacheStorageService::IsOnManagementThread() || aForceAsync) { if (mBackgroundOperations.Set(aOperations)) CacheStorageService::Self()->Dispatch(this); LOG(("CacheEntry::BackgroundOp this=%p dipatch of %x", this, aOperations)); return; } mozilla::MutexAutoUnlock unlock(mLock); MOZ_ASSERT(CacheStorageService::IsOnManagementThread()); if (aOperations & Ops::FRECENCYUPDATE) { #ifndef M_LN2 #define M_LN2 0.69314718055994530942 #endif // Half-life is dynamic, in seconds. static double half_life = CacheObserver::HalfLifeSeconds(); // Must convert from seconds to milliseconds since PR_Now() gives usecs. static double const decay = (M_LN2 / half_life) / static_cast<double>(PR_USEC_PER_SEC); double now_decay = static_cast<double>(PR_Now()) * decay; if (mFrecency == 0) { mFrecency = now_decay; } else { // TODO: when C++11 enabled, use std::log1p(n) which is equal to log(n + 1) but // more precise. mFrecency = log(exp(mFrecency - now_decay) + 1) + now_decay; } LOG(("CacheEntry FRECENCYUPDATE [this=%p, frecency=%1.10f]", this, mFrecency)); // Because CacheFile::Set*() are not thread-safe to use (uses WeakReference that // is not thread-safe) we must post to the main thread... nsRefPtr<nsRunnableMethod<CacheEntry> > event = NS_NewRunnableMethod(this, &CacheEntry::StoreFrecency); NS_DispatchToMainThread(event); } if (aOperations & Ops::REGISTER) { LOG(("CacheEntry REGISTER [this=%p]", this)); CacheStorageService::Self()->RegisterEntry(this); } if (aOperations & Ops::DOOM) { LOG(("CacheEntry DOOM [this=%p]", this)); DoomAlreadyRemoved(); } if (aOperations & Ops::CALLBACKS) { LOG(("CacheEntry CALLBACKS (invoke) [this=%p]", this)); mozilla::MutexAutoLock lock(mLock); InvokeCallbacks(); } }