From 24ef19555dfdb96b05ed10f138cc37586e7ea3aa Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Sat, 3 Apr 2021 14:35:20 +0200 Subject: [PATCH] Added a process_info abstraction --- Makefile | 4 ++-- include/gp/pointers.hpp | 24 ++++++++++++++++-------- include/gp/vfs/process_data.hpp | 2 +- include/gp/vfs/system.hpp | 6 +++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 5e10bac..6566eaf 100644 --- a/Makefile +++ b/Makefile @@ -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 \ # -fsanitize=address -fsanitize-blacklist=blacklist.txt diff --git a/include/gp/pointers.hpp b/include/gp/pointers.hpp index 86f20a9..92938db 100644 --- a/include/gp/pointers.hpp +++ b/include/gp/pointers.hpp @@ -13,7 +13,7 @@ namespace gp { gp::allocator& owner; unique_ptr(T* _data, gp::allocator& _owner) - : data(data) + : data(_data) , owner(_owner) {} @@ -25,19 +25,23 @@ namespace gp { } public: template - unique_ptr make(gp::allocator& owner, U&&... args) { + static unique_ptr make(gp::allocator& owner, U&&... args) { auto ptr = owner.allocate(sizeof(T)); return unique_ptr(new(ptr) T(gp::forward(args)...), owner); } - T& operator->() { - return *data; + T* operator->() { + return data; } T& operator*() { return *data; } + operator bool() { + return data != nullptr; + } + unique_ptr(unique_ptr&) = delete; unique_ptr(unique_ptr&& oth) @@ -67,7 +71,7 @@ namespace gp { gp::allocator& owner; shared_ptr(T* _data, gp::allocator& _owner) - : data(data) + : data(_data) , owner(_owner) {} @@ -83,7 +87,7 @@ namespace gp { } public: template - shared_ptr make(gp::allocator& owner, U&&... args) { + static shared_ptr make(gp::allocator& owner, U&&... args) { auto ptr = owner.allocate(sizeof(T)); auto shared_atomic = owner.allocate(sizeof(std::atomic_int)); refcounter = new(shared_atomic) std::atomic_int(); @@ -91,14 +95,18 @@ namespace gp { return shared_ptr(new(ptr) T(gp::forward(args)...), owner); } - T& operator->() { - return *data; + T* operator->() { + return data; } T& operator*() { return *data; } + operator bool() { + return data != nullptr; + } + shared_ptr(shared_ptr& oth) { oth.refcounter->fetch_add(1, std::memory_order::acquire); diff --git a/include/gp/vfs/process_data.hpp b/include/gp/vfs/process_data.hpp index a44e5db..af3a2f5 100644 --- a/include/gp/vfs/process_data.hpp +++ b/include/gp/vfs/process_data.hpp @@ -47,7 +47,7 @@ namespace gp { , stack_sz(_stack_sz) , state(gp::process_status::inactive) , specifics(gp::buffer{(char*)stack, stack_sz}) - , info(_info) + , info(gp::move(_info)) {} process_data(process_data&& v) diff --git a/include/gp/vfs/system.hpp b/include/gp/vfs/system.hpp index 7f1d680..3b5e1bf 100644 --- a/include/gp/vfs/system.hpp +++ b/include/gp/vfs/system.hpp @@ -46,7 +46,7 @@ public: stack_estimate = gp::buffer{seed, (size_t)(gp_config::limits::process_stack*page_cnt)}; } main_context.value = (process_data*)system_allocator.get().allocate(sizeof(process_data)); - new(main_context.value) process_data(gp::function([]() -> void{}, nullopt), stack_estimate.begin().data, stack_estimate.size()); + new(main_context.value) process_data(gp::function([]() -> void{}, nullopt), stack_estimate.begin().data, stack_estimate.size(), gp::unique_ptr::make(system_allocator)); gp_config::assertion(main_context.value != nullptr, "failed to allocate return to main switch"); scheme.link(*this); } @@ -57,7 +57,7 @@ public: gp_config::assertion(stack != nullptr, "failed to allocate a stack"); process_data* created_process = (process_data*)system_allocator.get().allocate(sizeof(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::make(system_allocator)); topic_list::node_ptr pp = (topic_list::node_ptr)system_allocator.get().allocate( sizeof(topic_list::node) @@ -92,7 +92,7 @@ public: scheduler::scheduler(class system& v, size_t token) : id(token) , sys(v) -, main_context_data{gp::function{[](){}, v.system_allocator}, nullptr, size_t(0)} +, main_context_data{gp::function{[](){}, v.system_allocator}, nullptr, size_t(0), gp::unique_ptr::make(v.system_allocator)} , main_context() { main_context.value = &main_context_data;