Skip to content
Snippets Groups Projects
Commit f9137ab6 authored by j2-tulloch's avatar j2-tulloch :speech_balloon:
Browse files

Upload New File

parent a0c94d97
No related branches found
No related tags found
No related merge requests found
#include "scheduler.h"
#include <iostream>
void scheduler::yield(fiber* f) {
get_context(f->get_context());
if (!f->finished()){
fibers_.push_back(f);
}
set_context(&context_);
}
scheduler::scheduler() {
// Initialization, if necessary
}
scheduler::~scheduler() {
// Clean up, if necessary
}
void scheduler::spawn(fiber* f) {
fibers_.push_back(f);
}
void scheduler::do_it() {
std::cout << "Entering" << std::endl;
get_context(&context_); // Save the scheduler's context
while (!fibers_.empty()) {
fiber* currentFiber = fibers_.front();
std::cout << "Switching fiber" << std::endl;
fibers_.pop_front(); // Remove the fiber from the queue
set_context(currentFiber->get_context()); // Switch to the fiber's context
// After fiber finishes execution, control returns here
std::cout << " returning to scheduler" << std::endl;
}
std::cout << "Exiting" << std::endl;
}
void scheduler::fiber_exit() {
set_context(&context_); // Switch back to the scheduler's context
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment