|
|
@ -12,6 +12,9 @@ |
|
|
|
namespace gp { |
|
|
|
namespace system { |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Represent the different execution states a process can be in |
|
|
|
*/ |
|
|
|
enum class process_status { |
|
|
|
inactive = 0, |
|
|
|
running = 1, |
|
|
@ -20,27 +23,38 @@ namespace gp { |
|
|
|
zombie = 4 |
|
|
|
}; |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief A process ID type |
|
|
|
*/ |
|
|
|
using pid_t = size_t; |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Represent and manages all the process info the scheduler doesn't need to be aware of |
|
|
|
* |
|
|
|
* Anything thread local is part of that |
|
|
|
*/ |
|
|
|
struct base_process_info { |
|
|
|
virtual void initialize() {} |
|
|
|
virtual void checkpoint() {} |
|
|
|
virtual void restore() {} |
|
|
|
virtual void switch_in() {} |
|
|
|
virtual void switch_out() {} |
|
|
|
virtual void cleanup() {} |
|
|
|
virtual ~base_process_info() {} |
|
|
|
virtual void initialize() {} //< An initializer
|
|
|
|
virtual void checkpoint() {} //< Creates a checkpoint if the feature is available
|
|
|
|
virtual void restore() {} //< Restores a checkpoint if the feature is available
|
|
|
|
virtual void switch_in() {} //< Called as the process is resuming
|
|
|
|
virtual void switch_out() {} //< Called as the process is paused
|
|
|
|
virtual void cleanup() {} //< Called before the process get destroyed
|
|
|
|
virtual ~base_process_info() {} //< Called as the process is destroyed
|
|
|
|
}; |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Represents the data used for scheduling and managing a process resources. |
|
|
|
*/ |
|
|
|
struct process_data{ |
|
|
|
pid_t pid; |
|
|
|
gp::function<void()> fn; |
|
|
|
void* stack; |
|
|
|
size_t stack_sz; |
|
|
|
gp::system::process_status state; |
|
|
|
std::atomic_bool is_running; |
|
|
|
[[no_unique_address]] gp::system::specifics::platform_data specifics; |
|
|
|
gp::unique_ptr<base_process_info> info; |
|
|
|
pid_t pid; //< The current pid
|
|
|
|
gp::function<void()> fn; //< Whatever there is to execute
|
|
|
|
void* stack; //< The stack lower bound pointer
|
|
|
|
size_t stack_sz; //< The stack size in bytes
|
|
|
|
gp::system::process_status state; //< The current process' state
|
|
|
|
std::atomic_bool is_running; //< Whenever the process is currently using execution time
|
|
|
|
[[no_unique_address]] gp::system::specifics::platform_data specifics; //< The special bits used to handle context switching
|
|
|
|
gp::unique_ptr<base_process_info> info; //< Other data related to processes but not to scheduling
|
|
|
|
|
|
|
|
process_data(gp::function<void()> _fn, void* _stack, size_t _stack_sz, gp::unique_ptr<base_process_info>&& _info) |
|
|
|
: fn(_fn) |
|
|
|