Skip to content

Commit

Permalink
Merge pull request libbitcoin#145 from evoskuil/version3
Browse files Browse the repository at this point in the history
Make block index read atomic.
  • Loading branch information
evoskuil authored May 18, 2017
2 parents b3e2ae8 + 0c145c3 commit 9057e17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/databases/block_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ void block_database::write_position(file_offset position, array_index height)
file_offset block_database::read_position(array_index height) const
{
const auto slab = index_manager_.get(height);

// Critical Section
///////////////////////////////////////////////////////////////////////////
shared_lock lock(mutex_);
return from_little_endian_unsafe<file_offset>(REMAP_ADDRESS(slab));
///////////////////////////////////////////////////////////////////////////
}

// The index of the highest existing block, independent of gaps.
Expand Down
8 changes: 4 additions & 4 deletions src/databases/transaction_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ memory_ptr transaction_database::find(const hash_digest& hash,
///////////////////////////////////////////////////////////////////////////
// Critical Section
metadata_mutex_.lock_shared();
const size_t height = deserial.read_4_bytes_little_endian();
const size_t position = deserial.read_2_bytes_little_endian();
const auto height = deserial.read_4_bytes_little_endian();
const auto position = deserial.read_2_bytes_little_endian();
metadata_mutex_.unlock_shared();
///////////////////////////////////////////////////////////////////////////

Expand All @@ -158,7 +158,7 @@ transaction_result transaction_database::get(const hash_digest& hash,
metadata_mutex_.lock_shared();
auto deserial = make_unsafe_deserializer(REMAP_ADDRESS(slab));
const auto height = deserial.read_4_bytes_little_endian();
const auto position = deserial.read_4_bytes_little_endian();
const auto position = deserial.read_2_bytes_little_endian();
metadata_mutex_.unlock_shared();
///////////////////////////////////////////////////////////////////////

Expand All @@ -185,7 +185,7 @@ bool transaction_database::get_output(output& out_output, size_t& out_height,
metadata_mutex_.lock_shared();
auto deserial = make_unsafe_deserializer(REMAP_ADDRESS(slab));
const auto height = deserial.read_4_bytes_little_endian();
const auto position = deserial.read_4_bytes_little_endian();
const auto position = deserial.read_2_bytes_little_endian();
metadata_mutex_.unlock_shared();
///////////////////////////////////////////////////////////////////////

Expand Down

0 comments on commit 9057e17

Please sign in to comment.