thread.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include <cstddef>
  3. #include <string>
  4. #include <stdint.h>
  5. #include <sys/types.h>
  6. #include <types/types.h>
  7. #include <kernel/signal.hpp>
  8. #include <kernel/user/thread_local.hpp>
  9. namespace kernel::task {
  10. using tid_t = std::size_t;
  11. struct thread {
  12. public:
  13. using thd_attr_t = uint32_t;
  14. static constexpr thd_attr_t SYSTEM = 0x01;
  15. static constexpr thd_attr_t READY = 0x02;
  16. static constexpr thd_attr_t STOPPED = 0x04;
  17. static constexpr thd_attr_t ZOMBIE = 0x08;
  18. static constexpr thd_attr_t ISLEEP = 0x10;
  19. static constexpr thd_attr_t USLEEP = 0x20;
  20. private:
  21. struct kernel_stack {
  22. std::byte* stack_base;
  23. uint32_t* esp;
  24. kernel_stack();
  25. kernel_stack(const kernel_stack& other);
  26. kernel_stack(kernel_stack&& other);
  27. ~kernel_stack();
  28. };
  29. public:
  30. kernel_stack kstack;
  31. pid_t owner;
  32. thd_attr_t attr;
  33. signal_list signals;
  34. int* __user set_child_tid {};
  35. int* __user clear_child_tid {};
  36. std::string name {};
  37. // TODO: LONG MODE
  38. // segment_descriptor tls_desc {};
  39. explicit thread(std::string name, pid_t owner);
  40. thread(const thread& val, pid_t owner);
  41. int set_thread_area(user::user_desc* ptr);
  42. int load_thread_area() const;
  43. void set_attr(thd_attr_t new_attr);
  44. void send_signal(signal_list::signo_type signal);
  45. thread(thread&& val) = default;
  46. tid_t tid() const;
  47. bool operator<(const thread& rhs) const;
  48. bool operator==(const thread& rhs) const;
  49. };
  50. } // namespace kernel::task