[lld] r204853 - [PECOFF] Use RAII object for mutex.
Rui Ueyama
ruiu at google.com
Wed Mar 26 14:08:18 PDT 2014
Author: ruiu
Date: Wed Mar 26 16:08:17 2014
New Revision: 204853
URL: http://llvm.org/viewvc/llvm-project?rev=204853&view=rev
Log:
[PECOFF] Use RAII object for mutex.
Modified:
lld/trunk/include/lld/Driver/Driver.h
lld/trunk/include/lld/Driver/WinLinkInputGraph.h
lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/trunk/lib/Driver/WinLinkDriver.cpp
Modified: lld/trunk/include/lld/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/Driver.h?rev=204853&r1=204852&r2=204853&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/Driver.h (original)
+++ lld/trunk/include/lld/Driver/Driver.h Wed Mar 26 16:08:17 2014
@@ -115,9 +115,6 @@ public:
bool isDirective = false);
private:
- static bool doParse(int argc, const char *argv[], PECOFFLinkingContext &info,
- raw_ostream &diagnostics, bool isDirective);
-
WinLinkDriver() LLVM_DELETED_FUNCTION;
};
Modified: lld/trunk/include/lld/Driver/WinLinkInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WinLinkInputGraph.h?rev=204853&r1=204852&r2=204853&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/WinLinkInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/WinLinkInputGraph.h Wed Mar 26 16:08:17 2014
@@ -67,13 +67,11 @@ public:
/// \brief Parse the group members.
error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) override {
auto *pctx = (PECOFFLinkingContext *)(&ctx);
- error_code ec = error_code::success();
- pctx->lock();
+ std::lock_guard<std::recursive_mutex> lock(pctx->getMutex());
for (auto &elem : _elements)
- if ((ec = elem->parse(ctx, diagnostics)))
- break;
- pctx->unlock();
- return ec;
+ if (error_code ec = elem->parse(ctx, diagnostics))
+ return ec;
+ return error_code::success();
}
};
Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=204853&r1=204852&r2=204853&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Wed Mar 26 16:08:17 2014
@@ -265,8 +265,7 @@ public:
void setLibraryGroup(Group *group) { _libraryGroup = group; }
Group *getLibraryGroup() const { return _libraryGroup; }
- void lock() { _mutex.lock(); }
- void unlock() { _mutex.unlock(); }
+ std::recursive_mutex &getMutex() { return _mutex; }
protected:
/// Method to create a internal file for the entry symbol
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=204853&r1=204852&r2=204853&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Wed Mar 26 16:08:17 2014
@@ -780,9 +780,14 @@ bool WinLinkDriver::linkPECOFF(int argc,
return link(context, diag);
}
-bool WinLinkDriver::doParse(int argc, const char *argv[],
- PECOFFLinkingContext &ctx, raw_ostream &diag,
- bool isReadingDirectiveSection) {
+bool WinLinkDriver::parse(int argc, const char *argv[],
+ PECOFFLinkingContext &ctx, raw_ostream &diag,
+ bool isReadingDirectiveSection) {
+ // Parse may be called from multiple threads simultaneously to parse .drectve
+ // sections. This function is not thread-safe because it mutates the context
+ // object. So acquire the lock.
+ std::lock_guard<std::recursive_mutex> lock(ctx.getMutex());
+
std::map<StringRef, StringRef> failIfMismatchMap;
// Parse the options.
std::unique_ptr<llvm::opt::InputArgList> parsedArgs =
@@ -1260,16 +1265,4 @@ bool WinLinkDriver::doParse(int argc, co
return ctx.validate(diag);
}
-// Parse may be called from multiple threads simultaneously to parse .drectve
-// sections. doParse() is not thread-safe because it mutates the context
-// object. This function wraps doParse() with a mutex.
-bool WinLinkDriver::parse(int argc, const char *argv[],
- PECOFFLinkingContext &ctx, raw_ostream &diag,
- bool isReadingDirectiveSection) {
- ctx.lock();
- bool r = doParse(argc, argv, ctx, diag, isReadingDirectiveSection);
- ctx.unlock();
- return r;
-}
-
} // namespace lld
More information about the llvm-commits
mailing list