General Purpose library for Freestanding C++ and POSIX systems
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

89 linhas
1.9 KiB

#include <gp/algorithms/foreach.hpp>
#include <gp/utils/allocators/buddy.hpp>
#include <gp/containers/array.hpp>
#include <gp/ipc/enveloppe/cbor.hpp>
#include <gp/system/system.hpp>
#include <gp/system/scheduling/simple_scheduling.hpp>
#include "test_scaffold.h"
#include <atomic>
#include <memory>
#include <vector>
#include <random>
#include <thread>
#include <chrono>
#include <iostream>
using namespace std::chrono_literals;
using weight_t = float;
template<typename T>
struct node {
node(T _value)
: value(_value)
{}
std::vector<std::pair<std::shared_ptr<node>, weight_t>> next_links;
T value;
};
struct point {
float x, y;
};
std::thread* leaver_4989487;
std::atomic_int quit_signal_4989487 = 0;
gp::system* sys_ptr_4989487;
struct channel_test : public test_scaffold {
channel_test() {
name = __FILE__ ":1";
}
std::unique_ptr<
gp::array<char, 4096*512>,
std::default_delete<gp::array<char, 4096*512>>
> store = std::make_unique<gp::array<char, 4096*512>>();
gp::buddy<> alloc{&*store->begin(), store->size()};
gp::simple_scheduling sched{};
gp::system& sys = *(new(alloc.allocate(sizeof(gp::system))) gp::system{alloc, sched});
struct terminator{};
virtual int run() {
std::atomic_int a = 0;
sys_ptr_4989487 = &sys;
sys.spawn(gp::function<void()>{[&](){
a.fetch_add(1);
}, alloc});
sys.spawn(gp::function<void()>{[&](){
while(!quit_signal_4989487.load()) {
std::this_thread::sleep_for(500us);
}
pthread_exit(nullptr);
}, alloc});
sys.run([](gp::function<void(void)> a) {
leaver_4989487 = new std::thread(a);
});
leaver_4989487->detach();
std::this_thread::sleep_for(16ms);
gp_config::assertion(a.load(), "did not increment (aka run the fiber)");
return 0;
}
virtual ~channel_test() {
quit_signal_4989487.store(1);
std::this_thread::sleep_for(1s);
}
};
append_test dummy_hke41r43(new channel_test{});