Explorar el Código

made the topic list, the base class of the scheduler

channel
Ludovic 'Archivist' Lagouardette hace 4 años
padre
commit
572e1c2dd2
Se han modificado 4 ficheros con 88 adiciones y 7 borrados
  1. +1
    -1
      Makefile
  2. +82
    -0
      include/gp/vfs/runqueue.hpp
  3. +3
    -4
      include/gp/vfs/system.hpp
  4. +2
    -2
      tests/cbor_test.cpp

+ 1
- 1
Makefile Ver fichero

@ -1,5 +1,5 @@
CXX= clang++-10
CXXFLAGS= --std=c++20 -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=1 -pedantic \
CXXFLAGS= --std=c++20 -O2 -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

+ 82
- 0
include/gp/vfs/runqueue.hpp Ver fichero

@ -0,0 +1,82 @@
#pragma once
#include "gp/vfs/process_data.hpp"
#include <atomic>
class runqueue{
struct node{
std::atomic_bool is_locked;
gp::process_data* value;
std::atomic<struct node*> next;
bool try_acquire() noexcept {
bool expected = false;
return !(is_locked.compare_exchange_strong(expected, true));
}
void release() noexcept {
is_locked.store(false);
}
};
using node_ptr = struct node*;
using node_ptr_rep = std::atomic<struct node*>;
struct topic_list{
node_ptr_rep start;
node_ptr_rep end;
// NODES ARE ACQUIRED ON POP
node_ptr try_pop() {
auto ptr = start.load();
if(!ptr) return nullptr;
if(ptr->try_acquire()) {
auto replace = ptr->next.load();
auto expected = ptr;
if(end.load() == ptr) {
end.store(nullptr);
}
if(start.compare_exchange_strong(expected, replace)) {
return ptr;
} else {
return nullptr;
}
} else {
return nullptr;
}
}
// ONLY PUSH ACQUIRED NODES
bool try_push(node_ptr node) {
auto ed = end.load();
if(ed) {
if(ed->try_acquire()) {
node->next.store(ed);
if(end.compare_exchange_strong(ed, node)) {
ed->release();
node->release();
return true;
} else {
ed->release();
node->release();
return false;
}
} else return false;
} else {
if(end.compare_exchange_strong(ed, node)) {
start.store(node);
node->release();
return true;
} else {
return false;
}
}
}
};
topic_list running;
topic_list waiting;
};

+ 3
- 4
include/gp/vfs/system.hpp Ver fichero

@ -48,9 +48,8 @@ public:
scheduler::scheduler(class system& v)
: sys(v){}
no_inline_decl(
void scheduler::yield_to(size_t target_pid)
) {
void scheduler::yield_to(size_t target_pid)
{
auto& cur = current ? sys.processes[current-1]->specifics : root;
auto& target = target_pid ? sys.processes[target_pid-1]->specifics : root;
current = target_pid;
@ -67,7 +66,7 @@ no_inline_decl(
}
}(static_cast<scheduler*>(target.push(this)));
} else {
volatile scheduler* new_p = static_cast<scheduler*>(target.push(this));
na">[[maybe_unused]] volatile scheduler* new_p = static_cast<scheduler*>(target.push(this));
}
}

+ 2
- 2
tests/cbor_test.cpp Ver fichero

@ -487,8 +487,8 @@ struct cbor_test : public test_scaffold {
data = meta;
gp::array<std::byte, 31> serialized;
gp::array<std::byte, 31> serialized_manual{
gp::array<std::byte, 25> serialized;
gp::array<std::byte, 25> serialized_manual{
std::byte(0b10100010),
std::byte(0b01000101),
std::byte('h'),

Cargando…
Cancelar
Guardar