forked from OSchip/llvm-project
[XRay][compiler-rt] Remove reliance on C++ ABI from BufferQueue
Summary: This is part of the work to address http://llvm.org/PR32274. We remove the calls to array-placement-new and array-delete. This allows us to rely on the internal memory management provided by sanitizer_common/sanitizer_internal_allocator.h. Reviewers: eizan, kpw Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47695 llvm-svn: 333982
This commit is contained in:
parent
e5eb99668c
commit
8ba925d2c3
|
@ -16,14 +16,37 @@
|
||||||
#include "sanitizer_common/sanitizer_allocator_internal.h"
|
#include "sanitizer_common/sanitizer_allocator_internal.h"
|
||||||
#include "sanitizer_common/sanitizer_common.h"
|
#include "sanitizer_common/sanitizer_common.h"
|
||||||
#include "sanitizer_common/sanitizer_libc.h"
|
#include "sanitizer_common/sanitizer_libc.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
using namespace __xray;
|
using namespace __xray;
|
||||||
using namespace __sanitizer;
|
using namespace __sanitizer;
|
||||||
|
|
||||||
|
template <class T> static T *initArray(size_t N) {
|
||||||
|
auto A = reinterpret_cast<T *>(
|
||||||
|
InternalAlloc(N * sizeof(T), nullptr, kCacheLineSize));
|
||||||
|
if (A != nullptr)
|
||||||
|
while (N > 0)
|
||||||
|
new (A + (--N)) T();
|
||||||
|
return A;
|
||||||
|
}
|
||||||
|
|
||||||
BufferQueue::BufferQueue(size_t B, size_t N, bool &Success)
|
BufferQueue::BufferQueue(size_t B, size_t N, bool &Success)
|
||||||
: BufferSize(B), Buffers(new BufferRep[N]()), BufferCount(N), Finalizing{0},
|
: BufferSize(B), Buffers(initArray<BufferQueue::BufferRep>(N)),
|
||||||
OwnedBuffers(new void *[N]()), Next(Buffers), First(Buffers),
|
BufferCount(N), Finalizing{0}, OwnedBuffers(initArray<void *>(N)),
|
||||||
LiveBuffers(0) {
|
Next(Buffers), First(Buffers), LiveBuffers(0) {
|
||||||
|
if (Buffers == nullptr) {
|
||||||
|
Success = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (OwnedBuffers == nullptr) {
|
||||||
|
// Clean up the buffers we've already allocated.
|
||||||
|
for (auto B = Buffers, E = Buffers + BufferCount; B != E; ++B)
|
||||||
|
B->~BufferRep();
|
||||||
|
InternalFree(Buffers);
|
||||||
|
Success = false;
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < N; ++i) {
|
for (size_t i = 0; i < N; ++i) {
|
||||||
auto &T = Buffers[i];
|
auto &T = Buffers[i];
|
||||||
void *Tmp = InternalAlloc(BufferSize, nullptr, 64);
|
void *Tmp = InternalAlloc(BufferSize, nullptr, 64);
|
||||||
|
@ -109,6 +132,8 @@ BufferQueue::~BufferQueue() {
|
||||||
InternalFree(Buf.Data);
|
InternalFree(Buf.Data);
|
||||||
InternalFree(Buf.Extents);
|
InternalFree(Buf.Extents);
|
||||||
}
|
}
|
||||||
delete[] Buffers;
|
for (auto B = Buffers, E = Buffers + BufferCount; B != E; ++B)
|
||||||
delete[] OwnedBuffers;
|
B->~BufferRep();
|
||||||
|
InternalFree(Buffers);
|
||||||
|
InternalFree(OwnedBuffers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ public:
|
||||||
BufferExtents *Extents;
|
BufferExtents *Extents;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
|
||||||
struct BufferRep {
|
struct BufferRep {
|
||||||
// The managed buffer.
|
// The managed buffer.
|
||||||
Buffer Buff;
|
Buffer Buff;
|
||||||
|
@ -49,6 +48,7 @@ private:
|
||||||
bool Used = false;
|
bool Used = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
// This models a ForwardIterator. |T| Must be either a `Buffer` or `const
|
// This models a ForwardIterator. |T| Must be either a `Buffer` or `const
|
||||||
// Buffer`. Note that we only advance to the "used" buffers, when
|
// Buffer`. Note that we only advance to the "used" buffers, when
|
||||||
// incrementing, so that at dereference we're always at a valid point.
|
// incrementing, so that at dereference we're always at a valid point.
|
||||||
|
|
Loading…
Reference in New Issue