-
-
Save rightfold/4bd64407e62526baa808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Styx::VM::VM() : run(true), work(ioService) { | |
auto nthreads = std::thread::hardware_concurrency(); | |
if (nthreads == 0) { | |
nthreads = 1; | |
} | |
for (decltype(nthreads) i = 0; i < nthreads; ++i) { | |
threads.create_thread([this] { | |
while (run) { | |
Fiber* fiber; | |
scheduledFibers.pop(fiber); | |
resume(*fiber); | |
} | |
}); | |
} | |
threads.create_thread([this] { | |
ioService.run(); | |
}); | |
} | |
Styx::VM::~VM() { | |
run = false; | |
ioService.stop(); | |
threads.join_all(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VM { | |
public: | |
VM(); | |
~VM(); | |
std::future<GCPtr<>> call(GCPtr<Function> function, GCPtr<> arg); | |
private: | |
std::atomic<bool> run; | |
public: | |
GC gc; | |
boost::asio::io_service ioService; | |
private: | |
Fiber& spawn(GCPtr<Function> function); | |
void resume(Fiber& fiber); | |
boost::asio::io_service::work work; | |
std::vector<std::unique_ptr<Fiber>> fibers; | |
tbb::concurrent_bounded_queue<Fiber*> scheduledFibers; | |
boost::thread_group threads; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment