General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1018 B

  1. #pragma once
  2. #include "gp/vfs/system.hpp"
  3. namespace gp{
  4. class simple_lockfree_scheduling : gp::scheduling_scheme {
  5. gp::topic_list running;
  6. gp::topic_list waiting;
  7. gp::topic_list to_clean;
  8. gp::topic_list naughty;
  9. scheduler me;
  10. public:
  11. virtual gp::topic_list::node_ptr one(size_t) {
  12. auto v = running.try_pop();
  13. do{
  14. if(v) return v;
  15. v = running.try_pop();
  16. }while(true);
  17. }
  18. virtual gp::topic_list::node_ptr next(size_t, gp::topic_list::node_ptr current) {
  19. switch(current->value->state) {
  20. case process_status::inactive:
  21. case process_status::running:
  22. do{}while(!running.try_push(current));
  23. break;
  24. case process_status::finished:
  25. do{}while(!to_clean.try_push(current));
  26. break;
  27. case process_status::zombie:
  28. do{}while(!naughty.try_push(current));
  29. break;
  30. case process_status::waiting:
  31. do{}while(!waiting.try_push(current));
  32. break;
  33. }
  34. return one(0);
  35. }
  36. virtual gp::scheduler& current_scheduler() {
  37. return me;
  38. }
  39. };
  40. }