General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

89 rivejä
1.9 KiB

#include <gp/algorithms/foreach.hpp>
#include <gp/utils/allocators/buddy.hpp>
#include <gp/containers/array.hpp>
#include <gp/ipc/envelope/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::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::system::simple_scheduling sched{};
gp::system::system& sys = *(new(alloc.allocate(sizeof(gp::system::system))) gp::system::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{});