Rename BackgroundCollection to CollectionNotifier

This commit is contained in:
Thomas Goyne 2016-04-19 14:01:09 -07:00
parent fe5564f40e
commit 953e1b15a8
16 changed files with 47 additions and 47 deletions

View File

@ -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

View File

@ -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)
{
}

View File

@ -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;
};

View File

@ -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> realm)
CollectionNotifier::CollectionNotifier(std::shared_ptr<Realm> 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<std::mutex> lock(m_realm_mutex);
m_realm = nullptr;
}
bool BackgroundCollection::is_alive() const noexcept
bool CollectionNotifier::is_alive() const noexcept
{
std::lock_guard<std::mutex> lock(m_realm_mutex);
return m_realm != nullptr;
}
std::unique_lock<std::mutex> BackgroundCollection::lock_target()
std::unique_lock<std::mutex> CollectionNotifier::lock_target()
{
return std::unique_lock<std::mutex>{m_realm_mutex};
}
@ -154,12 +154,12 @@ static void find_relevant_tables(std::vector<size_t>& 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<std::mutex> 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);

View File

@ -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<Realm>);
virtual ~BackgroundCollection();
CollectionNotifier(std::shared_ptr<Realm>);
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

View File

@ -26,7 +26,7 @@ using namespace realm;
using namespace realm::_impl;
ListNotifier::ListNotifier(LinkViewRef lv, std::shared_ptr<Realm> 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

View File

@ -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 <realm/group_shared.hpp>
namespace realm {
namespace _impl {
class ListNotifier : public BackgroundCollection {
class ListNotifier : public CollectionNotifier {
public:
ListNotifier(LinkViewRef lv, std::shared_ptr<Realm> realm);

View File

@ -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<BackgroundCollection> notifier)
void RealmCoordinator::register_notifier(std::shared_ptr<CollectionNotifier> 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<std::shared_ptr<_impl::BackgroundCollection>>& notifiers)
std::vector<std::shared_ptr<_impl::CollectionNotifier>>& notifiers)
: m_sg(sg)
{
if (notifiers.empty())

View File

@ -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<BackgroundCollection> notifier);
static void register_notifier(std::shared_ptr<CollectionNotifier> notifier);
// Advance the Realm to the most recent transaction version which all async
// work is complete for
@ -95,8 +95,8 @@ private:
std::vector<WeakRealmNotifier> m_weak_realm_notifiers;
std::mutex m_notifier_mutex;
std::vector<std::shared_ptr<_impl::BackgroundCollection>> m_new_notifiers;
std::vector<std::shared_ptr<_impl::BackgroundCollection>> m_notifiers;
std::vector<std::shared_ptr<_impl::CollectionNotifier>> m_new_notifiers;
std::vector<std::shared_ptr<_impl::CollectionNotifier>> m_notifiers;
// SharedGroup used for actually running async notifiers
// Will have a read transaction iff m_notifiers is non-empty

View File

@ -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)

View File

@ -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 <realm/group_shared.hpp>
namespace realm {
namespace _impl {
class ResultsNotifier : public BackgroundCollection {
class ResultsNotifier : public CollectionNotifier {
public:
ResultsNotifier(Results& target);

View File

@ -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 <realm/group_shared.hpp>

View File

@ -89,7 +89,7 @@ private:
std::shared_ptr<Realm> 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;

View File

@ -36,7 +36,7 @@ namespace realm {
typedef std::weak_ptr<Realm> 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; }

View File

@ -1,6 +1,6 @@
#include "catch.hpp"
#include "impl/background_collection.hpp"
#include "impl/collection_notifier.hpp"
#include "util/index_helpers.hpp"

View File

@ -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"