Browse Source

Added a process_info abstraction

channel
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
24ef19555d
4 changed files with 22 additions and 14 deletions
  1. +2
    -2
      Makefile
  2. +16
    -8
      include/gp/pointers.hpp
  3. +1
    -1
      include/gp/vfs/process_data.hpp
  4. +3
    -3
      include/gp/vfs/system.hpp

+ 2
- 2
Makefile View File

@ -1,5 +1,5 @@
CXX= clang++-10
CXXFLAGS= --std=c++20 -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=100000 -DNO_BENCH=0 -pedantic \
CXX= clang++
CXXFLAGS= --std=c++2a -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=100000 -DNO_BENCH=0 -pedantic \
-fprofile-instr-generate -fcoverage-mapping -Wno-unknown-attributes -fno-omit-frame-pointer \ -fprofile-instr-generate -fcoverage-mapping -Wno-unknown-attributes -fno-omit-frame-pointer \
# -fsanitize=address -fsanitize-blacklist=blacklist.txt # -fsanitize=address -fsanitize-blacklist=blacklist.txt

+ 16
- 8
include/gp/pointers.hpp View File

@ -13,7 +13,7 @@ namespace gp {
gp::allocator& owner; gp::allocator& owner;
unique_ptr(T* _data, gp::allocator& _owner) unique_ptr(T* _data, gp::allocator& _owner)
: data(data)
: data(_data)
, owner(_owner) , owner(_owner)
{} {}
@ -25,19 +25,23 @@ namespace gp {
} }
public: public:
template<typename ...U> template<typename ...U>
unique_ptr make(gp::allocator& owner, U&&... args) {
k">static unique_ptr make(gp::allocator& owner, U&&... args) {
auto ptr = owner.allocate(sizeof(T)); auto ptr = owner.allocate(sizeof(T));
return unique_ptr(new(ptr) T(gp::forward<U>(args)...), owner); return unique_ptr(new(ptr) T(gp::forward<U>(args)...), owner);
} }
T& operator->() {
return o">*data;
T* operator->() {
return data;
} }
T& operator*() { T& operator*() {
return *data; return *data;
} }
operator bool() {
return data != nullptr;
}
unique_ptr(unique_ptr&) = delete; unique_ptr(unique_ptr&) = delete;
unique_ptr(unique_ptr&& oth) unique_ptr(unique_ptr&& oth)
@ -67,7 +71,7 @@ namespace gp {
gp::allocator& owner; gp::allocator& owner;
shared_ptr(T* _data, gp::allocator& _owner) shared_ptr(T* _data, gp::allocator& _owner)
: data(data)
: data(_data)
, owner(_owner) , owner(_owner)
{} {}
@ -83,7 +87,7 @@ namespace gp {
} }
public: public:
template<typename ...U> template<typename ...U>
shared_ptr make(gp::allocator& owner, U&&... args) {
k">static shared_ptr make(gp::allocator& owner, U&&... args) {
auto ptr = owner.allocate(sizeof(T)); auto ptr = owner.allocate(sizeof(T));
auto shared_atomic = owner.allocate(sizeof(std::atomic_int)); auto shared_atomic = owner.allocate(sizeof(std::atomic_int));
refcounter = new(shared_atomic) std::atomic_int(); refcounter = new(shared_atomic) std::atomic_int();
@ -91,14 +95,18 @@ namespace gp {
return shared_ptr(new(ptr) T(gp::forward<U>(args)...), owner); return shared_ptr(new(ptr) T(gp::forward<U>(args)...), owner);
} }
T& operator->() {
return o">*data;
T* operator->() {
return data;
} }
T& operator*() { T& operator*() {
return *data; return *data;
} }
operator bool() {
return data != nullptr;
}
shared_ptr(shared_ptr& oth) { shared_ptr(shared_ptr& oth) {
oth.refcounter->fetch_add(1, std::memory_order::acquire); oth.refcounter->fetch_add(1, std::memory_order::acquire);

+ 1
- 1
include/gp/vfs/process_data.hpp View File

@ -47,7 +47,7 @@ namespace gp {
, stack_sz(_stack_sz) , stack_sz(_stack_sz)
, state(gp::process_status::inactive) , state(gp::process_status::inactive)
, specifics(gp::buffer<char>{(char*)stack, stack_sz}) , specifics(gp::buffer<char>{(char*)stack, stack_sz})
, info(_info)
, info(gp::move(_info))
{} {}
process_data(process_data&& v) process_data(process_data&& v)

+ 3
- 3
include/gp/vfs/system.hpp View File

@ -46,7 +46,7 @@ public:
stack_estimate = gp::buffer<char>{seed, (size_t)(gp_config::limits::process_stack*page_cnt)}; stack_estimate = gp::buffer<char>{seed, (size_t)(gp_config::limits::process_stack*page_cnt)};
} }
main_context.value = (process_data*)system_allocator.get().allocate(sizeof(process_data)); main_context.value = (process_data*)system_allocator.get().allocate(sizeof(process_data));
new(main_context.value) process_data(gp::function<void()>([]() -> void{}, nullopt), stack_estimate.begin().data, stack_estimate.size());
new(main_context.value) process_data(gp::function<void()>([]() -> void{}, nullopt), stack_estimate.begin().data, stack_estimate.size(), gp::unique_ptr<base_process_info>::make(system_allocator));
gp_config::assertion(main_context.value != nullptr, "failed to allocate return to main switch"); gp_config::assertion(main_context.value != nullptr, "failed to allocate return to main switch");
scheme.link(*this); scheme.link(*this);
} }
@ -57,7 +57,7 @@ public:
gp_config::assertion(stack != nullptr, "failed to allocate a stack"); gp_config::assertion(stack != nullptr, "failed to allocate a stack");
process_data* created_process = (process_data*)system_allocator.get().allocate(sizeof(process_data)); process_data* created_process = (process_data*)system_allocator.get().allocate(sizeof(process_data));
gp_config::assertion(stack != nullptr, "failed to allocate a process data"); gp_config::assertion(stack != nullptr, "failed to allocate a process data");
new(created_process) process_data(fn, stack, stack_sz);
new(created_process) process_data(fn, stack, stack_sz, gp::unique_ptr<base_process_info>::make(system_allocator));
topic_list::node_ptr pp = (topic_list::node_ptr)system_allocator.get().allocate( topic_list::node_ptr pp = (topic_list::node_ptr)system_allocator.get().allocate(
sizeof(topic_list::node) sizeof(topic_list::node)
@ -92,7 +92,7 @@ public:
scheduler::scheduler(class system& v, size_t token) scheduler::scheduler(class system& v, size_t token)
: id(token) : id(token)
, sys(v) , sys(v)
, main_context_data{gp::function<void()>{[](){}, v.system_allocator}, nullptr, size_t(0)}
, main_context_data{gp::function<void()>{[](){}, v.system_allocator}, nullptr, size_t(0), gp::unique_ptr<base_process_info>::make(v.system_allocator)}
, main_context() , main_context()
{ {
main_context.value = &main_context_data; main_context.value = &main_context_data;

Loading…
Cancel
Save