diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-12 20:22:31 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-14 09:16:48 +0000 |
commit | f24990e7ce5fbb61ec9e59ab7658fd39370e5b25 (patch) | |
tree | 253e2dafaba87c7c5982726c043d4726df1106f6 | |
parent | 3e0ab6f73c7b49967b5c55e52cb0f2095e3f3c76 (diff) |
Replace usage of boost::shared_ptr/weak_ptr with std::versions.
25 files changed, 139 insertions, 131 deletions
diff --git a/filedistribution/src/apps/filedistributor/filedistributor.cpp b/filedistribution/src/apps/filedistributor/filedistributor.cpp index 62def74ee7a..23fcb25ea21 100644 --- a/filedistribution/src/apps/filedistributor/filedistributor.cpp +++ b/filedistribution/src/apps/filedistributor/filedistributor.cpp @@ -53,29 +53,33 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, class Components { ComponentsDeleter _componentsDeleter; public: - const boost::shared_ptr<ZKFacade> _zk; - const boost::shared_ptr<FileDistributionModelImpl> _model; - const boost::shared_ptr<FileDistributorTrackerImpl> _tracker; - const boost::shared_ptr<FileDownloader> _downloader; - const boost::shared_ptr<FileDownloaderManager> _manager; - const boost::shared_ptr<FileDistributorRPC> _rpcHandler; - const boost::shared_ptr<StateServerImpl> _stateServer; + const std::shared_ptr<ZKFacade> _zk; + const std::shared_ptr<FileDistributionModelImpl> _model; + const std::shared_ptr<FileDistributorTrackerImpl> _tracker; + const std::shared_ptr<FileDownloader> _downloader; + const std::shared_ptr<FileDownloaderManager> _manager; + const FileDistributorRPC::SP _rpcHandler; + const std::shared_ptr<StateServerImpl> _stateServer; private: boost::thread _downloaderEventLoopThread; config::ConfigFetcher _configFetcher; - template <class T> - typename boost::shared_ptr<T> track(T* component) { + typename std::shared_ptr<T> track(T* component) { return _componentsDeleter.track(component); } + template <class T> + typename boost::shared_ptr<T> track_boost(T* component) { + return _componentsDeleter.track_boost(component); + } + public: Components(const Components &) = delete; Components & operator = (const Components &) = delete; - Components(const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower, + Components(const std::shared_ptr<ExceptionRethrower>& exceptionRethrower, const config::ConfigUri & configUri, const ZookeepersConfig& zooKeepersConfig, const FiledistributorConfig& fileDistributorConfig, @@ -94,10 +98,9 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, boost::filesystem::path(fileDistributorConfig.filedbpath), exceptionRethrower))), _manager(track(new FileDownloaderManager(_downloader, _model))), - _rpcHandler(track(new FileDistributorRPC(rpcConfig.connectionspec, _manager))), + _rpcHandler(track_boost(new FileDistributorRPC(rpcConfig.connectionspec, _manager))), _stateServer(track(new StateServerImpl(fileDistributorConfig.stateport))), - _downloaderEventLoopThread( - ll::bind(&FileDownloader::runEventLoop, _downloader.get())), + _downloaderEventLoopThread( ll::bind(&FileDownloader::runEventLoop, _downloader.get())), _configFetcher(configUri.getContext()) { @@ -134,7 +137,7 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, std::unique_ptr<FiledistributorConfig> _fileDistributorConfig; std::unique_ptr<FiledistributorrpcConfig> _rpcConfig; - boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; + std::shared_ptr<ExceptionRethrower> _exceptionRethrower; std::unique_ptr<Components> _components; public: FileDistributor(const FileDistributor &) = delete; @@ -195,7 +198,7 @@ public: } } - static void ensureExceptionsStored(const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower) { + static void ensureExceptionsStored(const std::shared_ptr<ExceptionRethrower>& exceptionRethrower) { //TODO: this is somewhat hackish, refactor to eliminate this later. LOG(debug, "Waiting for shutdown"); for (int i=0; @@ -211,7 +214,7 @@ public: } } - void createComponents(const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower, const config::ConfigUri & configUri) { + void createComponents(const std::shared_ptr<ExceptionRethrower>& exceptionRethrower, const config::ConfigUri & configUri) { LockGuard guard(_configMutex); _components.reset( new Components(exceptionRethrower, diff --git a/filedistribution/src/apps/status/status-filedistribution.cpp b/filedistribution/src/apps/status/status-filedistribution.cpp index 90c21623016..5950712a103 100644 --- a/filedistribution/src/apps/status/status-filedistribution.cpp +++ b/filedistribution/src/apps/status/status-filedistribution.cpp @@ -60,10 +60,10 @@ printWaitingForHosts(const StatusByHostName& notFinishedHosts) //TODO:refactor int printStatus(const std::string& zkservers) { - boost::shared_ptr<ExceptionRethrower> exceptionRethrower; - boost::shared_ptr<ZKFacade> zk(new ZKFacade(zkservers, exceptionRethrower)); + std::shared_ptr<ExceptionRethrower> exceptionRethrower; + std::shared_ptr<ZKFacade> zk(new ZKFacade(zkservers, exceptionRethrower)); - boost::shared_ptr<FileDBModel> model(new ZKFileDBModel(zk)); + std::shared_ptr<FileDBModel> model(new ZKFileDBModel(zk)); std::vector<std::string> hosts = model->getHosts(); diff --git a/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp b/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp index 84d1b5b958c..7642798125b 100644 --- a/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp +++ b/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp @@ -20,10 +20,10 @@ namespace { struct Fixture { - boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; + std::shared_ptr<ExceptionRethrower> _exceptionRethrower; ComponentsDeleter _componentsDeleter; - boost::shared_ptr<ZKFacade> _zk; - boost::shared_ptr<FileDistributionModelImpl> _distModel; + std::shared_ptr<ZKFacade> _zk; + std::shared_ptr<FileDistributionModelImpl> _distModel; Fixture() { _exceptionRethrower.reset(new ExceptionRethrower()); _zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181", _exceptionRethrower)); diff --git a/filedistribution/src/tests/filedownloader/testfiledownloader.cpp b/filedistribution/src/tests/filedownloader/testfiledownloader.cpp index 94b505f4f9f..cc82aab01ea 100644 --- a/filedistribution/src/tests/filedownloader/testfiledownloader.cpp +++ b/filedistribution/src/tests/filedownloader/testfiledownloader.cpp @@ -33,14 +33,14 @@ const int uploaderPort = 9113; const int downloaderPort = 9112; #if 0 -boost::shared_ptr<FileDownloader> +std::shared_ptr<FileDownloader> createDownloader(ComponentsDeleter& deleter, int port, const fs::path& downloaderPath, - const boost::shared_ptr<FileDistributionModel>& model, - const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower) + const std::shared_ptr<FileDistributionModel>& model, + const std::shared_ptr<ExceptionRethrower>& exceptionRethrower) { - boost::shared_ptr<FileDistributorTrackerImpl> tracker(deleter.track(new FileDistributorTrackerImpl(model, exceptionRethrower))); - boost::shared_ptr<FileDownloader> downloader(deleter.track(new FileDownloader(tracker, + std::shared_ptr<FileDistributorTrackerImpl> tracker(deleter.track(new FileDistributorTrackerImpl(model, exceptionRethrower))); + std::shared_ptr<FileDownloader> downloader(deleter.track(new FileDownloader(tracker, localHost, port, downloaderPath, exceptionRethrower))); tracker->setDownloader(downloader); @@ -101,13 +101,13 @@ BOOST_AUTO_TEST_CASE(fileDownloaderTest) { Buffer buffer(createTorrent.bencode()); ComponentsDeleter deleter; - boost::shared_ptr<ExceptionRethrower> exceptionRethrower(new ExceptionRethrower()); + std::shared_ptr<ExceptionRethrower> exceptionRethrower(new ExceptionRethrower()); - boost::shared_ptr<FileDistributionModel> model(deleter.track(new MockFileDistributionModel())); - boost::shared_ptr<FileDownloader> downloader = + std::shared_ptr<FileDistributionModel> model(deleter.track(new MockFileDistributionModel())); + std::shared_ptr<FileDownloader> downloader = createDownloader(deleter, downloaderPort, downloaderPath, model, exceptionRethrower); - boost::shared_ptr<FileDownloader> uploader = + std::shared_ptr<FileDownloader> uploader = createDownloader(deleter, uploaderPort, uploaderPath, model, exceptionRethrower); boost::thread uploaderThread( diff --git a/filedistribution/src/tests/lib/mock-zookeeper.cpp b/filedistribution/src/tests/lib/mock-zookeeper.cpp index 82cd03a268e..809733b9dd0 100644 --- a/filedistribution/src/tests/lib/mock-zookeeper.cpp +++ b/filedistribution/src/tests/lib/mock-zookeeper.cpp @@ -55,7 +55,7 @@ struct Node { void triggerWatches(zhandle_t* zh, const std::string& path); }; -boost::shared_ptr<Node> sharedRoot; +std::shared_ptr<Node> sharedRoot; struct ZHandle { struct Worker { @@ -68,7 +68,7 @@ struct ZHandle { int sequence; - boost::shared_ptr<Node> root; + std::shared_ptr<Node> root; boost::thread _watchersThread; vector<string> ephemeralNodes; diff --git a/filedistribution/src/tests/rpc/testfileprovider.cpp b/filedistribution/src/tests/rpc/testfileprovider.cpp index 6881eb96b8a..1291932c8a6 100644 --- a/filedistribution/src/tests/rpc/testfileprovider.cpp +++ b/filedistribution/src/tests/rpc/testfileprovider.cpp @@ -17,8 +17,8 @@ const std::string MockFileProvider::_queueForeverFileReference("queue-forever"); BOOST_AUTO_TEST_CASE(fileDistributionRPCTest) { const std::string spec("tcp/localhost:9111"); - boost::shared_ptr<fd::MockFileProvider> provider(new fd::MockFileProvider()); - boost::shared_ptr<fd::FileDistributorRPC> fileDistributorRPC(new fd::FileDistributorRPC(spec, provider)); + std::shared_ptr<fd::MockFileProvider> provider(new fd::MockFileProvider()); + fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider)); fileDistributorRPC->start(); frtstream::FrtClientStream rpc(spec); @@ -37,8 +37,8 @@ BOOST_AUTO_TEST_CASE(fileDistributionRPCTest) { //must be run through valgrind BOOST_AUTO_TEST_CASE(require_that_queued_requests_does_not_leak_memory) { const std::string spec("tcp/localhost:9111"); - boost::shared_ptr<MockFileProvider> provider(new MockFileProvider()); - boost::shared_ptr<fd::FileDistributorRPC> fileDistributorRPC(new fd::FileDistributorRPC(spec, provider)); + std::shared_ptr<MockFileProvider> provider(new MockFileProvider()); + fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider)); fileDistributorRPC->start(); FRT_Supervisor supervisor; diff --git a/filedistribution/src/tests/zkfacade/test-zkfacade.cpp b/filedistribution/src/tests/zkfacade/test-zkfacade.cpp index d45e5059a53..037ce448dd9 100644 --- a/filedistribution/src/tests/zkfacade/test-zkfacade.cpp +++ b/filedistribution/src/tests/zkfacade/test-zkfacade.cpp @@ -35,9 +35,9 @@ struct Watcher : public ZKFacade::NodeChangedWatcher { }; struct Fixture { - boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; + std::shared_ptr<ExceptionRethrower> _exceptionRethrower; ComponentsDeleter _componentsDeleter; - boost::shared_ptr<ZKFacade> zk; + std::shared_ptr<ZKFacade> zk; ZKFacade::Path testNode; Fixture() { @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(hasNode) BOOST_AUTO_TEST_CASE(hasNodeNotification) { - boost::shared_ptr<Watcher> watcher(new Watcher); + std::shared_ptr<Watcher> watcher(new Watcher); zk->hasNode(testNode, watcher); zk->setData(testNode, "", 0); @@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(addEphemeralNode) BOOST_AUTO_TEST_CASE(dataChangedNotification) { - boost::shared_ptr<Watcher> watcher(new Watcher); + std::shared_ptr<Watcher> watcher(new Watcher); zk->setData(testNode, "", 0); Buffer buffer(zk->getData(testNode, watcher)); @@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(dataChangedNotification) BOOST_AUTO_TEST_CASE(getChildrenNotification) { - boost::shared_ptr<Watcher> watcher(new Watcher); + std::shared_ptr<Watcher> watcher(new Watcher); zk->setData(testNode, "", 0); zk->getChildren(testNode, watcher); @@ -194,9 +194,9 @@ BOOST_AUTO_TEST_CASE(getChildrenNotification) BOOST_AUTO_TEST_CASE(require_that_zkfacade_can_be_deleted_from_callback) { struct DeleteZKFacadeWatcher : public Watcher { - boost::shared_ptr<ZKFacade> _zk; + std::shared_ptr<ZKFacade> _zk; - DeleteZKFacadeWatcher(const boost::shared_ptr<ZKFacade>& zk) + DeleteZKFacadeWatcher(const std::shared_ptr<ZKFacade>& zk) :_zk(zk) {} @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(require_that_zkfacade_can_be_deleted_from_callback) } }; - boost::shared_ptr<Watcher> watcher((Watcher*)new DeleteZKFacadeWatcher(zk)); + std::shared_ptr<Watcher> watcher((Watcher*)new DeleteZKFacadeWatcher(zk)); zk->setData(testNode, "", 0); zk->getData(testNode, watcher); diff --git a/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp b/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp index b385949bb98..108278b2d24 100644 --- a/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp +++ b/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp @@ -26,10 +26,10 @@ namespace { struct Fixture { - boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; + std::shared_ptr<ExceptionRethrower> _exceptionRethrower; ComponentsDeleter _componentsDeleter; - boost::shared_ptr<ZKFacade> zk; - boost::shared_ptr<ZKFileDBModel> model; + std::shared_ptr<ZKFacade> zk; + std::shared_ptr<ZKFileDBModel> model; Fixture() { _exceptionRethrower.reset(new ExceptionRethrower()); diff --git a/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h b/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h index 4238f88a05e..651b3d89cc5 100644 --- a/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h +++ b/filedistribution/src/vespa/filedistribution/common/componentsdeleter.h @@ -61,12 +61,20 @@ class ComponentsDeleter { ~ComponentsDeleter(); template <class T> - boost::shared_ptr<T> track(T* t) { + boost::shared_ptr<T> track_boost(T* t) { LockGuard guard(_trackedComponentsMutex); _trackedComponents[t] = typeid(t).name(); return boost::shared_ptr<T>(t, boost::bind(&ComponentsDeleter::requestDelete<T>, this, t)); } + + template <class T> + std::shared_ptr<T> track(T* t) { + LockGuard guard(_trackedComponentsMutex); + + _trackedComponents[t] = typeid(t).name(); + return std::shared_ptr<T>(t, boost::bind(&ComponentsDeleter::requestDelete<T>, this, t)); + } }; } diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp index 055a72e26b3..872d77a46d9 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp @@ -16,6 +16,7 @@ using filedistribution::FileDownloader; using filedistribution::FileDistributionModel; using filedistribution::Scheduler; using filedistribution::ExceptionRethrower; +using filedistribution::TorrentSP; typedef FileDistributionModel::PeerEntries PeerEntries; @@ -60,14 +61,14 @@ struct TrackingTask : public Scheduler::Task { libtorrent::tracker_request _trackerRequest; boost::weak_ptr<libtorrent::torrent> _torrent; - boost::weak_ptr<FileDownloader> _downloader; - boost::shared_ptr<FileDistributionModel> _model; + std::weak_ptr<FileDownloader> _downloader; + std::shared_ptr<FileDistributionModel> _model; TrackingTask(Scheduler& scheduler, const libtorrent::tracker_request& trackerRequest, - const boost::shared_ptr<libtorrent::torrent>& torrent, - const boost::weak_ptr<FileDownloader>& downloader, - const boost::shared_ptr<FileDistributionModel>& model) + const TorrentSP & torrent, + const std::weak_ptr<FileDownloader>& downloader, + const std::shared_ptr<FileDistributionModel>& model) : Task(scheduler), _numTimesRescheduled(0), _trackerRequest(trackerRequest), @@ -78,12 +79,12 @@ struct TrackingTask : public Scheduler::Task { //TODO: refactor void doHandle() { - if (boost::shared_ptr<FileDownloader> downloader = _downloader.lock()) { + if (std::shared_ptr<FileDownloader> downloader = _downloader.lock()) { //All torrents must be destructed before the session is destructed. //It's okay to prevent the torrent from expiring here //since the session can't be destructed while //we hold a shared_ptr to the downloader. - if (boost::shared_ptr<libtorrent::torrent> torrent = _torrent.lock()) { + if (TorrentSP torrent = _torrent.lock()) { PeerEntries peers = getPeers(downloader); if (!peers.empty()) { @@ -108,7 +109,7 @@ struct TrackingTask : public Scheduler::Task { } } - PeerEntries getPeers(const boost::shared_ptr<FileDownloader>& downloader) { + PeerEntries getPeers(const std::shared_ptr<FileDownloader>& downloader) { std::string fileReference = downloader->infoHash2FileReference(_trackerRequest.info_hash); const size_t recommendedMaxNumberOfPeers = 30; @@ -136,7 +137,7 @@ struct TrackingTask : public Scheduler::Task { void -workerFunction(boost::shared_ptr<ExceptionRethrower> exceptionRethrower, asio::io_service& ioService) +workerFunction(std::shared_ptr<ExceptionRethrower> exceptionRethrower, asio::io_service& ioService) { while (!boost::this_thread::interruption_requested()) { try { @@ -155,8 +156,8 @@ workerFunction(boost::shared_ptr<ExceptionRethrower> exceptionRethrower, asio::i FileDistributorTrackerImpl::FileDistributorTrackerImpl( - const boost::shared_ptr<FileDistributionModel>& model, - const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower) + const std::shared_ptr<FileDistributionModel>& model, + const std::shared_ptr<ExceptionRethrower>& exceptionRethrower) :_exceptionRethrower(exceptionRethrower), _model(model) {} @@ -173,12 +174,12 @@ FileDistributorTrackerImpl::~FileDistributorTrackerImpl() { void FileDistributorTrackerImpl::trackingRequest( libtorrent::tracker_request& request, - const boost::shared_ptr<libtorrent::torrent> & torrent) + const TorrentSP & torrent) { LockGuard guard(_mutex); - if (torrent != boost::shared_ptr<libtorrent::torrent>()) { - boost::shared_ptr<TrackingTask> trackingTask(new TrackingTask( + if (torrent != TorrentSP()) { + std::shared_ptr<TrackingTask> trackingTask(new TrackingTask( *_scheduler.get(), request, torrent, _downloader, _model)); trackingTask->scheduleNow(); @@ -187,7 +188,7 @@ FileDistributorTrackerImpl::trackingRequest( void -FileDistributorTrackerImpl::setDownloader(const boost::shared_ptr<FileDownloader>& downloader) +FileDistributorTrackerImpl::setDownloader(const std::shared_ptr<FileDownloader>& downloader) { LockGuard guard(_mutex); diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.h b/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.h index edbdb9b8943..7fa574b5105 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.h +++ b/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.h @@ -5,7 +5,6 @@ #include <libtorrent/torrent.hpp> #include <boost/thread.hpp> -#include <boost/shared_ptr.hpp> #include <boost/asio/io_service.hpp> #include <boost/asio/deadline_timer.hpp> @@ -17,28 +16,29 @@ namespace filedistribution { class FileDistributionModel; class FileDownloader; +using TorrentSP = boost::shared_ptr<libtorrent::torrent>; + class FileDistributorTrackerImpl : public FileDistributionTracker { - const boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; - const boost::shared_ptr<FileDistributionModel> _model; + const std::shared_ptr<ExceptionRethrower> _exceptionRethrower; + const std::shared_ptr<FileDistributionModel> _model; typedef boost::lock_guard<boost::mutex> LockGuard; boost::mutex _mutex; - boost::weak_ptr<FileDownloader> _downloader; + std::weak_ptr<FileDownloader> _downloader; //Use separate worker thread to avoid potential deadlock //between tracker requests and files to download changed requests. boost::scoped_ptr<Scheduler> _scheduler; public: - FileDistributorTrackerImpl(const boost::shared_ptr<FileDistributionModel>& model, - const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower); + FileDistributorTrackerImpl(const std::shared_ptr<FileDistributionModel>& model, + const std::shared_ptr<ExceptionRethrower>& exceptionRethrower); virtual ~FileDistributorTrackerImpl(); //overrides - void trackingRequest(libtorrent::tracker_request& request, - const boost::shared_ptr<libtorrent::torrent> & torrent); + void trackingRequest(libtorrent::tracker_request& request, const TorrentSP & torrent); - void setDownloader(const boost::shared_ptr<FileDownloader>& downloader); + void setDownloader(const std::shared_ptr<FileDownloader>& downloader); }; } //namespace filedistribution diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp index 546ae8028f8..049b07bf4cd 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp @@ -209,10 +209,10 @@ FileDownloader::LogSessionDeconstructed::~LogSessionDeconstructed() LOG(debug, "Libtorrent session closed successfully."); } -FileDownloader::FileDownloader(const boost::shared_ptr<FileDistributionTracker>& tracker, +FileDownloader::FileDownloader(const std::shared_ptr<FileDistributionTracker>& tracker, const std::string& hostName, int port, const fs::path& dbPath, - const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower) + const std::shared_ptr<ExceptionRethrower>& exceptionRethrower) : _outstanding_SRD_requests(0), _tracker(tracker), _session(tracker.get(), libtorrent::fingerprint("vp", 0, 0, 0, 0), 0), diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h index 9056f437664..b2819f78540 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h @@ -40,7 +40,7 @@ class FileDownloader }; size_t _outstanding_SRD_requests; - boost::shared_ptr<FileDistributionTracker> _tracker; + std::shared_ptr<FileDistributionTracker> _tracker; boost::mutex _modifyTorrentsDownloadingMutex; typedef boost::lock_guard<boost::mutex> LockGuard; @@ -65,10 +65,10 @@ public: typedef FileProvider::DownloadCompletedSignal DownloadCompletedSignal; typedef FileProvider::DownloadFailedSignal DownloadFailedSignal; - FileDownloader(const boost::shared_ptr<FileDistributionTracker>& tracker, + FileDownloader(const std::shared_ptr<FileDistributionTracker>& tracker, const std::string& hostName, int port, const boost::filesystem::path& dbPath, - const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower); + const std::shared_ptr<ExceptionRethrower>& exceptionRethrower); ~FileDownloader(); DirectoryGuard::UP getGuard() { return std::make_unique<DirectoryGuard>(_dbPath); } @@ -84,7 +84,7 @@ public: void setMaxDownloadSpeed(double MBPerSec); void setMaxUploadSpeed(double MBPerSec); - const boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; + const std::shared_ptr<ExceptionRethrower> _exceptionRethrower; const std::string _hostName; const int _port; diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp index 7bc57c57dd1..a4f7bb802da 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp @@ -26,8 +26,8 @@ void logStartDownload(const std::set<std::string> & filesToDownload) { } //anonymous namespace FileDownloaderManager::FileDownloaderManager( - const boost::shared_ptr<FileDownloader>& downloader, - const boost::shared_ptr<FileDistributionModel>& model) + const std::shared_ptr<FileDownloader>& downloader, + const std::shared_ptr<FileDistributionModel>& model) :_fileDownloader(downloader), _fileDistributionModel(model), diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h index f99888c5a26..0670a38907c 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h @@ -32,8 +32,8 @@ class FileDownloaderManager : public FileProvider, typedef boost::lock_guard<boost::mutex> LockGuard; boost::mutex _updateFilesToDownloadMutex; - boost::shared_ptr<FileDownloader> _fileDownloader; - boost::shared_ptr<FileDistributionModel> _fileDistributionModel; + std::shared_ptr<FileDownloader> _fileDownloader; + std::shared_ptr<FileDistributionModel> _fileDistributionModel; StartDownloads _startDownloads; SetFinishedDownloadingStatus _setFinishedDownloadingStatus; @@ -45,8 +45,8 @@ class FileDownloaderManager : public FileProvider, public: FileDownloaderManager(const FileDownloaderManager &) = delete; FileDownloaderManager & operator = (const FileDownloaderManager &) = delete; - FileDownloaderManager(const boost::shared_ptr<FileDownloader>&, - const boost::shared_ptr<FileDistributionModel>& model); + FileDownloaderManager(const std::shared_ptr<FileDownloader>&, + const std::shared_ptr<FileDistributionModel>& model); ~FileDownloaderManager(); void start(); diff --git a/filedistribution/src/vespa/filedistribution/distributor/scheduler.h b/filedistribution/src/vespa/filedistribution/distributor/scheduler.h index 9492a8977d7..10a6b4395a2 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/scheduler.h +++ b/filedistribution/src/vespa/filedistribution/distributor/scheduler.h @@ -14,7 +14,7 @@ public: class Task : public boost::enable_shared_from_this<Task> { boost::asio::deadline_timer _timer; public: - typedef boost::shared_ptr<Task> SP; + typedef std::shared_ptr<Task> SP; Task(Scheduler& scheduler); diff --git a/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp b/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp index fb75d88e031..e6efa92c9f2 100644 --- a/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp +++ b/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp @@ -89,8 +89,8 @@ void initMockFileDBModel(NativeFileDistributionManager& manager) void initFileDBModel(NativeFileDistributionManager& manager, const std::string& zkServers) { //Ignored for now, since we're not installing any watchers. - boost::shared_ptr<ExceptionRethrower> ignoredRethrower(new ExceptionRethrower()); - boost::shared_ptr<ZKFacade> zk(new ZKFacade(zkServers, ignoredRethrower)); + std::shared_ptr<ExceptionRethrower> ignoredRethrower(new ExceptionRethrower()); + std::shared_ptr<ZKFacade> zk(new ZKFacade(zkServers, ignoredRethrower)); manager._fileDBModel.reset(new ZKFileDBModel(zk)); } } //end anonymous namespace diff --git a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp index 5b9de93249a..3e1912eb206 100644 --- a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp +++ b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp @@ -74,18 +74,18 @@ using filedistribution::FileDistributionModelImpl; struct FileDistributionModelImpl::DeployedFilesChangedCallback : public ZKFacade::NodeChangedWatcher { - typedef boost::shared_ptr<DeployedFilesChangedCallback> SP; + typedef std::shared_ptr<DeployedFilesChangedCallback> SP; - boost::weak_ptr<FileDistributionModelImpl> _parent; + std::weak_ptr<FileDistributionModelImpl> _parent; DeployedFilesChangedCallback( - const boost::shared_ptr<FileDistributionModelImpl> & parent) + const std::shared_ptr<FileDistributionModelImpl> & parent) :_parent(parent) {} //override void operator()() { - if (boost::shared_ptr<FileDistributionModelImpl> model = _parent.lock()) { + if (std::shared_ptr<FileDistributionModelImpl> model = _parent.lock()) { model->_filesToDownloadChanged(); } } diff --git a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.h b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.h index 04a111a00df..34836abfb73 100644 --- a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.h +++ b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.h @@ -16,21 +16,21 @@ namespace filedistribution { class FileDistributionModelImpl : public FileDistributionModel, public config::IFetcherCallback<FilereferencesConfig>, - public boost::enable_shared_from_this<FileDistributionModelImpl> + public std::enable_shared_from_this<FileDistributionModelImpl> { struct DeployedFilesChangedCallback; const std::string _hostName; const int _port; - const boost::shared_ptr<ZKFacade> _zk; + const std::shared_ptr<ZKFacade> _zk; ZKFileDBModel _fileDBModel; boost::mutex _activeFileReferencesMutex; typedef boost::lock_guard<boost::mutex> LockGuard; std::vector<vespalib::string> _activeFileReferences; - const boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; + const std::shared_ptr<ExceptionRethrower> _exceptionRethrower; bool /*changed*/ updateActiveFileReferences(const std::vector<vespalib::string>& fileReferences); @@ -38,8 +38,8 @@ class FileDistributionModelImpl : public FileDistributionModel, ZKFacade::Path getPeerEntryPath(const std::string& fileReference); public: FileDistributionModelImpl(const std::string& hostName, int port, - const boost::shared_ptr<ZKFacade>& zk, - const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower) + const std::shared_ptr<ZKFacade>& zk, + const std::shared_ptr<ExceptionRethrower>& exceptionRethrower) :_hostName(hostName), _port(port), _zk(zk), diff --git a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp index ecfb3ca7b44..838e5c2c301 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp +++ b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp @@ -136,11 +136,11 @@ setDataForExistingFile(ZKFacade& zk, const Path& path, const char* buffer, int l /********** Active watchers *******************************************/ struct ZKFacade::ZKWatcher { - const boost::weak_ptr<ZKFacade> _owner; + const std::weak_ptr<ZKFacade> _owner; const NodeChangedWatcherSP _nodeChangedWatcher; ZKWatcher( - const boost::shared_ptr<ZKFacade> &owner, + const std::shared_ptr<ZKFacade> &owner, const NodeChangedWatcherSP& nodeChangedWatcher ) :_owner(owner), _nodeChangedWatcher(nodeChangedWatcher) @@ -170,7 +170,7 @@ struct ZKFacade::ZKWatcher { //this will cause infinite waiting. //To avoid this, a custom shared_ptr deleter using a separate deleter thread must be used. - if (boost::shared_ptr<ZKFacade> zk = self->_owner.lock()) { + if (std::shared_ptr<ZKFacade> zk = self->_owner.lock()) { zk->invokeWatcher(watcherContext); } @@ -201,21 +201,21 @@ void* /* watcherContext */ ZKFacade::registerWatcher(const NodeChangedWatcherSP& watcher) { UniqueLock lock(_watchersMutex); - boost::shared_ptr<ZKWatcher> zkWatcher(new ZKWatcher(shared_from_this(), watcher)); + std::shared_ptr<ZKWatcher> zkWatcher(new ZKWatcher(shared_from_this(), watcher)); _watchers[zkWatcher.get()] = zkWatcher; return zkWatcher.get(); } -boost::shared_ptr<ZKFacade::ZKWatcher> +std::shared_ptr<ZKFacade::ZKWatcher> ZKFacade::unregisterWatcher(void* watcherContext) { UniqueLock lock(_watchersMutex); WatchersMap::iterator i = _watchers.find(watcherContext); if (i == _watchers.end()) { - return boost::shared_ptr<ZKWatcher>(); + return std::shared_ptr<ZKWatcher>(); } else { - boost::shared_ptr<ZKWatcher> result = i->second; + std::shared_ptr<ZKWatcher> result = i->second; _watchers.erase(i); return result; } @@ -224,7 +224,7 @@ ZKFacade::unregisterWatcher(void* watcherContext) { void ZKFacade::invokeWatcher(void* watcherContext) { try { - boost::shared_ptr<ZKWatcher> watcher = unregisterWatcher(watcherContext); + std::shared_ptr<ZKWatcher> watcher = unregisterWatcher(watcherContext); if (!_watchersEnabled) return; @@ -243,7 +243,7 @@ ZKFacade::invokeWatcher(void* watcherContext) { ZKFacade::ZKFacade(const std::string& zkservers, - const boost::shared_ptr<ExceptionRethrower> &exceptionRethrower) + const std::shared_ptr<ExceptionRethrower> &exceptionRethrower) :_retriesEnabled(true), _watchersEnabled(true), _exceptionRethrower(exceptionRethrower), diff --git a/filedistribution/src/vespa/filedistribution/model/zkfacade.h b/filedistribution/src/vespa/filedistribution/model/zkfacade.h index e46ed42fdec..2075e69ec05 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfacade.h +++ b/filedistribution/src/vespa/filedistribution/model/zkfacade.h @@ -59,11 +59,11 @@ diagnosticUserLevelMessage(const ZKException& zk); -class ZKFacade : public boost::enable_shared_from_this<ZKFacade> { +class ZKFacade : public std::enable_shared_from_this<ZKFacade> { volatile bool _retriesEnabled; volatile bool _watchersEnabled; - boost::shared_ptr<ExceptionRethrower> _exceptionRethrower; + std::shared_ptr<ExceptionRethrower> _exceptionRethrower; zhandle_t* _zhandle; const static int _zkSessionTimeOut = 30 * 1000; const static size_t _maxDataSize = 1024 * 1024; @@ -71,7 +71,7 @@ class ZKFacade : public boost::enable_shared_from_this<ZKFacade> { class ZKWatcher; static void stateWatchingFun(zhandle_t*, int type, int state, const char* path, void* context); public: - typedef boost::shared_ptr<ZKFacade> SP; + typedef std::shared_ptr<ZKFacade> SP; /* Lifetime is managed by ZKFacade. Derived classes should only contain weak_ptrs to other objects @@ -86,12 +86,12 @@ public: virtual void operator()() = 0; }; - typedef boost::shared_ptr<NodeChangedWatcher> NodeChangedWatcherSP; + typedef std::shared_ptr<NodeChangedWatcher> NodeChangedWatcherSP; typedef boost::filesystem::path Path; ZKFacade(const ZKFacade &) = delete; ZKFacade & operator = (const ZKFacade &) = delete; - ZKFacade(const std::string& zkservers, const boost::shared_ptr<ExceptionRethrower> &); + ZKFacade(const std::string& zkservers, const std::shared_ptr<ExceptionRethrower> &); ~ZKFacade(); bool hasNode(const Path&); @@ -125,11 +125,11 @@ public: private: void* registerWatcher(const NodeChangedWatcherSP &); //returns watcherContext - boost::shared_ptr<ZKWatcher> unregisterWatcher(void* watcherContext); + std::shared_ptr<ZKWatcher> unregisterWatcher(void* watcherContext); void invokeWatcher(void* watcherContext); boost::mutex _watchersMutex; - typedef std::map<void*, boost::shared_ptr<ZKWatcher> > WatchersMap; + typedef std::map<void*, std::shared_ptr<ZKWatcher> > WatchersMap; WatchersMap _watchers; }; diff --git a/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp b/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp index f9a4c777b30..ebb58a3829b 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp +++ b/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp @@ -242,7 +242,7 @@ ZKFileDBModel::cleanFiles( _zk->retainOnly(_fileDBPath, filesToPreserve); } -ZKFileDBModel::ZKFileDBModel(const boost::shared_ptr<ZKFacade>& zk) +ZKFileDBModel::ZKFileDBModel(const std::shared_ptr<ZKFacade>& zk) : _zk(zk) { createNode(_root, *_zk); diff --git a/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.h b/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.h index cf180f4c780..4249410c00e 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.h +++ b/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.h @@ -1,8 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <boost/shared_ptr.hpp> - #include "filedistributionmodel.h" #include "zkfacade.h" @@ -12,7 +10,7 @@ class ZKFileDBModel : public FileDBModel { public: typedef boost::filesystem::path Path; private: - const boost::shared_ptr<ZKFacade> _zk; + const std::shared_ptr<ZKFacade> _zk; char getProgress(const Path& path); void removeDeployFileNodes(const Path& hostPath, const std::string& appId); void removeLegacyDeployFileNodes(const Path& hostPath); @@ -49,7 +47,7 @@ public: std::vector<std::string> getHosts(); HostStatus getHostStatus(const std::string& hostName); - ZKFileDBModel(const boost::shared_ptr<ZKFacade>& zk); + ZKFileDBModel(const std::shared_ptr<ZKFacade>& zk); Progress getProgress(const std::string& fileReference, const std::vector<std::string>& hostsSortedAscending); diff --git a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp index 4e63b90d8b9..c56accdd35d 100644 --- a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp +++ b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp @@ -146,7 +146,7 @@ public: class FileDistributorRPC::Server : public FRT_Invokable { public: - boost::shared_ptr<FileProvider> _fileProvider; + std::shared_ptr<FileProvider> _fileProvider; std::unique_ptr<FRT_Supervisor> _supervisor; QueuedRequests _queuedRequests; @@ -159,8 +159,8 @@ class FileDistributorRPC::Server : public FRT_Invokable { Server(const Server &) = delete; Server & operator = (const Server &) = delete; - Server(int listen_port, const boost::shared_ptr<FileProvider>& provider); - void start(const boost::shared_ptr<FileDistributorRPC> parent); + Server(int listen_port, const std::shared_ptr<FileProvider>& provider); + void start(const FileDistributorRPC::SP & parent); ~Server(); void waitFor(FRT_RPCRequest*); @@ -168,7 +168,7 @@ class FileDistributorRPC::Server : public FRT_Invokable { FileDistributorRPC:: Server::Server(int listen_port, - const boost::shared_ptr<filedistribution::FileProvider>& provider) + const std::shared_ptr<filedistribution::FileProvider>& provider) :_fileProvider(provider), _supervisor(new FRT_Supervisor()) { @@ -178,8 +178,7 @@ Server::Server(int listen_port, } -FileDistributorRPC:: -Server::~Server() { +FileDistributorRPC::Server::~Server() { _queuedRequests.shutdown(); const bool waitForFinished = true; @@ -187,7 +186,7 @@ Server::~Server() { } void -FileDistributorRPC::Server::start(const boost::shared_ptr<FileDistributorRPC> parent) { +FileDistributorRPC::Server::start(const FileDistributorRPC::SP & parent) { _downloadCompletedConnection = _fileProvider->downloadCompleted().connect(FileProvider::DownloadCompletedSignal::slot_type( ll::bind(&QueuedRequests::downloadFinished, &_queuedRequests, ll::_1, ll::_2)). @@ -214,8 +213,7 @@ Server::queueRequest(const std::string& fileReference, FRT_RPCRequest* request) } void -FileDistributorRPC:: -Server::defineMethods() { +FileDistributorRPC::Server::defineMethods() { const bool instant = true; FRT_ReflectionBuilder builder(_supervisor.get()); builder.DefineMethod("waitFor", "s", "s", instant, @@ -223,8 +221,7 @@ Server::defineMethods() { } void -FileDistributorRPC:: -Server::waitFor(FRT_RPCRequest* request) { +FileDistributorRPC::Server::waitFor(FRT_RPCRequest* request) { try { frtstream::FrtServerStream requestHandler(request); std::string fileReference; @@ -253,7 +250,7 @@ Server::waitFor(FRT_RPCRequest* request) { } FileDistributorRPC::FileDistributorRPC(const std::string& connectionSpec, - const boost::shared_ptr<filedistribution::FileProvider>& provider) + const std::shared_ptr<filedistribution::FileProvider>& provider) :_server(new Server(get_port(connectionSpec), provider)) {} diff --git a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h index 8c492ad4b5d..c05991236aa 100644 --- a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h +++ b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h @@ -12,9 +12,10 @@ class FileDistributorRPC : public boost::enable_shared_from_this<FileDistributor { class Server; public: + using SP = boost::shared_ptr<FileDistributorRPC>; FileDistributorRPC(const FileDistributorRPC &) = delete; FileDistributorRPC & operator = (const FileDistributorRPC &) = delete; - FileDistributorRPC(const std::string& connectSpec, const boost::shared_ptr<FileProvider>& provider); + FileDistributorRPC(const std::string& connectSpec, const std::shared_ptr<FileProvider>& provider); void start(); |