General Purpose library for Freestanding C++ and POSIX systems
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

68 righe
1.4 KiB

  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. }