Remove a lock and use a std::unique_ptr instead.

We had a lock to guard BAlloc from being used concurrently, but that
is not very easy to understand. This patch replaces it with a
std::unique_ptr.

llvm-svn: 311056
This commit is contained in:
Rui Ueyama 2017-08-17 00:27:55 +00:00
parent 42a535351e
commit 314a005002
2 changed files with 9 additions and 9 deletions

View File

@ -200,17 +200,12 @@ void InputSectionBase::uncompress() {
Config->IsLE, Config->Is64));
size_t Size = Dec.getDecompressedSize();
char *OutputBuf;
{
static std::mutex Mu;
std::lock_guard<std::mutex> Lock(Mu);
OutputBuf = BAlloc.Allocate<char>(Size);
}
if (Error E = Dec.decompress({OutputBuf, Size}))
UncompressBuf.reset(new std::vector<uint8_t>(Size));
if (Error E = Dec.decompress({(char *)UncompressBuf->data(), Size}))
fatal(toString(this) +
": decompress failed: " + llvm::toString(std::move(E)));
this->Data = ArrayRef<uint8_t>((uint8_t *)OutputBuf, Size);
this->Data = *UncompressBuf;
this->Flags &= ~(uint64_t)SHF_COMPRESSED;
}

View File

@ -183,6 +183,11 @@ public:
assert(S % sizeof(T) == 0);
return llvm::makeArrayRef<T>((const T *)Data.data(), S / sizeof(T));
}
private:
// A pointer that owns uncompressed data if a section is compressed by zlib.
// Since the feature is not used often, this is usually a nullptr.
std::unique_ptr<std::vector<uint8_t>> UncompressBuf;
};
// SectionPiece represents a piece of splittable section contents.