mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-05 00:48:08 +00:00
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:
parent
42a535351e
commit
314a005002
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user