2016-01-27 11:31:39 +00:00
|
|
|
#include <ws/ws.hpp>
|
|
|
|
|
|
|
|
namespace WonderSwan {
|
|
|
|
|
|
|
|
Scheduler scheduler;
|
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
auto Scheduler::power() -> void {
|
2016-01-27 11:31:39 +00:00
|
|
|
host = co_active();
|
2016-02-09 11:51:12 +00:00
|
|
|
resume = cpu.thread;
|
2016-01-27 11:31:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
auto Scheduler::enter(Mode mode_) -> Event {
|
|
|
|
mode = mode_;
|
|
|
|
host = co_active();
|
|
|
|
co_switch(resume);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Scheduler::exit(Event event_) -> void {
|
|
|
|
event = event_;
|
|
|
|
resume = co_active();
|
2016-01-27 11:31:39 +00:00
|
|
|
co_switch(host);
|
|
|
|
}
|
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
auto Scheduler::synchronize(cothread_t thread) -> void {
|
|
|
|
if(thread == cpu.thread) {
|
|
|
|
while(enter(Mode::SynchronizeCPU) != Event::Synchronize);
|
|
|
|
} else {
|
|
|
|
resume = thread;
|
|
|
|
while(enter(Mode::SynchronizeAll) != Event::Synchronize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Scheduler::synchronize() -> void {
|
|
|
|
if(co_active() == cpu.thread && mode == Mode::SynchronizeCPU) return exit(Event::Synchronize);
|
|
|
|
if(co_active() != cpu.thread && mode == Mode::SynchronizeAll) return exit(Event::Synchronize);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Scheduler::synchronizing() const -> bool {
|
|
|
|
return mode == Mode::SynchronizeAll;
|
2016-01-27 11:31:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|