Skip to content

Commit 3d6fc23

Browse files
authored
Small refactoring (iresearch-toolkit#567)
* Small refactoring * Fix misleading comment * Fix misleading comment * Update index_writer.hpp * Update index_writer.hpp
1 parent e8c0135 commit 3d6fc23

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

core/index/index_writer.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,11 +1204,9 @@ void IndexWriter::Clear(uint64_t tick) {
12041204

12051205
to_commit.ctx = SwitchFlushContext();
12061206
// Ensure there are no active struct update operations
1207-
std::unique_lock ctx_lock{to_commit.ctx->pending_.Mutex()};
1208-
to_commit.ctx->pending_.Wait(ctx_lock);
1209-
ctx_lock.unlock();
1207+
to_commit.ctx->pending_.Wait();
12101208

1211-
Abort(); // Abort any already opened transaction
1209+
Abort(); // iff Clear called between Begin and Commit
12121210
ApplyFlush(std::move(to_commit));
12131211
Finish();
12141212

@@ -1823,11 +1821,8 @@ IndexWriter::PendingContext IndexWriter::PrepareFlush(const CommitInfo& info) {
18231821

18241822
// noexcept block: I'm not sure is it really necessary or not
18251823
auto ctx = SwitchFlushContext();
1826-
// TODO(MBkkt) It looks like lock mutex_ completely unnecessary
18271824
// ensure there are no active struct update operations
1828-
std::unique_lock lock{ctx->pending_.Mutex()};
1829-
ctx->pending_.Wait(lock);
1830-
lock.unlock();
1825+
ctx->pending_.Wait();
18311826
// Stage 0
18321827
// wait for any outstanding segments to settle to ensure that any rollbacks
18331828
// are properly tracked in 'modification_queries_'

core/index/index_writer.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -826,15 +826,14 @@ class IndexWriter : private util::noncopyable {
826826
}
827827
}
828828

829-
void Wait(std::unique_lock<std::mutex>& lock) noexcept {
830-
IRS_ASSERT(lock.mutex() == &m_);
831-
IRS_ASSERT(lock.owns_lock());
829+
void Wait() noexcept {
832830
if (counter_.fetch_sub(1, std::memory_order_acq_rel) != 1) {
833-
do {
831+
std::unique_lock lock{m_};
832+
while (counter_.load(std::memory_order_acquire) != 0) {
834833
cv_.wait(lock);
835-
// relaxed probably enough
836-
} while (counter_.load(std::memory_order_acquire) != 0);
834+
}
837835
}
836+
// We can put acquire here and remove above, but is it worth?
838837
counter_.store(1, std::memory_order_relaxed);
839838
}
840839

0 commit comments

Comments
 (0)