[lld] r238072 - [lld] Manage atom ordinals in the File class rather than using a static counter.
Lang Hames
lhames at gmail.com
Fri May 22 16:56:45 PDT 2015
Author: lhames
Date: Fri May 22 18:56:44 2015
New Revision: 238072
URL: http://llvm.org/viewvc/llvm-project?rev=238072&view=rev
Log:
[lld] Manage atom ordinals in the File class rather than using a static counter.
This is a cleaner fix for the race-condition bug that was originally papered
over by r237857.
Modified:
lld/trunk/include/lld/Core/File.h
lld/trunk/include/lld/Core/Simple.h
Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=238072&r1=238071&r2=238072&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Fri May 22 18:56:44 2015
@@ -86,6 +86,11 @@ public:
/// Sets the command line order of the file.
void setOrdinal(uint64_t ordinal) const { _ordinal = ordinal; }
+ /// Returns the ordinal for the next atom to be defined in this file.
+ uint64_t getNextAtomOrdinalAndIncrement() const {
+ return _nextAtomOrdinal++;
+ }
+
/// For allocating any objects owned by this File.
llvm::BumpPtrAllocator &allocator() const {
return _allocator;
@@ -152,7 +157,8 @@ public:
protected:
/// \brief only subclasses of File can be instantiated
File(StringRef p, Kind kind)
- : _path(p), _kind(kind), _ordinal(UINT64_MAX) {}
+ : _path(p), _kind(kind), _ordinal(UINT64_MAX),
+ _nextAtomOrdinal(0) {}
/// \brief Subclasses should override this method to parse the
/// memory buffer passed to this file's constructor.
@@ -170,6 +176,7 @@ private:
mutable std::string _archiveMemberPath;
Kind _kind;
mutable uint64_t _ordinal;
+ mutable uint64_t _nextAtomOrdinal;
std::shared_ptr<MemoryBuffer> _sharedMemoryBuffer;
llvm::Optional<std::error_code> _lastError;
std::mutex _parseMutex;
Modified: lld/trunk/include/lld/Core/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Simple.h?rev=238072&r1=238071&r2=238072&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Simple.h (original)
+++ lld/trunk/include/lld/Core/Simple.h Fri May 22 18:56:44 2015
@@ -206,9 +206,8 @@ namespace lld {
class SimpleDefinedAtom : public DefinedAtom {
public:
- explicit SimpleDefinedAtom(const File &f) : _file(f) {
- static std::atomic<uint32_t> lastOrdinal(0);
- _ordinal = lastOrdinal++;
+ explicit SimpleDefinedAtom(const File &f)
+ : _file(f), _ordinal(f.getNextAtomOrdinalAndIncrement()) {
_references.setAllocator(&f.allocator());
}
More information about the llvm-commits
mailing list