Merge pull request #54 from realm/tg/in-transaction
Remove Realm::m_in_transaction and use the value from the SharedGroup
This commit is contained in:
commit
3244f441fc
|
@ -212,7 +212,6 @@ void Realm::update_schema(std::unique_ptr<Schema> schema, uint64_t version)
|
||||||
read_group();
|
read_group();
|
||||||
transaction::begin(*m_shared_group, m_binding_context.get(),
|
transaction::begin(*m_shared_group, m_binding_context.get(),
|
||||||
/* error on schema changes */ false);
|
/* error on schema changes */ false);
|
||||||
m_in_transaction = true;
|
|
||||||
|
|
||||||
struct WriteTransactionGuard {
|
struct WriteTransactionGuard {
|
||||||
Realm& realm;
|
Realm& realm;
|
||||||
|
@ -288,12 +287,20 @@ void Realm::verify_in_write() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Realm::is_in_transaction() const noexcept
|
||||||
|
{
|
||||||
|
if (!m_shared_group) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return m_shared_group->get_transact_stage() == SharedGroup::transact_Writing;
|
||||||
|
}
|
||||||
|
|
||||||
void Realm::begin_transaction()
|
void Realm::begin_transaction()
|
||||||
{
|
{
|
||||||
check_read_write(this);
|
check_read_write(this);
|
||||||
verify_thread();
|
verify_thread();
|
||||||
|
|
||||||
if (m_in_transaction) {
|
if (is_in_transaction()) {
|
||||||
throw InvalidTransactionException("The Realm is already in a write transaction");
|
throw InvalidTransactionException("The Realm is already in a write transaction");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +308,6 @@ void Realm::begin_transaction()
|
||||||
read_group();
|
read_group();
|
||||||
|
|
||||||
transaction::begin(*m_shared_group, m_binding_context.get());
|
transaction::begin(*m_shared_group, m_binding_context.get());
|
||||||
m_in_transaction = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Realm::commit_transaction()
|
void Realm::commit_transaction()
|
||||||
|
@ -309,11 +315,10 @@ void Realm::commit_transaction()
|
||||||
check_read_write(this);
|
check_read_write(this);
|
||||||
verify_thread();
|
verify_thread();
|
||||||
|
|
||||||
if (!m_in_transaction) {
|
if (!is_in_transaction()) {
|
||||||
throw InvalidTransactionException("Can't commit a non-existing write transaction");
|
throw InvalidTransactionException("Can't commit a non-existing write transaction");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_in_transaction = false;
|
|
||||||
transaction::commit(*m_shared_group, m_binding_context.get());
|
transaction::commit(*m_shared_group, m_binding_context.get());
|
||||||
m_coordinator->send_commit_notifications();
|
m_coordinator->send_commit_notifications();
|
||||||
}
|
}
|
||||||
|
@ -323,18 +328,19 @@ void Realm::cancel_transaction()
|
||||||
check_read_write(this);
|
check_read_write(this);
|
||||||
verify_thread();
|
verify_thread();
|
||||||
|
|
||||||
if (!m_in_transaction) {
|
if (!is_in_transaction()) {
|
||||||
throw InvalidTransactionException("Can't cancel a non-existing write transaction");
|
throw InvalidTransactionException("Can't cancel a non-existing write transaction");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_in_transaction = false;
|
|
||||||
transaction::cancel(*m_shared_group, m_binding_context.get());
|
transaction::cancel(*m_shared_group, m_binding_context.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Realm::invalidate()
|
void Realm::invalidate()
|
||||||
{
|
{
|
||||||
verify_thread();
|
verify_thread();
|
||||||
if (m_in_transaction) {
|
check_read_write(this);
|
||||||
|
|
||||||
|
if (is_in_transaction()) {
|
||||||
cancel_transaction();
|
cancel_transaction();
|
||||||
}
|
}
|
||||||
if (!m_group) {
|
if (!m_group) {
|
||||||
|
@ -352,7 +358,7 @@ bool Realm::compact()
|
||||||
if (m_config.read_only) {
|
if (m_config.read_only) {
|
||||||
throw InvalidTransactionException("Can't compact a read-only Realm");
|
throw InvalidTransactionException("Can't compact a read-only Realm");
|
||||||
}
|
}
|
||||||
if (m_in_transaction) {
|
if (is_in_transaction()) {
|
||||||
throw InvalidTransactionException("Can't compact a Realm within a write transaction");
|
throw InvalidTransactionException("Can't compact a Realm within a write transaction");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +400,7 @@ bool Realm::refresh()
|
||||||
check_read_write(this);
|
check_read_write(this);
|
||||||
|
|
||||||
// can't be any new changes if we're in a write transaction
|
// can't be any new changes if we're in a write transaction
|
||||||
if (m_in_transaction) {
|
if (is_in_transaction()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ namespace realm {
|
||||||
void begin_transaction();
|
void begin_transaction();
|
||||||
void commit_transaction();
|
void commit_transaction();
|
||||||
void cancel_transaction();
|
void cancel_transaction();
|
||||||
bool is_in_transaction() const { return m_in_transaction; }
|
bool is_in_transaction() const noexcept;
|
||||||
bool is_in_read_transaction() const { return !!m_group; }
|
bool is_in_read_transaction() const { return !!m_group; }
|
||||||
|
|
||||||
bool refresh();
|
bool refresh();
|
||||||
|
@ -164,7 +164,6 @@ namespace realm {
|
||||||
private:
|
private:
|
||||||
Config m_config;
|
Config m_config;
|
||||||
std::thread::id m_thread_id = std::this_thread::get_id();
|
std::thread::id m_thread_id = std::this_thread::get_id();
|
||||||
bool m_in_transaction = false;
|
|
||||||
bool m_auto_refresh = true;
|
bool m_auto_refresh = true;
|
||||||
|
|
||||||
std::unique_ptr<Replication> m_history;
|
std::unique_ptr<Replication> m_history;
|
||||||
|
|
Loading…
Reference in New Issue