Bug 1156974 - mark CacheFileHandle::mIsDoomed as a release/acquire Atomic variable; r=michal

This commit is contained in:
Nathan Froyd 2015-08-04 00:32:36 -04:00
Родитель 0b107f9b8a
Коммит 8a9abcdd4d
2 изменённых файлов: 11 добавлений и 5 удалений

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

@ -110,7 +110,6 @@ NS_INTERFACE_MAP_END_THREADSAFE
CacheFileHandle::CacheFileHandle(const SHA1Sum::Hash *aHash, bool aPriority) CacheFileHandle::CacheFileHandle(const SHA1Sum::Hash *aHash, bool aPriority)
: mHash(aHash) : mHash(aHash)
, mIsDoomed(false)
, mPriority(aPriority) , mPriority(aPriority)
, mClosed(false) , mClosed(false)
, mSpecialFile(false) , mSpecialFile(false)
@ -119,13 +118,17 @@ CacheFileHandle::CacheFileHandle(const SHA1Sum::Hash *aHash, bool aPriority)
, mFileSize(-1) , mFileSize(-1)
, mFD(nullptr) , mFD(nullptr)
{ {
// If we initialize mDoomed in the initialization list, that initialization is
// not guaranteeded to be atomic. Whereas this assignment here is guaranteed
// to be atomic. TSan will see this (atomic) assignment and be satisfied
// that cross-thread accesses to mIsDoomed are properly synchronized.
mIsDoomed = false;
LOG(("CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]" LOG(("CacheFileHandle::CacheFileHandle() [this=%p, hash=%08x%08x%08x%08x%08x]"
, this, LOGSHA1(aHash))); , this, LOGSHA1(aHash)));
} }
CacheFileHandle::CacheFileHandle(const nsACString &aKey, bool aPriority) CacheFileHandle::CacheFileHandle(const nsACString &aKey, bool aPriority)
: mHash(nullptr) : mHash(nullptr)
, mIsDoomed(false)
, mPriority(aPriority) , mPriority(aPriority)
, mClosed(false) , mClosed(false)
, mSpecialFile(true) , mSpecialFile(true)
@ -135,6 +138,8 @@ CacheFileHandle::CacheFileHandle(const nsACString &aKey, bool aPriority)
, mFD(nullptr) , mFD(nullptr)
, mKey(aKey) , mKey(aKey)
{ {
// See comment above about the initialization of mIsDoomed.
mIsDoomed = false;
LOG(("CacheFileHandle::CacheFileHandle() [this=%p, key=%s]", this, LOG(("CacheFileHandle::CacheFileHandle() [this=%p, key=%s]", this,
PromiseFlatCString(aKey).get())); PromiseFlatCString(aKey).get()));
} }
@ -162,13 +167,13 @@ CacheFileHandle::Log()
if (mSpecialFile) { if (mSpecialFile) {
LOG(("CacheFileHandle::Log() - special file [this=%p, isDoomed=%d, " LOG(("CacheFileHandle::Log() - special file [this=%p, isDoomed=%d, "
"priority=%d, closed=%d, invalid=%d, fileExists=%d, fileSize=%lld, " "priority=%d, closed=%d, invalid=%d, fileExists=%d, fileSize=%lld, "
"leafName=%s, key=%s]", this, mIsDoomed, mPriority, mClosed, mInvalid, "leafName=%s, key=%s]", this, int(mIsDoomed), mPriority, mClosed, mInvalid,
mFileExists, mFileSize, leafName.get(), mKey.get())); mFileExists, mFileSize, leafName.get(), mKey.get()));
} else { } else {
LOG(("CacheFileHandle::Log() - entry file [this=%p, hash=%08x%08x%08x%08x" LOG(("CacheFileHandle::Log() - entry file [this=%p, hash=%08x%08x%08x%08x"
"%08x, isDoomed=%d, priority=%d, closed=%d, invalid=%d, fileExists=%d," "%08x, isDoomed=%d, priority=%d, closed=%d, invalid=%d, fileExists=%d,"
" fileSize=%lld, leafName=%s, key=%s]", this, LOGSHA1(mHash), " fileSize=%lld, leafName=%s, key=%s]", this, LOGSHA1(mHash),
mIsDoomed, mPriority, mClosed, mInvalid, mFileExists, mFileSize, int(mIsDoomed), mPriority, mClosed, mInvalid, mFileExists, mFileSize,
leafName.get(), mKey.get())); leafName.get(), mKey.get()));
} }
} }

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

@ -10,6 +10,7 @@
#include "nsIEventTarget.h" #include "nsIEventTarget.h"
#include "nsITimer.h" #include "nsITimer.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "mozilla/Atomics.h"
#include "mozilla/SHA1.h" #include "mozilla/SHA1.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
#include "nsTArray.h" #include "nsTArray.h"
@ -69,7 +70,7 @@ private:
virtual ~CacheFileHandle(); virtual ~CacheFileHandle();
const SHA1Sum::Hash *mHash; const SHA1Sum::Hash *mHash;
bool mIsDoomed; mozilla::Atomic<bool,ReleaseAcquire> mIsDoomed;
bool mPriority; bool mPriority;
bool mClosed; bool mClosed;
bool mSpecialFile; bool mSpecialFile;