#pragma once
|
|
|
|
#include "gp_config.hpp"
|
|
#include "gp/functional/function.hpp"
|
|
#include "gp/containers/indexed_array.hpp"
|
|
#include "gp/utils/pointers.hpp"
|
|
#include "gp/ipc/file_description.hpp"
|
|
#include "gp/system/platforms/platform_autopicker.hpp"
|
|
|
|
#include <atomic>
|
|
|
|
namespace gp {
|
|
namespace system {
|
|
|
|
enum class process_status {
|
|
inactive = 0,
|
|
running = 1,
|
|
waiting = 2,
|
|
finished = 3,
|
|
zombie = 4
|
|
};
|
|
|
|
using pid_t = size_t;
|
|
|
|
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() {}
|
|
};
|
|
|
|
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;
|
|
|
|
process_data(gp::function<void()> _fn, void* _stack, size_t _stack_sz, gp::unique_ptr<base_process_info>&& _info)
|
|
: fn(_fn)
|
|
, stack(_stack)
|
|
, stack_sz(_stack_sz)
|
|
, state(gp::system::process_status::inactive)
|
|
, specifics(gp::buffer<char>{(char*)stack, stack_sz})
|
|
, info(gp::move(_info))
|
|
{}
|
|
|
|
process_data(process_data&& v)
|
|
: fn(v.fn)
|
|
, stack(v.stack)
|
|
, stack_sz(v.stack_sz)
|
|
, state(v.state)
|
|
, specifics(v.specifics)
|
|
, info(gp::move(v.info))
|
|
{}
|
|
|
|
~process_data() {
|
|
if(info) {
|
|
info->cleanup();
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|