[lld] r311056 - Remove a lock and use a std::unique_ptr instead.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 17:27:55 PDT 2017
Author: ruiu
Date: Wed Aug 16 17:27:55 2017
New Revision: 311056
URL: http://llvm.org/viewvc/llvm-project?rev=311056&view=rev
Log:
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.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=311056&r1=311055&r2=311056&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Aug 16 17:27:55 2017
@@ -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;
}
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=311056&r1=311055&r2=311056&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Aug 16 17:27:55 2017
@@ -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.
More information about the llvm-commits
mailing list