1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

updated vm (breaking compatibility)

- updated vm
- new actor scheduler
- updated tonlib
- updated DNS smartcontract
This commit is contained in:
ton 2020-02-28 14:28:47 +04:00
parent 9e4816e7f6
commit e27fb1e09c
100 changed files with 3692 additions and 1299 deletions

View file

@ -14,7 +14,7 @@
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2019 Telegram Systems LLP
Copyright 2017-2020 Telegram Systems LLP
*/
#include "td/utils/MpmcWaiter.h"
#include "td/utils/port/sleep.h"
@ -25,21 +25,22 @@
#include <atomic>
#if !TD_THREAD_UNSUPPORTED
TEST(MpmcWaiter, stress_one_one) {
template <class W>
void test_waiter_stress_one_one() {
td::Stage run;
td::Stage check;
std::vector<td::thread> threads;
std::atomic<size_t> value{0};
size_t write_cnt = 10;
td::unique_ptr<td::MpmcWaiter> waiter;
td::unique_ptr<W> waiter;
size_t threads_n = 2;
for (size_t i = 0; i < threads_n; i++) {
threads.push_back(td::thread([&, id = static_cast<td::uint32>(i)] {
for (td::uint64 round = 1; round < 100000; round++) {
if (id == 0) {
value = 0;
waiter = td::make_unique<td::MpmcWaiter>();
waiter = td::make_unique<W>();
write_cnt = td::Random::fast(1, 10);
}
run.wait(round * threads_n);
@ -49,17 +50,19 @@ TEST(MpmcWaiter, stress_one_one) {
waiter->notify();
}
} else {
int yields = 0;
typename W::Slot slot;
waiter->init_slot(slot, id);
for (size_t i = 1; i <= write_cnt; i++) {
while (true) {
auto x = value.load(std::memory_order_relaxed);
if (x >= i) {
break;
}
yields = waiter->wait(yields, id);
waiter->wait(slot);
}
yields = waiter->stop_wait(yields, id);
waiter->stop_wait(slot);
}
waiter->stop_wait(slot);
}
check.wait(round * threads_n);
}
@ -69,7 +72,15 @@ TEST(MpmcWaiter, stress_one_one) {
thread.join();
}
}
TEST(MpmcWaiter, stress) {
TEST(MpmcEagerWaiter, stress_one_one) {
test_waiter_stress_one_one<td::MpmcEagerWaiter>();
}
TEST(MpmcSleepyWaiter, stress_one_one) {
test_waiter_stress_one_one<td::MpmcSleepyWaiter>();
}
template <class W>
void test_waiter_stress() {
td::Stage run;
td::Stage check;
@ -81,7 +92,7 @@ TEST(MpmcWaiter, stress) {
size_t end_pos;
size_t write_cnt;
size_t threads_n = 20;
td::unique_ptr<td::MpmcWaiter> waiter;
td::unique_ptr<W> waiter;
for (size_t i = 0; i < threads_n; i++) {
threads.push_back(td::thread([&, id = static_cast<td::uint32>(i)] {
for (td::uint64 round = 1; round < 1000; round++) {
@ -92,7 +103,7 @@ TEST(MpmcWaiter, stress) {
end_pos = write_n * write_cnt;
write_pos = 0;
read_pos = 0;
waiter = td::make_unique<td::MpmcWaiter>();
waiter = td::make_unique<W>();
}
run.wait(round * threads_n);
if (id <= write_n) {
@ -104,21 +115,26 @@ TEST(MpmcWaiter, stress) {
waiter->notify();
}
} else if (id > 10 && id - 10 <= read_n) {
int yields = 0;
typename W::Slot slot;
waiter->init_slot(slot, id);
while (true) {
auto x = read_pos.load(std::memory_order_relaxed);
if (x == end_pos) {
waiter->stop_wait(slot);
break;
}
if (x == write_pos.load(std::memory_order_relaxed)) {
yields = waiter->wait(yields, id);
waiter->wait(slot);
continue;
}
yields = waiter->stop_wait(yields, id);
waiter->stop_wait(slot);
read_pos.compare_exchange_strong(x, x + 1, std::memory_order_relaxed);
}
}
check.wait(round * threads_n);
if (id == 0) {
waiter->close();
}
}
}));
}
@ -126,4 +142,10 @@ TEST(MpmcWaiter, stress) {
thread.join();
}
}
TEST(MpmcEagerWaiter, stress_multi) {
test_waiter_stress<td::MpmcEagerWaiter>();
}
TEST(MpmcSleepyWaiter, stress_multi) {
test_waiter_stress<td::MpmcSleepyWaiter>();
}
#endif // !TD_THREAD_UNSUPPORTED