|
|
- #pragma once
- #include "gp/vfs/system.hpp"
-
- namespace gp{
-
- class simple_lockfree_scheduling : gp::scheduling_scheme {
- gp::topic_list running;
- gp::topic_list waiting;
- gp::topic_list to_clean;
- gp::topic_list naughty;
- scheduler me;
-
- public:
- virtual gp::topic_list::node_ptr one(size_t) {
- auto v = running.try_pop();
- do{
- if(v) return v;
- v = running.try_pop();
- }while(true);
- }
- virtual gp::topic_list::node_ptr next(size_t, gp::topic_list::node_ptr current) {
- switch(current->value->state) {
- case process_status::inactive:
- case process_status::running:
- do{}while(!running.try_push(current));
- break;
- case process_status::finished:
- do{}while(!to_clean.try_push(current));
- break;
- case process_status::zombie:
- do{}while(!naughty.try_push(current));
- break;
- case process_status::waiting:
- do{}while(!waiting.try_push(current));
- break;
- }
- return one(0);
- }
-
- virtual gp::scheduler& current_scheduler() {
- return me;
- }
- };
- }
|