mirror of
https://github.com/asamy/ctorrent
synced 2025-10-05 23:52:41 +02:00
fix scheduler not exiting properly
Signed-off-by: Ahmed Samy <f.fallen45@gmail.com>
This commit is contained in:
@@ -78,8 +78,9 @@ public:
|
||||
}
|
||||
|
||||
~TorrentFileManagerImpl() {
|
||||
lock();
|
||||
m_stopped = true;
|
||||
m_condition.notify_all();
|
||||
unlock_and_notify();
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
@@ -289,6 +290,9 @@ void TorrentFileManagerImpl::thread()
|
||||
m_readRequests.pop();
|
||||
}
|
||||
|
||||
if (m_stopped)
|
||||
break;
|
||||
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
7
main.cpp
7
main.cpp
@@ -178,7 +178,7 @@ int main(int argc, char *argv[])
|
||||
size_t eseed = 0;
|
||||
size_t started = 0;
|
||||
|
||||
Torrent *torrents = new Torrent[total]; // Workaround for CLang non-POD
|
||||
std::vector<Torrent> torrents(total);
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
std::string file = files[i];
|
||||
Torrent *t = &torrents[i];
|
||||
@@ -251,7 +251,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
Connection::poll();
|
||||
print_all_stats(torrents, total);
|
||||
print_all_stats(&torrents[0], total);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
}
|
||||
@@ -272,7 +272,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
Connection::poll();
|
||||
print_all_stats(torrents, total);
|
||||
print_all_stats(&torrents[0], total);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
}
|
||||
@@ -293,7 +293,6 @@ int main(int argc, char *argv[])
|
||||
std::clog << meta->name() << std::endl;
|
||||
}
|
||||
|
||||
delete []torrents;
|
||||
logfile.close();
|
||||
return 0;
|
||||
}
|
||||
|
@@ -84,11 +84,14 @@ public:
|
||||
}
|
||||
|
||||
void stop() {
|
||||
mutex.lock();
|
||||
m_stopped = true;
|
||||
m_condition.notify_one();
|
||||
mutex.unlock();
|
||||
m_condition.notify_all();
|
||||
m_thread.join();
|
||||
m_dispatcherThread.join();
|
||||
}
|
||||
void notify_one() { m_condition.notify_one(); }
|
||||
void notify_all() { m_condition.notify_all(); }
|
||||
|
||||
protected:
|
||||
@@ -122,7 +125,7 @@ uint32_t Scheduler::addEvent(const SchedulerCallback &cb, uint32_t ms)
|
||||
i->events.push(ev);
|
||||
i->mutex.unlock();
|
||||
if (notify)
|
||||
i->notify_all();
|
||||
i->notify_one();
|
||||
|
||||
return ev.id();
|
||||
}
|
||||
@@ -174,7 +177,7 @@ void SchedulerImpl::thread()
|
||||
// Ugly hack for newly added events
|
||||
fart:
|
||||
bool cont = m_condition.wait_until(m, std::chrono::system_clock::now()
|
||||
+ std::chrono::milliseconds(5), [this] () { return events.top().expired(); });
|
||||
+ std::chrono::milliseconds(5), [this] () { return events.top().expired() || m_stopped; });
|
||||
if (m_stopped)
|
||||
break;
|
||||
else if (!cont)
|
||||
|
Reference in New Issue
Block a user