[lld] r204850 - [PECOFF] Use std::mutex.

Rui Ueyama ruiu at google.com
Wed Mar 26 13:20:54 PDT 2014


Author: ruiu
Date: Wed Mar 26 15:20:53 2014
New Revision: 204850

URL: http://llvm.org/viewvc/llvm-project?rev=204850&view=rev
Log:
[PECOFF] Use std::mutex.

Use <mutex> instead of "llvm/Support/Mutex.h".

Also change the type of mutex for the context object to recursive mutex, as
the driver could acquire the lock recursively. E.g. If file A has .drectve
section containing /defaultlib:B, the driver tries to parse file B, and if
file B has .drectve section, the driver acquires the lock again.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h

Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=204850&r1=204849&r2=204850&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Wed Mar 26 15:20:53 2014
@@ -19,9 +19,9 @@
 #include "llvm/Support/COFF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileUtilities.h"
-#include "llvm/Support/Mutex.h"
 
 #include <map>
+#include <mutex>
 #include <set>
 #include <vector>
 
@@ -36,7 +36,7 @@ class Group;
 class PECOFFLinkingContext : public LinkingContext {
 public:
   PECOFFLinkingContext()
-      : _mutex(true), _allocMutex(false), _baseAddress(invalidBaseAddress),
+      : _mutex(), _allocMutex(), _baseAddress(invalidBaseAddress),
         _stackReserve(1024 * 1024), _stackCommit(4096),
         _heapReserve(1024 * 1024), _heapCommit(4096), _noDefaultLibAll(false),
         _sectionDefaultAlignment(4096),
@@ -236,9 +236,9 @@ public:
   const std::set<ExportDesc> &getDllExports() const { return _dllExports; }
 
   StringRef allocate(StringRef ref) const {
-    _allocMutex.acquire();
+    _allocMutex.lock();
     char *x = _allocator.Allocate<char>(ref.size() + 1);
-    _allocMutex.release();
+    _allocMutex.unlock();
     memcpy(x, ref.data(), ref.size());
     x[ref.size()] = '\0';
     return x;
@@ -246,17 +246,17 @@ public:
 
   ArrayRef<uint8_t> allocate(ArrayRef<uint8_t> array) const {
     size_t size = array.size();
-    _allocMutex.acquire();
+    _allocMutex.lock();
     uint8_t *p = _allocator.Allocate<uint8_t>(size);
-    _allocMutex.release();
+    _allocMutex.unlock();
     memcpy(p, array.data(), size);
     return ArrayRef<uint8_t>(p, p + array.size());
   }
 
   template <typename T> T &allocateCopy(const T &x) const {
-    _allocMutex.acquire();
+    _allocMutex.lock();
     T *r = new (_allocator) T(x);
-    _allocMutex.release();
+    _allocMutex.unlock();
     return *r;
   }
 
@@ -265,8 +265,8 @@ public:
   void setLibraryGroup(Group *group) { _libraryGroup = group; }
   Group *getLibraryGroup() const { return _libraryGroup; }
 
-  void lock() { _mutex.acquire(); }
-  void unlock() { _mutex.release(); }
+  void lock() { _mutex.lock(); }
+  void unlock() { _mutex.unlock(); }
 
 protected:
   /// Method to create a internal file for the entry symbol
@@ -282,8 +282,8 @@ private:
     pe32PlusDefaultBaseAddress = 0x140000000U
   };
 
-  llvm::sys::SmartMutex<false> _mutex;
-  mutable llvm::sys::SmartMutex<false> _allocMutex;
+  std::recursive_mutex _mutex;
+  mutable std::mutex _allocMutex;
 
   // The start address for the program. The default value for the executable is
   // 0x400000, but can be altered using /base command line option.





More information about the llvm-commits mailing list