Implement getBytes()
This commit is contained in:
21
RootSet.cpp
21
RootSet.cpp
@@ -1,4 +1,5 @@
|
||||
#include "RootSet.h"
|
||||
#include "Internal.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
@@ -9,10 +10,13 @@
|
||||
|
||||
struct RootSet::ThreadSafeHandle::Impl {
|
||||
|
||||
static int sizeForCapacity(int capacity) {
|
||||
return sizeof(Impl) + sizeof(int64_t) * capacity +
|
||||
sizeof(uint32_t) * capacity;
|
||||
}
|
||||
|
||||
static Impl *create(int capacity) {
|
||||
int size =
|
||||
sizeof(Impl) + sizeof(int64_t) * capacity + sizeof(uint32_t) * capacity;
|
||||
auto *result = (Impl *)malloc(size);
|
||||
auto *result = (Impl *)safe_malloc(sizeForCapacity(capacity));
|
||||
result->capacity = capacity;
|
||||
return result;
|
||||
}
|
||||
@@ -62,9 +66,10 @@ struct RootSet::Impl {
|
||||
auto *tmp = i;
|
||||
i = i->next;
|
||||
|
||||
free(tmp);
|
||||
safe_free(tmp, ThreadSafeHandle::Impl::sizeForCapacity(tmp->capacity));
|
||||
}
|
||||
free(handle.load(std::memory_order_relaxed));
|
||||
auto h = handle.load(std::memory_order_relaxed);
|
||||
safe_free(h, ThreadSafeHandle::Impl::sizeForCapacity(h->capacity));
|
||||
}
|
||||
|
||||
void add(uint32_t node, int64_t version) {
|
||||
@@ -116,7 +121,7 @@ struct RootSet::Impl {
|
||||
1] <= oldestVersion) {
|
||||
auto *tmp = firstToFree;
|
||||
firstToFree = firstToFree->next;
|
||||
free(tmp);
|
||||
safe_free(tmp, ThreadSafeHandle::Impl::sizeForCapacity(tmp->capacity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,11 +169,11 @@ RootSet::ThreadSafeHandle RootSet::getThreadSafeHandle() const {
|
||||
const uint32_t *RootSet::roots() const { return impl->roots(); }
|
||||
int RootSet::rootCount() const { return impl->rootCount(); }
|
||||
|
||||
RootSet::RootSet() : impl(new(malloc(sizeof(Impl))) Impl()) {}
|
||||
RootSet::RootSet() : impl(new(safe_malloc(sizeof(Impl))) Impl()) {}
|
||||
|
||||
RootSet::~RootSet() {
|
||||
impl->~Impl();
|
||||
free(impl);
|
||||
safe_free(impl, sizeof(*impl));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ROOTSET_TESTS
|
||||
|
Reference in New Issue
Block a user