diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-13 14:26:01 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-14 09:16:53 +0000 |
commit | d17fbcef25617f928cc0aa3d221379d2f2a21719 (patch) | |
tree | 7272dc5f586c9b1a8ecff6ba906877e4d2e6972f /filedistribution | |
parent | 5fd50504380a45396890e99fa3412ff5f5172ff9 (diff) |
boost::thread -> std::thread
Diffstat (limited to 'filedistribution')
3 files changed, 25 insertions, 21 deletions
diff --git a/filedistribution/src/apps/filedistributor/filedistributor.cpp b/filedistribution/src/apps/filedistributor/filedistributor.cpp index 11b2844e95f..0fbf81c9912 100644 --- a/filedistribution/src/apps/filedistributor/filedistributor.cpp +++ b/filedistribution/src/apps/filedistributor/filedistributor.cpp @@ -62,7 +62,7 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, const std::shared_ptr<StateServerImpl> _stateServer; private: - boost::thread _downloaderEventLoopThread; + std::thread _downloaderEventLoopThread; config::ConfigFetcher _configFetcher; template <class T> @@ -95,8 +95,7 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, _tracker, fileDistributorConfig.hostname, fileDistributorConfig.torrentport, - boost::filesystem::path(fileDistributorConfig.filedbpath), - exceptionRethrower))), + boost::filesystem::path(fileDistributorConfig.filedbpath)))), _manager(track_boost(new FileDownloaderManager(_downloader, _model))), _rpcHandler(track_boost(new FileDistributorRPC(rpcConfig.connectionspec, _manager))), _stateServer(track(new StateServerImpl(fileDistributorConfig.stateport))), @@ -123,7 +122,7 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, //Do not waste time retrying zookeeper operations when going down. _zk->disableRetries(); - _downloaderEventLoopThread.interrupt(); + _downloader->close(); _downloaderEventLoopThread.join(); } diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp index 049b07bf4cd..2300d4e7efc 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp @@ -211,13 +211,12 @@ FileDownloader::LogSessionDeconstructed::~LogSessionDeconstructed() FileDownloader::FileDownloader(const std::shared_ptr<FileDistributionTracker>& tracker, const std::string& hostName, int port, - const fs::path& dbPath, - const std::shared_ptr<ExceptionRethrower>& exceptionRethrower) + const fs::path& dbPath) : _outstanding_SRD_requests(0), _tracker(tracker), _session(tracker.get(), libtorrent::fingerprint("vp", 0, 0, 0, 0), 0), + _closed(false), _dbPath(dbPath), - _exceptionRethrower(exceptionRethrower), _hostName(hostName), _port(port) { @@ -382,20 +381,26 @@ FileDownloader::removeAllTorrentsBut(const std::set<std::string> & filesToRetain void FileDownloader::runEventLoop() { EventHandler eventHandler(this); - try { - while (!boost::this_thread::interruption_requested()) { - if (_session.wait_for_alert(libtorrent::milliseconds(100))) { - std::unique_ptr<libtorrent::alert> alert = _session.pop_alert(); - eventHandler.handle(std::move(alert)); - } + while ( ! closed() ) { + if (_session.wait_for_alert(libtorrent::milliseconds(100))) { + std::unique_ptr<libtorrent::alert> alert = _session.pop_alert(); + eventHandler.handle(std::move(alert)); } - } catch(const boost::thread_interrupted&) { - LOG(spam, "The FileDownloader thread was interrupted."); - } catch(...) { - _exceptionRethrower->store(boost::current_exception()); } } +bool +FileDownloader::closed() const +{ + return _closed.load(); +} + +void +FileDownloader::close() +{ + _closed.store(true); +} + void FileDownloader::signalIfFinishedDownloading(const std::string& fileReference) { boost::optional<fs::path> path = pathToCompletedFile(fileReference); diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h index 758cfc5d1cd..6f2124fd10c 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h @@ -47,6 +47,7 @@ class FileDownloader LogSessionDeconstructed _logSessionDeconstructed; //session is safe to use from multiple threads. libtorrent::session _session; + std::atomic<bool> _closed; const boost::filesystem::path _dbPath; typedef std::vector<char> ResumeDataBuffer; @@ -66,8 +67,7 @@ public: FileDownloader(const std::shared_ptr<FileDistributionTracker>& tracker, const std::string& hostName, int port, - const boost::filesystem::path& dbPath, - const std::shared_ptr<ExceptionRethrower>& exceptionRethrower); + const boost::filesystem::path& dbPath); ~FileDownloader(); DirectoryGuard::UP getGuard() { return std::make_unique<DirectoryGuard>(_dbPath); } @@ -82,8 +82,8 @@ public: std::string infoHash2FileReference(const libtorrent::sha1_hash& hash); void setMaxDownloadSpeed(double MBPerSec); void setMaxUploadSpeed(double MBPerSec); - - const std::shared_ptr<ExceptionRethrower> _exceptionRethrower; + void close(); + bool closed() const; const std::string _hostName; const int _port; |