diff --git a/CMakeLists.txt b/CMakeLists.txt index 27d82ae95..04795a372 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -283,7 +283,6 @@ list(APPEND INCLUDE_FILES ${PROJECT_SOURCE_DIR}/include/mbgl/util/interpolate.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/logging.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/noncopyable.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/util/pass_types.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/platform.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/premultiply.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/projection.hpp diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index 124121a54..4525613af 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include @@ -74,7 +73,7 @@ public: /// The scheduled tasks might run in parallel on different /// threads. /// TODO : Rename to GetPool() - static PassRefPtr GetBackground(); + [[nodiscard]] static std::shared_ptr GetBackground(); /// Get the *sequenced* scheduler for asynchronous tasks. /// Unlike the method above, the returned scheduler @@ -84,7 +83,7 @@ public: /// /// Sequenced scheduler can be used for running tasks /// on the same thread-unsafe object. - static PassRefPtr GetSequenced(); + [[nodiscard]] static std::shared_ptr GetSequenced(); protected: template diff --git a/include/mbgl/storage/file_source_manager.hpp b/include/mbgl/storage/file_source_manager.hpp index 1f6ed8e22..dd78eb319 100644 --- a/include/mbgl/storage/file_source_manager.hpp +++ b/include/mbgl/storage/file_source_manager.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace mbgl { @@ -31,7 +30,7 @@ public: // Returns shared instance of a file source for (type, options) tuple. // Creates new instance via registered factory if needed. If new instance cannot be // created, nullptr would be returned. - PassRefPtr getFileSource(FileSourceType, const ResourceOptions&, const ClientOptions& = ClientOptions()) noexcept; + [[nodiscard]] std::shared_ptr getFileSource(FileSourceType, const ResourceOptions&, const ClientOptions& = ClientOptions()) noexcept; // Registers file source factory for a provided FileSourceType type. If factory for the // same type was already registered, will unregister previously registered factory. diff --git a/include/mbgl/util/pass_types.hpp b/include/mbgl/util/pass_types.hpp deleted file mode 100644 index e0da2fba4..000000000 --- a/include/mbgl/util/pass_types.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -namespace mbgl { - -/// Using this type as a return type enforces the client to retain the returned object. -template -class Pass { -public: - Pass(T obj_) : obj(std::move(obj_)) {} - Pass(Pass&&) noexcept = default; - Pass(const Pass&) = delete; - Pass& operator=(const Pass&) = delete; - operator T() && { return std::move(obj); } - -private: - T obj; -}; - -template -using PassRefPtr = Pass>; - -} // namespace mbgl diff --git a/src/mbgl/actor/scheduler.cpp b/src/mbgl/actor/scheduler.cpp index d765cfcf6..0e051d027 100644 --- a/src/mbgl/actor/scheduler.cpp +++ b/src/mbgl/actor/scheduler.cpp @@ -27,7 +27,7 @@ Scheduler* Scheduler::GetCurrent() { } // static -PassRefPtr Scheduler::GetBackground() { +std::shared_ptr Scheduler::GetBackground() { static std::weak_ptr weak; static std::mutex mtx; @@ -38,11 +38,11 @@ PassRefPtr Scheduler::GetBackground() { weak = scheduler = std::make_shared(); } - return PassRefPtr(std::move(scheduler)); + return scheduler; } // static -PassRefPtr Scheduler::GetSequenced() { +std::shared_ptr Scheduler::GetSequenced() { const std::size_t kSchedulersCount = 10; static std::vector> weaks(kSchedulersCount); static std::mutex mtx; @@ -65,7 +65,7 @@ PassRefPtr Scheduler::GetSequenced() { break; } - return PassRefPtr(std::move(result)); + return result; } } //namespace mbgl diff --git a/src/mbgl/storage/file_source_manager.cpp b/src/mbgl/storage/file_source_manager.cpp index 5e8018088..6e24d7210 100644 --- a/src/mbgl/storage/file_source_manager.cpp +++ b/src/mbgl/storage/file_source_manager.cpp @@ -31,7 +31,7 @@ FileSourceManager::FileSourceManager() : impl(std::make_unique()) {} FileSourceManager::~FileSourceManager() = default; -PassRefPtr FileSourceManager::getFileSource(FileSourceType type, const ResourceOptions& resourceOptions, const ClientOptions& clientOptions) noexcept { +std::shared_ptr FileSourceManager::getFileSource(FileSourceType type, const ResourceOptions& resourceOptions, const ClientOptions& clientOptions) noexcept { std::lock_guard lock(impl->mutex); // Remove released file sources. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1100c2bc4..1dcd7853a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -94,7 +94,6 @@ add_library( ${PROJECT_SOURCE_DIR}/test/util/memory.test.cpp ${PROJECT_SOURCE_DIR}/test/util/merge_lines.test.cpp ${PROJECT_SOURCE_DIR}/test/util/number_conversions.test.cpp - ${PROJECT_SOURCE_DIR}/test/util/pass.test.cpp ${PROJECT_SOURCE_DIR}/test/util/position.test.cpp ${PROJECT_SOURCE_DIR}/test/util/projection.test.cpp ${PROJECT_SOURCE_DIR}/test/util/rotation.test.cpp diff --git a/test/util/pass.test.cpp b/test/util/pass.test.cpp deleted file mode 100644 index 10651f854..000000000 --- a/test/util/pass.test.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#include - -TEST(Pass, NoCopy) { - static int copyCount = 0; - struct A { - A() = default; - A(A&&) = default; - A(const A&) { ++copyCount; } - static mbgl::Pass create() { return A(); } - }; - A a = A::create(); - (void)a; - EXPECT_EQ(0, copyCount); -} \ No newline at end of file