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.

88 rivejä
1.9 KiB

4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
  1. #include <gp/algorithms/foreach.hpp>
  2. #include <gp/utils/allocators/buddy.hpp>
  3. #include <gp/containers/array.hpp>
  4. #include <gp/ipc/envelope/cbor.hpp>
  5. #include <gp/system/system.hpp>
  6. #include <gp/system/scheduling/simple_scheduling.hpp>
  7. #include "test_scaffold.h"
  8. #include <atomic>
  9. #include <memory>
  10. #include <vector>
  11. #include <random>
  12. #include <thread>
  13. #include <chrono>
  14. #include <iostream>
  15. using namespace std::chrono_literals;
  16. using weight_t = float;
  17. template<typename T>
  18. struct node {
  19. node(T _value)
  20. : value(_value)
  21. {}
  22. std::vector<std::pair<std::shared_ptr<node>, weight_t>> next_links;
  23. T value;
  24. };
  25. struct point {
  26. float x, y;
  27. };
  28. std::thread* leaver_4989487;
  29. std::atomic_int quit_signal_4989487 = 0;
  30. gp::system::system* sys_ptr_4989487;
  31. struct channel_test : public test_scaffold {
  32. channel_test() {
  33. name = __FILE__ ":1";
  34. }
  35. std::unique_ptr<
  36. gp::array<char, 4096*512>,
  37. std::default_delete<gp::array<char, 4096*512>>
  38. > store = std::make_unique<gp::array<char, 4096*512>>();
  39. gp::buddy<> alloc{&*store->begin(), store->size()};
  40. gp::system::simple_scheduling sched{};
  41. gp::system::system& sys = *(new(alloc.allocate(sizeof(gp::system::system))) gp::system::system{alloc, sched});
  42. struct terminator{};
  43. virtual int run() {
  44. std::atomic_int a = 0;
  45. sys_ptr_4989487 = &sys;
  46. sys.spawn(gp::function<void()>{[&](){
  47. a.fetch_add(1);
  48. }, alloc});
  49. sys.spawn(gp::function<void()>{[&](){
  50. while(!quit_signal_4989487.load()) {
  51. std::this_thread::sleep_for(500us);
  52. }
  53. pthread_exit(nullptr);
  54. }, alloc});
  55. sys.run([](gp::function<void(void)> a) {
  56. leaver_4989487 = new std::thread(a);
  57. });
  58. leaver_4989487->detach();
  59. std::this_thread::sleep_for(16ms);
  60. gp_config::assertion(a.load(), "did not increment (aka run the fiber)");
  61. return 0;
  62. }
  63. virtual ~channel_test() {
  64. quit_signal_4989487.store(1);
  65. std::this_thread::sleep_for(1s);
  66. }
  67. };
  68. append_test dummy_hke41r43(new channel_test{});