mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Merge branch 'testnet' into block-generation
This commit is contained in:
commit
e4e77c16c5
463 changed files with 29976 additions and 2517 deletions
|
@ -51,13 +51,6 @@ ValidatorSessionDescriptionImpl::ValidatorSessionDescriptionImpl(ValidatorSessio
|
|||
CHECK(it != rev_sources_.end());
|
||||
self_idx_ = it->second;
|
||||
|
||||
pdata_temp_ptr_ = 0;
|
||||
pdata_temp_size_ = 1 << 27;
|
||||
pdata_temp_ = new td::uint8[pdata_temp_size_];
|
||||
|
||||
pdata_perm_size_ = 1ull << 27;
|
||||
pdata_perm_ptr_ = 0;
|
||||
|
||||
for (auto &el : cache_) {
|
||||
Cached v{nullptr};
|
||||
el.store(v, std::memory_order_relaxed);
|
||||
|
@ -167,43 +160,11 @@ void ValidatorSessionDescriptionImpl::update_hash(const RootObject *obj, HashTyp
|
|||
}
|
||||
|
||||
void *ValidatorSessionDescriptionImpl::alloc(size_t size, size_t align, bool temp) {
|
||||
CHECK(align && !(align & (align - 1))); // align should be a power of 2
|
||||
auto get_padding = [&](const uint8_t* ptr) {
|
||||
return (-(size_t)ptr) & (align - 1);
|
||||
};
|
||||
if (temp) {
|
||||
pdata_temp_ptr_ += get_padding(pdata_temp_ + pdata_temp_ptr_);
|
||||
auto s = pdata_temp_ptr_;
|
||||
pdata_temp_ptr_ += size;
|
||||
CHECK(s + size <= pdata_temp_size_);
|
||||
return static_cast<void *>(pdata_temp_ + s);
|
||||
} else {
|
||||
while (true) {
|
||||
size_t idx = pdata_perm_ptr_ / pdata_perm_size_;
|
||||
if (idx < pdata_perm_.size()) {
|
||||
auto ptr = pdata_perm_[idx] + (pdata_perm_ptr_ % pdata_perm_size_);
|
||||
pdata_perm_ptr_ += get_padding(ptr);
|
||||
ptr += get_padding(ptr);
|
||||
pdata_perm_ptr_ += size;
|
||||
if (pdata_perm_ptr_ <= pdata_perm_.size() * pdata_perm_size_) {
|
||||
return static_cast<void *>(ptr);
|
||||
}
|
||||
}
|
||||
pdata_perm_.push_back(new td::uint8[pdata_perm_size_]);
|
||||
}
|
||||
}
|
||||
return (temp ? mem_temp_ : mem_perm_).alloc(size, align);
|
||||
}
|
||||
|
||||
bool ValidatorSessionDescriptionImpl::is_persistent(const void *ptr) const {
|
||||
if (ptr == nullptr) {
|
||||
return true;
|
||||
}
|
||||
for (auto &v : pdata_perm_) {
|
||||
if (ptr >= v && ptr <= v + pdata_perm_size_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return mem_perm_.contains(ptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<ValidatorSessionDescription> ValidatorSessionDescription::create(
|
||||
|
@ -211,6 +172,58 @@ std::unique_ptr<ValidatorSessionDescription> ValidatorSessionDescription::create
|
|||
return std::make_unique<ValidatorSessionDescriptionImpl>(std::move(opts), nodes, local_id);
|
||||
}
|
||||
|
||||
ValidatorSessionDescriptionImpl::MemPool::MemPool(size_t chunk_size) : chunk_size_(chunk_size) {
|
||||
}
|
||||
|
||||
ValidatorSessionDescriptionImpl::MemPool::~MemPool() {
|
||||
for (auto &v : data_) {
|
||||
delete[] v;
|
||||
}
|
||||
}
|
||||
|
||||
void *ValidatorSessionDescriptionImpl::MemPool::alloc(size_t size, size_t align) {
|
||||
CHECK(align && !(align & (align - 1))); // align should be a power of 2
|
||||
CHECK(size + align <= chunk_size_);
|
||||
auto get_padding = [&](const uint8_t* ptr) {
|
||||
return (-(size_t)ptr) & (align - 1);
|
||||
};
|
||||
while (true) {
|
||||
size_t idx = ptr_ / chunk_size_;
|
||||
if (idx < data_.size()) {
|
||||
auto ptr = data_[idx] + (ptr_ % chunk_size_);
|
||||
ptr_ += get_padding(ptr);
|
||||
ptr += get_padding(ptr);
|
||||
ptr_ += size;
|
||||
if (ptr_ <= data_.size() * chunk_size_) {
|
||||
return static_cast<void *>(ptr);
|
||||
} else {
|
||||
ptr_ = data_.size() * chunk_size_;
|
||||
}
|
||||
}
|
||||
data_.push_back(new td::uint8[chunk_size_]);
|
||||
}
|
||||
}
|
||||
|
||||
void ValidatorSessionDescriptionImpl::MemPool::clear() {
|
||||
while (data_.size() > 1) {
|
||||
delete[] data_.back();
|
||||
data_.pop_back();
|
||||
}
|
||||
ptr_ = 0;
|
||||
}
|
||||
|
||||
bool ValidatorSessionDescriptionImpl::MemPool::contains(const void* ptr) const {
|
||||
if (ptr == nullptr) {
|
||||
return true;
|
||||
}
|
||||
for (auto &v : data_) {
|
||||
if (ptr >= v && ptr <= v + chunk_size_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace validatorsession
|
||||
|
||||
} // namespace ton
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue