mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-04 00:20:14 +00:00
[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. llvm-svn: 204850
This commit is contained in:
parent
e180ecab2c
commit
664afe94a6
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user