stephb9959
2023-04-18 07:45:07 -07:00
parent aec865aac4
commit 0ddcf18c2c
3 changed files with 17 additions and 8 deletions

2
build
View File

@@ -1 +1 @@
23
24

View File

@@ -52,13 +52,13 @@ namespace OpenWifi {
void SimulationRunner::Stop() {
if (Running_) {
Running_ = false;
Reactor_.stop();
SocketReactorThread_.join();
Running_ = false;
for(auto &client:Clients_) {
OWLSclientEvents::Disconnect(client.second, this, "Simulation shutting down", false);
client.second->Valid_ = false;
}
Reactor_.stop();
SocketReactorThread_.join();
Clients_.clear();
}
}

View File

@@ -71,11 +71,11 @@ namespace Bosma {
explicit Scheduler(unsigned int max_n_tasks = 4) : done(false), threads(max_n_tasks + 1) {
threads.push([this](int) {
while (!done) {
if (tasks.empty()) {
sleeper.sleep();
Clock::time_point sleep_until_time;
if(find_sleep_time(sleep_until_time)) {
sleeper.sleep_until(sleep_until_time);
} else {
auto time_of_first_task = (*tasks.begin()).first;
sleeper.sleep_until(time_of_first_task);
sleeper.sleep();
}
manage_tasks();
}
@@ -183,6 +183,15 @@ namespace Bosma {
sleeper.interrupt();
}
bool find_sleep_time(Clock::time_point &sleep_value) {
std::lock_guard<std::mutex> l(lock);
if(tasks.empty()) {
return false;
}
sleep_value = (*tasks.begin()).first;
return true;
}
void manage_tasks() {
std::lock_guard<std::mutex> l(lock);