mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
fix compilation errors of different platforms and move to c++20
This commit is contained in:
parent
0780a6a1b5
commit
1c66852842
10 changed files with 67 additions and 25 deletions
|
@ -79,7 +79,7 @@ else()
|
||||||
set(HAVE_SSE42 FALSE)
|
set(HAVE_SSE42 FALSE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||||
set(CMAKE_CXX_EXTENSIONS FALSE)
|
set(CMAKE_CXX_EXTENSIONS FALSE)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "absl/strings/internal/str_format/parser.h"
|
|
||||||
#include "td/actor/actor.h"
|
#include "td/actor/actor.h"
|
||||||
|
|
||||||
namespace ton {
|
namespace ton {
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
#include "vm/dict.h"
|
#include "vm/dict.h"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
|
@ -2010,7 +2011,7 @@ TEST(TonDb, CompactArrayOld) {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
ton_db->commit_transaction(std::move(txn));
|
ton_db->commit_transaction(std::move(txn));
|
||||||
};
|
};
|
||||||
auto smart = txn->begin_smartcontract("");
|
auto smart = txn->begin_smartcontract();
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
txn->commit_smartcontract(std::move(smart));
|
txn->commit_smartcontract(std::move(smart));
|
||||||
};
|
};
|
||||||
|
@ -2037,7 +2038,7 @@ TEST(TonDb, CompactArrayOld) {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
ton_db->commit_transaction(std::move(txn));
|
ton_db->commit_transaction(std::move(txn));
|
||||||
};
|
};
|
||||||
auto smart = txn->begin_smartcontract("");
|
auto smart = txn->begin_smartcontract();
|
||||||
//smart->validate_meta();
|
//smart->validate_meta();
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
txn->commit_smartcontract(std::move(smart));
|
txn->commit_smartcontract(std::move(smart));
|
||||||
|
@ -2058,7 +2059,7 @@ TEST(TonDb, CompactArrayOld) {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
ton_db->abort_transaction(std::move(txn));
|
ton_db->abort_transaction(std::move(txn));
|
||||||
};
|
};
|
||||||
auto smart = txn->begin_smartcontract("");
|
auto smart = txn->begin_smartcontract();
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
txn->abort_smartcontract(std::move(smart));
|
txn->abort_smartcontract(std::move(smart));
|
||||||
};
|
};
|
||||||
|
@ -2219,7 +2220,7 @@ TEST(TonDb, CellStat) {
|
||||||
ASSERT_EQ(stat.cells, new_stat.get_stat().cells);
|
ASSERT_EQ(stat.cells, new_stat.get_stat().cells);
|
||||||
ASSERT_EQ(stat.bits, new_stat.get_stat().bits);
|
ASSERT_EQ(stat.bits, new_stat.get_stat().bits);
|
||||||
|
|
||||||
CHECK(usage_tree.unique());
|
CHECK(usage_tree.use_count() == 1);
|
||||||
usage_tree.reset();
|
usage_tree.reset();
|
||||||
td::Ref<vm::Cell> C, BC, C_proof;
|
td::Ref<vm::Cell> C, BC, C_proof;
|
||||||
std::shared_ptr<vm::CellUsageTree> usage_tree_B;
|
std::shared_ptr<vm::CellUsageTree> usage_tree_B;
|
||||||
|
|
|
@ -76,7 +76,7 @@ struct CellHash {
|
||||||
|
|
||||||
inline size_t cell_hash_slice_hash(td::Slice hash) {
|
inline size_t cell_hash_slice_hash(td::Slice hash) {
|
||||||
// use offset 8, because in db keys are grouped by first bytes.
|
// use offset 8, because in db keys are grouped by first bytes.
|
||||||
return td::as<size_t>(hash.ubegin() + 8);
|
return td::as<size_t>(hash.substr(8, 8).ubegin());
|
||||||
}
|
}
|
||||||
namespace std {
|
namespace std {
|
||||||
template <>
|
template <>
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "td/utils/HashMap.h"
|
#include "td/utils/HashMap.h"
|
||||||
#include "td/utils/HashSet.h"
|
#include "td/utils/HashSet.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#if TD_PORT_POSIX
|
#if TD_PORT_POSIX
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -98,7 +100,7 @@ class ArenaPrunnedCellCreator : public ExtCellCreator {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static std::unique_ptr<char, Deleter> alloc() {
|
static std::unique_ptr<char, Deleter> alloc() {
|
||||||
auto ptr = reinterpret_cast<char *>(malloc(batch_size)));
|
auto ptr = reinterpret_cast<char *>(malloc(batch_size));
|
||||||
CHECK(ptr != nullptr);
|
CHECK(ptr != nullptr);
|
||||||
return std::unique_ptr<char, Deleter>(ptr);
|
return std::unique_ptr<char, Deleter>(ptr);
|
||||||
}
|
}
|
||||||
|
@ -292,7 +294,7 @@ struct CellInfoHashTableDense {
|
||||||
}
|
}
|
||||||
template <class Iterator>
|
template <class Iterator>
|
||||||
void init_from(Iterator begin, Iterator end) {
|
void init_from(Iterator begin, Iterator end) {
|
||||||
auto size = std::distance(begin, end);
|
auto size = td::narrow_cast<size_t>(std::distance(begin, end));
|
||||||
dense_ht_buckets_ = std::max(size_t(1), size_t(size / 8));
|
dense_ht_buckets_ = std::max(size_t(1), size_t(size / 8));
|
||||||
|
|
||||||
std::vector<size_t> offsets(dense_ht_buckets_ + 2);
|
std::vector<size_t> offsets(dense_ht_buckets_ + 2);
|
||||||
|
@ -438,16 +440,16 @@ class CellStorage {
|
||||||
add_stat("ht.size", size);
|
add_stat("ht.size", size);
|
||||||
add_stat("ht.load", double(size) / std::max(1.0, double(capacity)));
|
add_stat("ht.load", double(size) / std::max(1.0, double(capacity)));
|
||||||
}
|
}
|
||||||
CHECK(stats.roots_total_count == local_roots_.size());
|
CHECK(td::narrow_cast<size_t>(stats.roots_total_count) == local_roots_.size());
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
void apply_stats_diff(DynamicBagOfCellsDb::Stats diff) {
|
void apply_stats_diff(DynamicBagOfCellsDb::Stats diff) {
|
||||||
auto unique_access = local_access_.lock();
|
auto unique_access = local_access_.lock();
|
||||||
stats_.apply_diff(diff);
|
stats_.apply_diff(diff);
|
||||||
CHECK(stats_.roots_total_count == local_roots_.size());
|
CHECK(td::narrow_cast<size_t>(stats_.roots_total_count) == local_roots_.size());
|
||||||
size_t cells_count{0};
|
size_t cells_count{0};
|
||||||
for_each_bucket(0, [&](size_t bucket_id, auto &bucket) { cells_count += bucket.infos_.size(); });
|
for_each_bucket(0, [&](size_t bucket_id, auto &bucket) { cells_count += bucket.infos_.size(); });
|
||||||
CHECK(stats_.cells_total_count == cells_count);
|
CHECK(td::narrow_cast<size_t>(stats_.cells_total_count) == cells_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
td::Result<Ref<DataCell>> load_cell(const CellHash &hash) const {
|
td::Result<Ref<DataCell>> load_cell(const CellHash &hash) const {
|
||||||
|
@ -541,8 +543,8 @@ class CellStorage {
|
||||||
DefaultPrunnedCellCreator default_pc_creator;
|
DefaultPrunnedCellCreator default_pc_creator;
|
||||||
|
|
||||||
auto timer = td::Timer();
|
auto timer = td::Timer();
|
||||||
size_t cell_count{0};
|
td::int64 cell_count{0};
|
||||||
size_t desc_count{0};
|
td::int64 desc_count{0};
|
||||||
if (options.use_less_memory_during_creation) {
|
if (options.use_less_memory_during_creation) {
|
||||||
auto [new_cell_count, new_desc_count] = parallel_scan_cells(
|
auto [new_cell_count, new_desc_count] = parallel_scan_cells(
|
||||||
default_pc_creator, options.use_arena,
|
default_pc_creator, options.use_arena,
|
||||||
|
|
|
@ -113,7 +113,8 @@ class TonDbTransactionImpl;
|
||||||
using TonDbTransaction = std::unique_ptr<TonDbTransactionImpl>;
|
using TonDbTransaction = std::unique_ptr<TonDbTransactionImpl>;
|
||||||
class TonDbTransactionImpl {
|
class TonDbTransactionImpl {
|
||||||
public:
|
public:
|
||||||
SmartContractDb begin_smartcontract(td::Slice hash = {});
|
|
||||||
|
SmartContractDb begin_smartcontract(td::Slice hash = std::string(32, '\0'));
|
||||||
|
|
||||||
void commit_smartcontract(SmartContractDb txn);
|
void commit_smartcontract(SmartContractDb txn);
|
||||||
void commit_smartcontract(SmartContractDiff txn);
|
void commit_smartcontract(SmartContractDiff txn);
|
||||||
|
|
|
@ -2,12 +2,24 @@
|
||||||
#include "td/actor/core/ActorTypeStat.h"
|
#include "td/actor/core/ActorTypeStat.h"
|
||||||
#include "td/actor/core/Scheduler.h"
|
#include "td/actor/core/Scheduler.h"
|
||||||
#include "td/utils/port/thread_local.h"
|
#include "td/utils/port/thread_local.h"
|
||||||
#include <cxxabi.h>
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
#include <optional>
|
||||||
|
#include "td/utils/port/platform.h"
|
||||||
|
|
||||||
|
#ifdef __has_include
|
||||||
|
#if __has_include(<cxxabi.h>)
|
||||||
|
#include <cxxabi.h>
|
||||||
|
#define CXXABI_AVAILABLE 1
|
||||||
|
#else
|
||||||
|
#define CXXABI_AVAILABLE 0
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define CXXABI_AVAILABLE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace actor {
|
namespace actor {
|
||||||
|
@ -82,6 +94,7 @@ ActorTypeStatRef ActorTypeStatManager::get_actor_type_stat(td::uint32 id, Actor
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ActorTypeStatManager::get_class_name(const char *name) {
|
std::string ActorTypeStatManager::get_class_name(const char *name) {
|
||||||
|
#if CXXABI_AVAILABLE
|
||||||
int status;
|
int status;
|
||||||
char *real_name = abi::__cxa_demangle(name, nullptr, nullptr, &status);
|
char *real_name = abi::__cxa_demangle(name, nullptr, nullptr, &status);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
@ -91,6 +104,9 @@ std::string ActorTypeStatManager::get_class_name(const char *name) {
|
||||||
std::string result = real_name;
|
std::string result = real_name;
|
||||||
std::free(real_name);
|
std::free(real_name);
|
||||||
return result;
|
return result;
|
||||||
|
#else
|
||||||
|
return name;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorTypeStats ActorTypeStatManager::get_stats(double inv_ticks_per_second) {
|
ActorTypeStats ActorTypeStatManager::get_stats(double inv_ticks_per_second) {
|
||||||
|
|
|
@ -22,6 +22,10 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
int64 Clocks::monotonic_nano() {
|
||||||
|
auto duration = std::chrono::steady_clock::now().time_since_epoch();
|
||||||
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
|
||||||
|
}
|
||||||
|
|
||||||
double Clocks::monotonic() {
|
double Clocks::monotonic() {
|
||||||
// TODO write system specific functions, because std::chrono::steady_clock is steady only under Windows
|
// TODO write system specific functions, because std::chrono::steady_clock is steady only under Windows
|
||||||
|
|
|
@ -22,20 +22,22 @@
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
struct Clocks {
|
struct Clocks {
|
||||||
|
static int64 monotonic_nano();
|
||||||
|
|
||||||
static double monotonic();
|
static double monotonic();
|
||||||
|
|
||||||
static double system();
|
static double system();
|
||||||
|
|
||||||
static int tz_offset();
|
static int tz_offset();
|
||||||
|
|
||||||
#if defined(__i386__)
|
#if defined(__i386__) or defined(__M_IX86)
|
||||||
static __inline__ td::uint64 rdtsc(void) {
|
static uint64 rdtsc() {
|
||||||
unsigned long long int x;
|
unsigned long long int x;
|
||||||
__asm__ volatile("rdtsc" : "=A"(x));
|
__asm__ volatile("rdtsc" : "=A"(x));
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr td::uint64 rdtsc_frequency(void) {
|
static constexpr uint64 rdtsc_frequency() {
|
||||||
return 2000'000'000;
|
return 2000'000'000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,13 +48,13 @@ struct Clocks {
|
||||||
static constexpr double inv_ticks_per_second() {
|
static constexpr double inv_ticks_per_second() {
|
||||||
return 0.5e-9;
|
return 0.5e-9;
|
||||||
}
|
}
|
||||||
#elif defined(__x86_64__)
|
#elif defined(__x86_64__) or defined(__M_X64)
|
||||||
static __inline__ td::uint64 rdtsc(void) {
|
static uint64 rdtsc() {
|
||||||
unsigned hi, lo;
|
unsigned hi, lo;
|
||||||
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
|
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
|
||||||
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
|
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
|
||||||
}
|
}
|
||||||
static constexpr td::uint64 rdtsc_frequency(void) {
|
static constexpr uint64 rdtsc_frequency() {
|
||||||
return 2000'000'000;
|
return 2000'000'000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,13 +65,13 @@ struct Clocks {
|
||||||
static constexpr double inv_ticks_per_second() {
|
static constexpr double inv_ticks_per_second() {
|
||||||
return 0.5e-9;
|
return 0.5e-9;
|
||||||
}
|
}
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__) or defined(_M_ARM64)
|
||||||
static __inline__ td::uint64 rdtsc(void) {
|
static uint64 rdtsc() {
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
asm volatile("mrs %0, cntvct_el0" : "=r"(val));
|
asm volatile("mrs %0, cntvct_el0" : "=r"(val));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
static __inline__ td::uint64 rdtsc_frequency(void) {
|
static uint64 rdtsc_frequency() {
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
asm volatile("mrs %0, cntfrq_el0" : "=r"(val));
|
asm volatile("mrs %0, cntfrq_el0" : "=r"(val));
|
||||||
return val;
|
return val;
|
||||||
|
@ -79,6 +81,21 @@ struct Clocks {
|
||||||
return static_cast<double>(rdtsc_frequency());
|
return static_cast<double>(rdtsc_frequency());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double inv_ticks_per_second() {
|
||||||
|
return 1.0 / static_cast<double>(rdtsc_frequency());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static uint64 rdtsc() {
|
||||||
|
return monotonic_nano();
|
||||||
|
}
|
||||||
|
static uint64 rdtsc_frequency() {
|
||||||
|
return 1000'000'000;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double ticks_per_second() {
|
||||||
|
return static_cast<double>(rdtsc_frequency());
|
||||||
|
}
|
||||||
|
|
||||||
static double inv_ticks_per_second() {
|
static double inv_ticks_per_second() {
|
||||||
return 1.0 / static_cast<double>(rdtsc_frequency());
|
return 1.0 / static_cast<double>(rdtsc_frequency());
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include "db-utils.h"
|
#include "db-utils.h"
|
||||||
#include "td/db/RocksDb.h"
|
#include "td/db/RocksDb.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace rocksdb {
|
namespace rocksdb {
|
||||||
class Statistics;
|
class Statistics;
|
||||||
class DB;
|
class DB;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue