Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use concurrent_unordered_set for _new_inventory #2383

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/net/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ namespace graphene { namespace net { namespace detail {
dlog("beginning an iteration of advertise inventory");
// swap inventory into local variable, clearing the node's copy
std::unordered_set<item_id> inventory_to_advertise;
inventory_to_advertise.swap(_new_inventory);
_new_inventory.swap( inventory_to_advertise );

// process all inventory to advertise and construct the inventory messages we'll send
// first, then send them all in a batch (to avoid any fiber interruption points while
Expand Down
13 changes: 10 additions & 3 deletions libraries/net/node_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public:
fc::scoped_lock<fc::mutex> lock(mux);
return std::unordered_set<Key, Hash, Pred>::erase( key );
}
// swap
void swap( typename std::unordered_set<Key, Hash, Pred>& other ) noexcept
{
fc::scoped_lock<fc::mutex> lock(mux);
std::unordered_set<Key, Hash, Pred>::swap( other );
}
// iteration
typename std::unordered_set<Key, Hash, Pred>::iterator begin() noexcept
{
Expand Down Expand Up @@ -335,11 +341,12 @@ class node_impl : public peer_connection_delegate
// @}

/// used by the task that advertises inventory during normal operation
// @{
/// @{
fc::promise<void>::ptr _retrigger_advertise_inventory_loop_promise;
fc::future<void> _advertise_inventory_loop_done;
std::unordered_set<item_id> _new_inventory; /// list of items we have received but not yet advertised to our peers
// @}
/// list of items we have received but not yet advertised to our peers
concurrent_unordered_set<item_id> _new_inventory;
/// @}

fc::future<void> _terminate_inactive_connections_loop_done;
uint8_t _recent_block_interval_in_seconds; // a cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value
Expand Down