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.

68 regels
1.4 KiB

3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
  1. #pragma once
  2. #include "gp_config.hpp"
  3. #include "gp/functional/function.hpp"
  4. #include "gp/containers/indexed_array.hpp"
  5. #include "gp/utils/pointers.hpp"
  6. #include "gp/ipc/file_description.hpp"
  7. #include "gp/system/platforms/platform_autopicker.hpp"
  8. #include <atomic>
  9. namespace gp {
  10. enum class process_status {
  11. inactive = 0,
  12. running = 1,
  13. waiting = 2,
  14. finished = 3,
  15. zombie = 4
  16. };
  17. using pid_t = size_t;
  18. struct base_process_info {
  19. virtual void initialize() {}
  20. virtual void checkpoint() {}
  21. virtual void restore() {}
  22. virtual void switch_in() {}
  23. virtual void switch_out() {}
  24. virtual void cleanup() {}
  25. virtual ~base_process_info() {}
  26. };
  27. struct process_data{
  28. pid_t pid;
  29. gp::function<void()> fn;
  30. void* stack;
  31. size_t stack_sz;
  32. gp::process_status state;
  33. std::atomic_bool is_running;
  34. [[no_unique_address]] gp::specifics::platform_data specifics;
  35. gp::unique_ptr<base_process_info> info;
  36. process_data(gp::function<void()> _fn, void* _stack, size_t _stack_sz, gp::unique_ptr<base_process_info>&& _info)
  37. : fn(_fn)
  38. , stack(_stack)
  39. , stack_sz(_stack_sz)
  40. , state(gp::process_status::inactive)
  41. , specifics(gp::buffer<char>{(char*)stack, stack_sz})
  42. , info(gp::move(_info))
  43. {}
  44. process_data(process_data&& v)
  45. : fn(v.fn)
  46. , stack(v.stack)
  47. , stack_sz(v.stack_sz)
  48. , state(v.state)
  49. , specifics(v.specifics)
  50. , info(gp::move(v.info))
  51. {}
  52. ~process_data() {
  53. if(info) {
  54. info->cleanup();
  55. }
  56. }
  57. };
  58. }