diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29db5138..b244ed81 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ set(SOURCES results.cpp schema.cpp shared_realm.cpp - impl/background_collection.cpp + impl/collection_notifier.cpp impl/list_notifier.cpp impl/realm_coordinator.cpp impl/results_notifier.cpp @@ -25,7 +25,7 @@ set(HEADERS results.hpp schema.hpp shared_realm.hpp - impl/background_collection.hpp + impl/collection_notifier.hpp impl/external_commit_helper.hpp impl/list_notifier.hpp impl/realm_coordinator.hpp diff --git a/src/collection_notifications.cpp b/src/collection_notifications.cpp index 7eae2cb8..9a11941d 100644 --- a/src/collection_notifications.cpp +++ b/src/collection_notifications.cpp @@ -18,12 +18,12 @@ #include "collection_notifications.hpp" -#include "impl/background_collection.hpp" +#include "impl/collection_notifier.hpp" using namespace realm; using namespace realm::_impl; -NotificationToken::NotificationToken(std::shared_ptr<_impl::BackgroundCollection> notifier, size_t token) +NotificationToken::NotificationToken(std::shared_ptr<_impl::CollectionNotifier> notifier, size_t token) : m_notifier(std::move(notifier)), m_token(token) { } diff --git a/src/collection_notifications.hpp b/src/collection_notifications.hpp index c2dc9d03..8fc2c0c8 100644 --- a/src/collection_notifications.hpp +++ b/src/collection_notifications.hpp @@ -29,13 +29,13 @@ namespace realm { namespace _impl { - class BackgroundCollection; + class CollectionNotifier; } // A token which keeps an asynchronous query alive struct NotificationToken { NotificationToken() = default; - NotificationToken(std::shared_ptr<_impl::BackgroundCollection> notifier, size_t token); + NotificationToken(std::shared_ptr<_impl::CollectionNotifier> notifier, size_t token); ~NotificationToken(); NotificationToken(NotificationToken&&); @@ -45,7 +45,7 @@ struct NotificationToken { NotificationToken& operator=(NotificationToken const&) = delete; private: - util::AtomicSharedPtr<_impl::BackgroundCollection> m_notifier; + util::AtomicSharedPtr<_impl::CollectionNotifier> m_notifier; size_t m_token; }; diff --git a/src/impl/background_collection.cpp b/src/impl/collection_notifier.cpp similarity index 96% rename from src/impl/background_collection.cpp rename to src/impl/collection_notifier.cpp index 552f457b..acf95d71 100644 --- a/src/impl/background_collection.cpp +++ b/src/impl/collection_notifier.cpp @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////// -#include "impl/background_collection.hpp" +#include "impl/collection_notifier.hpp" #include "impl/realm_coordinator.hpp" #include "shared_realm.hpp" @@ -58,20 +58,20 @@ bool TransactionChangeInfo::row_did_change(Table const& table, size_t idx, int d return false; } -BackgroundCollection::BackgroundCollection(std::shared_ptr realm) +CollectionNotifier::CollectionNotifier(std::shared_ptr realm) : m_realm(std::move(realm)) , m_sg_version(Realm::Internal::get_shared_group(*m_realm).get_version_of_current_transaction()) { } -BackgroundCollection::~BackgroundCollection() +CollectionNotifier::~CollectionNotifier() { // Need to do this explicitly to ensure m_realm is destroyed with the mutex // held to avoid potential double-deletion unregister(); } -size_t BackgroundCollection::add_callback(CollectionChangeCallback callback) +size_t CollectionNotifier::add_callback(CollectionChangeCallback callback) { m_realm->verify_thread(); @@ -95,7 +95,7 @@ size_t BackgroundCollection::add_callback(CollectionChangeCallback callback) return token; } -void BackgroundCollection::remove_callback(size_t token) +void CollectionNotifier::remove_callback(size_t token) { Callback old; { @@ -122,19 +122,19 @@ void BackgroundCollection::remove_callback(size_t token) } } -void BackgroundCollection::unregister() noexcept +void CollectionNotifier::unregister() noexcept { std::lock_guard lock(m_realm_mutex); m_realm = nullptr; } -bool BackgroundCollection::is_alive() const noexcept +bool CollectionNotifier::is_alive() const noexcept { std::lock_guard lock(m_realm_mutex); return m_realm != nullptr; } -std::unique_lock BackgroundCollection::lock_target() +std::unique_lock CollectionNotifier::lock_target() { return std::unique_lock{m_realm_mutex}; } @@ -154,12 +154,12 @@ static void find_relevant_tables(std::vector& out, Table const& table) } } -void BackgroundCollection::set_table(Table const& table) +void CollectionNotifier::set_table(Table const& table) { find_relevant_tables(m_relevant_tables, table); } -void BackgroundCollection::add_required_change_info(TransactionChangeInfo& info) +void CollectionNotifier::add_required_change_info(TransactionChangeInfo& info) { if (!do_add_required_change_info(info)) { return; @@ -173,14 +173,14 @@ void BackgroundCollection::add_required_change_info(TransactionChangeInfo& info) } } -void BackgroundCollection::prepare_handover() +void CollectionNotifier::prepare_handover() { REALM_ASSERT(m_sg); m_sg_version = m_sg->get_version_of_current_transaction(); do_prepare_handover(*m_sg); } -bool BackgroundCollection::deliver(SharedGroup& sg, std::exception_ptr err) +bool CollectionNotifier::deliver(SharedGroup& sg, std::exception_ptr err) { if (!is_for_current_thread()) { return false; @@ -206,7 +206,7 @@ bool BackgroundCollection::deliver(SharedGroup& sg, std::exception_ptr err) return should_call_callbacks && have_callbacks(); } -void BackgroundCollection::call_callbacks() +void CollectionNotifier::call_callbacks() { while (auto fn = next_callback()) { fn(m_changes_to_deliver, m_error); @@ -220,7 +220,7 @@ void BackgroundCollection::call_callbacks() } } -CollectionChangeCallback BackgroundCollection::next_callback() +CollectionChangeCallback CollectionNotifier::next_callback() { std::lock_guard callback_lock(m_callback_mutex); @@ -237,7 +237,7 @@ CollectionChangeCallback BackgroundCollection::next_callback() return nullptr; } -void BackgroundCollection::attach_to(SharedGroup& sg) +void CollectionNotifier::attach_to(SharedGroup& sg) { REALM_ASSERT(!m_sg); @@ -245,7 +245,7 @@ void BackgroundCollection::attach_to(SharedGroup& sg) do_attach_to(sg); } -void BackgroundCollection::detach() +void CollectionNotifier::detach() { REALM_ASSERT(m_sg); do_detach_from(*m_sg); diff --git a/src/impl/background_collection.hpp b/src/impl/collection_notifier.hpp similarity index 97% rename from src/impl/background_collection.hpp rename to src/impl/collection_notifier.hpp index 830cd8bf..a21ff042 100644 --- a/src/impl/background_collection.hpp +++ b/src/impl/collection_notifier.hpp @@ -90,10 +90,10 @@ struct TransactionChangeInfo { // most of the lifetime-management issues related to sharing an object between // the worker thread and the collection on the target thread, along with the // thread-safe callback collection. -class BackgroundCollection { +class CollectionNotifier { public: - BackgroundCollection(std::shared_ptr); - virtual ~BackgroundCollection(); + CollectionNotifier(std::shared_ptr); + virtual ~CollectionNotifier(); // ------------------------------------------------------------------------ // Public API for the collections using this to get notifications: @@ -123,7 +123,7 @@ public: // Release references to all core types // This is called on the worker thread to ensure that non-thread-safe things // can be destroyed on the correct thread, even if the last reference to the - // BackgroundCollection is released on a different thread + // CollectionNotifier is released on a different thread virtual void release_data() noexcept = 0; // Call each of the currently registered callbacks, if there have been any diff --git a/src/impl/list_notifier.cpp b/src/impl/list_notifier.cpp index 11a74bb4..2d14602b 100644 --- a/src/impl/list_notifier.cpp +++ b/src/impl/list_notifier.cpp @@ -26,7 +26,7 @@ using namespace realm; using namespace realm::_impl; ListNotifier::ListNotifier(LinkViewRef lv, std::shared_ptr realm) -: BackgroundCollection(std::move(realm)) +: CollectionNotifier(std::move(realm)) , m_prev_size(lv->size()) { // Find the lv's column, since that isn't tracked directly diff --git a/src/impl/list_notifier.hpp b/src/impl/list_notifier.hpp index 9cc0d775..82b4e414 100644 --- a/src/impl/list_notifier.hpp +++ b/src/impl/list_notifier.hpp @@ -19,13 +19,13 @@ #ifndef REALM_LIST_NOTIFIER_HPP #define REALM_LIST_NOTIFIER_HPP -#include "impl/background_collection.hpp" +#include "impl/collection_notifier.hpp" #include namespace realm { namespace _impl { -class ListNotifier : public BackgroundCollection { +class ListNotifier : public CollectionNotifier { public: ListNotifier(LinkViewRef lv, std::shared_ptr realm); diff --git a/src/impl/realm_coordinator.cpp b/src/impl/realm_coordinator.cpp index 7f0f6ff2..78a2f7ae 100644 --- a/src/impl/realm_coordinator.cpp +++ b/src/impl/realm_coordinator.cpp @@ -18,7 +18,7 @@ #include "impl/realm_coordinator.hpp" -#include "impl/background_collection.hpp" +#include "impl/collection_notifier.hpp" #include "impl/external_commit_helper.hpp" #include "impl/transact_log_handler.hpp" #include "impl/weak_realm_notifier.hpp" @@ -245,7 +245,7 @@ void RealmCoordinator::pin_version(uint_fast64_t version, uint_fast32_t index) } } -void RealmCoordinator::register_notifier(std::shared_ptr notifier) +void RealmCoordinator::register_notifier(std::shared_ptr notifier) { auto version = notifier->version(); auto& self = Realm::Internal::get_coordinator(*notifier->get_realm()); @@ -306,7 +306,7 @@ namespace { class IncrementalChangeInfo { public: IncrementalChangeInfo(SharedGroup& sg, - std::vector>& notifiers) + std::vector>& notifiers) : m_sg(sg) { if (notifiers.empty()) diff --git a/src/impl/realm_coordinator.hpp b/src/impl/realm_coordinator.hpp index 899f2c03..2a6f74b2 100644 --- a/src/impl/realm_coordinator.hpp +++ b/src/impl/realm_coordinator.hpp @@ -30,7 +30,7 @@ class SharedGroup; class StringData; namespace _impl { -class BackgroundCollection; +class CollectionNotifier; class ExternalCommitHelper; class WeakRealmNotifier; @@ -81,7 +81,7 @@ public: // Update the schema in the cached config void update_schema(Schema const& new_schema); - static void register_notifier(std::shared_ptr notifier); + static void register_notifier(std::shared_ptr notifier); // Advance the Realm to the most recent transaction version which all async // work is complete for @@ -95,8 +95,8 @@ private: std::vector m_weak_realm_notifiers; std::mutex m_notifier_mutex; - std::vector> m_new_notifiers; - std::vector> m_notifiers; + std::vector> m_new_notifiers; + std::vector> m_notifiers; // SharedGroup used for actually running async notifiers // Will have a read transaction iff m_notifiers is non-empty diff --git a/src/impl/results_notifier.cpp b/src/impl/results_notifier.cpp index 7f3c7320..c6ae69c9 100644 --- a/src/impl/results_notifier.cpp +++ b/src/impl/results_notifier.cpp @@ -24,7 +24,7 @@ using namespace realm; using namespace realm::_impl; ResultsNotifier::ResultsNotifier(Results& target) -: BackgroundCollection(target.get_realm()) +: CollectionNotifier(target.get_realm()) , m_target_results(&target) , m_sort(target.get_sort()) , m_from_linkview(target.get_linkview().get() != nullptr) diff --git a/src/impl/results_notifier.hpp b/src/impl/results_notifier.hpp index 03b4be60..de0b2d65 100644 --- a/src/impl/results_notifier.hpp +++ b/src/impl/results_notifier.hpp @@ -19,14 +19,14 @@ #ifndef REALM_RESULTS_NOTIFIER_HPP #define REALM_RESULTS_NOTIFIER_HPP -#include "background_collection.hpp" +#include "collection_notifier.hpp" #include "results.hpp" #include namespace realm { namespace _impl { -class ResultsNotifier : public BackgroundCollection { +class ResultsNotifier : public CollectionNotifier { public: ResultsNotifier(Results& target); diff --git a/src/impl/transact_log_handler.cpp b/src/impl/transact_log_handler.cpp index 129384a9..8aedd052 100644 --- a/src/impl/transact_log_handler.cpp +++ b/src/impl/transact_log_handler.cpp @@ -19,7 +19,7 @@ #include "impl/transact_log_handler.hpp" #include "binding_context.hpp" -#include "impl/background_collection.hpp" +#include "impl/collection_notifier.hpp" #include "index_set.hpp" #include diff --git a/src/list.hpp b/src/list.hpp index 2be94748..8abd601d 100644 --- a/src/list.hpp +++ b/src/list.hpp @@ -89,7 +89,7 @@ private: std::shared_ptr m_realm; const ObjectSchema* m_object_schema; LinkViewRef m_link_view; - std::shared_ptr<_impl::BackgroundCollection> m_notifier; + std::shared_ptr<_impl::CollectionNotifier> m_notifier; void verify_valid_row(size_t row_ndx, bool insertion = false) const; diff --git a/src/shared_realm.hpp b/src/shared_realm.hpp index f1ea3b2a..25e5acfd 100644 --- a/src/shared_realm.hpp +++ b/src/shared_realm.hpp @@ -36,7 +36,7 @@ namespace realm { typedef std::weak_ptr WeakRealm; namespace _impl { - class BackgroundCollection; + class CollectionNotifier; class ListNotifier; class RealmCoordinator; class ResultsNotifier; @@ -140,7 +140,7 @@ namespace realm { // Expose some internal functionality to other parts of the ObjectStore // without making it public to everyone class Internal { - friend class _impl::BackgroundCollection; + friend class _impl::CollectionNotifier; friend class _impl::ListNotifier; friend class _impl::RealmCoordinator; friend class _impl::ResultsNotifier; @@ -149,7 +149,7 @@ namespace realm { // to be able to call the handover functions, which are not very wrappable static SharedGroup& get_shared_group(Realm& realm) { return *realm.m_shared_group; } - // BackgroundCollection needs to be able to access the owning + // CollectionNotifier needs to be able to access the owning // coordinator to wake up the worker thread when a callback is // added, and coordinators need to be able to get themselves from a Realm static _impl::RealmCoordinator& get_coordinator(Realm& realm) { return *realm.m_coordinator; } diff --git a/tests/collection_change_indices.cpp b/tests/collection_change_indices.cpp index 7eddc254..1ca24f16 100644 --- a/tests/collection_change_indices.cpp +++ b/tests/collection_change_indices.cpp @@ -1,6 +1,6 @@ #include "catch.hpp" -#include "impl/background_collection.hpp" +#include "impl/collection_notifier.hpp" #include "util/index_helpers.hpp" diff --git a/tests/transaction_log_parsing.cpp b/tests/transaction_log_parsing.cpp index da394289..319a08ca 100644 --- a/tests/transaction_log_parsing.cpp +++ b/tests/transaction_log_parsing.cpp @@ -3,7 +3,7 @@ #include "util/index_helpers.hpp" #include "util/test_file.hpp" -#include "impl/background_collection.hpp" +#include "impl/collection_notifier.hpp" #include "impl/transact_log_handler.hpp" #include "property.hpp" #include "object_schema.hpp"